Jupyter Notebook

The Jupyter Notebook interface allows interacting with the data stored on the TAMP platform, extracting the data, plotting and manipulating them. The interface allows using amongst other two libraries:

  • the Open GeoSpatial Consortium (OGC) Web Service (OWS) library, that provides OGC-compliant WCS functionalities;
  • the PEP library developed within TAMP, that allows processing data on the platform.

An introduction of the Jupyter Notebook interface provided by TAMP can be watched in the video below.


Following, the code used in the video is provided. The two sections display code using the OWS library and the PEP library.

OWS Library

First, to import the Open GeoSpatial Consortium (OGC) Web Service (OWS) library, use the following code. Moreover, executing this code will display the available collections on the TAMP Platform.

from owslib.wcs import WebCoverageService

my_wcs = WebCoverageService('http://vtdas-dave.zamg.ac.at/wcs?service=WCS&Request=GetCapabilities', version='2.0.0', timeout=240)

for coverage_name in my_wcs.contents.keys():
    print coverage_name


To list available features for a selected collection, use the following code. As an example collection, we use Flexpart SO2 integrated column collection (FLEXPART_SO2__2D_175__DU_176_4326_01).

for item in dir(my_wcs.contents['FLEXPART_SO2__2D_175__DU_176_4326_01']):
    if "_" not in item:
        print item


The following code shows the supported formats of the Flexpart SO2 integrated column example collection.

my_wcs.contents['FLEXPART_SO2__2D_175__DU_176_4326_01'].supportedFormats


To extract a 2D raster image (geoTIFF) of a subset from the collection Flexpart SO2 integrated column using the Lat (45, 65) Lon (-20, 20) AOI at the time 2014-09-21 00:00:00, use the following code.

import numpy as np
import gdal

coverage_file = my_wcs.getCoverage(identifier=['FLEXPART_SO2__2D_175__DU_176_4326_01'], 
            format='image/tiff',subsets=[('Long',-20,20), ('Lat',45,65),('t',1411257600,1411257600)] )

with open('flexpart.tif', 'w') as outfile:
    outfile.write(coverage_file.read())


This code will open the previously generated geoTIFF file (flexpart.tif) with gdal and will plot it using matplotlib.

%matplotlib inline
import matplotlib.pyplot as plt

ds = gdal.Open('flexpart.tif')

band = ds.GetRasterBand(1)
elevation = band.ReadAsArray()

print elevation.shape
#print elevation

plt.imshow(elevation, cmap='gist_earth')
plt.colorbar()

ds = None


To extract and display a time series from the collection Flexpart SO2 integrated column on the Lat (55) Lon (-4) point in the timeframe 2014-09-20 00:00:00 - 2014-09-22 00:00:00 (2 days), use the following code. The information is saved as a xml file, the plot is generated using matplotlib.

import xml.etree.ElementTree as ET
coverage_file = my_wcs.getCoverage(identifier=['FLEXPART_SO2__2D_175__DU_176_4326_01'], 
            format='application/xml', subsets=[('Long',-4,-4), ('Lat',55,55),('t',1411171200,1411344000)] )

with open('flexpart.xml', 'w') as outfile:
    outfile.write(coverage_file.read())

tree = ET.parse('flexpart.xml')
root = tree.getroot()

for rangeSet in root.findall('{http://www.opengis.net/gml/3.2}rangeSet'):
    for DataBlock in rangeSet.findall('{http://www.opengis.net/gml/3.2}DataBlock'):
        data= DataBlock.find('{http://www.opengis.net/gml/3.2}tupleList').text

data = data.strip()
data_f = data.split(",")
print data_f

plt.plot(data_f)
plt.show()


PEP Library

Using PEPlib, we calculate the spatial average of the Flexpart SO2 Integrated Column in DU on the Lat (45, 65) Lon (-20, 20) AOI on 2014-09-21 23:00:00.
The PEPlib library is developed within TAMP, which allows processing data on the platform.

from peplib.scripts import tampProcessingUtilities as tpu

spatialAverage = tpu.spatialAverage('FLEXPART_SO2__2D_175__DU_176_4326_01', 65, -20, 45, 20,1411340400)

print "Spatial average: ", spatialAverage


This code computes the temporal average of the Flexpart SO2 Integrated Column in DU on the Lat (60, 65) Lon (-18, -12) AOI (Iceland) on the time range (2014-09-21 23:00:00) - (2014-09-23 23:00:00) (2 days).

import gdal
%matplotlib inline
import matplotlib.pyplot as plt

temporalAverage = tpu.temporalAverage('FLEXPART_SO2__2D_175__DU_176_4326_01', 
                         60, -18, 65, -12,
                         1411340400, 1411513200)

ds_temp = gdal.Open(temporalAverage)

band = ds_temp.GetRasterBand(1)
elevation = band.ReadAsArray()


plt.imshow(elevation, cmap='gist_earth')
plt.show()

ds_temp = None


The following PEPlib function will create a sum of the two collections GOME L2 SO2 [DU] and Flexpart SO2 integrated column [DU] on the Lat (62.5, 68.9) Lon (-20.7, -13.2) AOI on the (19.09.2014 - 15:15:05 to 22.09.2014 - 11:10:00) timeframe.

res = tpu.add('GOME2B_SO2_L2_2D_4326_025', 'FLEXPART_SO2__2D_175__DU_176_4326_01',
             62.5289530948, -20.749178235, 68.8804637455, -13.2067593373,
             1411125642, 1411132505)

ds_flex = gdal.Open(res)

band = ds_flex.GetRasterBand(1)
elevation = band.ReadAsArray()


plt.imshow(elevation, cmap='gist_earth')
plt.show()

ds_flex = None


To subtract one dataset from another, use the following code. We create a subtraction using the two collections GOME L2 SO2 [DU] and Flexpart SO2 integrated column [DU] on the Lat (62.5, 68.9) Lon (-20.7, -13.2) AOI on the (19.09.2014 - 15:15:05 to 22.09.2014 - 11:10:00) timeframe.

res = tpu.subtract('GOME2B_SO2_L2_2D_4326_025', 'FLEXPART_SO2__2D_175__DU_176_4326_01',
             62.5289530948, -20.749178235, 68.8804637455, -13.2067593373,
             1411125642, 1411132505)

ds_flex = gdal.Open(res)

band = ds_flex.GetRasterBand(1)
elevation = band.ReadAsArray()


plt.imshow(elevation, cmap='gist_earth')
plt.show()