WCS Clients and Servers

OWSLib

The OWSLib package can be obtained at:

http://trac.gispython.org/lab/wiki/OwsLib

and contains code for WMS and WCS.

A paper showing the use of the WCS capabilities can be found at:

http://ams.confex.com/ams/89annual/techprogram/paper_150644.htm

The following example code is included in the paper:

First, we instantiate a WebCoverageService object for a specific WCS service. This calls the GetCapabilities method of the server and populates Python metadata attributes.

from owslib.wcs import WebCoverageService
wcs=WebCoverageService('http://somewcs.url.com',version='1.0.0')
wcs.identification.title
'WCS Server from institution A'
Next, we find out which coverages are available.
wcs.contents
{'AirTemperature':<owslib.coverage.wcs100.ContentMetadata object at 0x8a7fc4c>,
'WaterVapour':<owslib.coverage.wcs100.ContentMetadata object at 0x8a7fc8c>,
'SeaSurfaceTemperature':<owslib.coverage.wcs100.ContentMetadata object at 0x8a7fe0c>,...}
Now we find out more about a particular coverage, e.g. the spatio-temporal extent, available output formats, etc. This method silently calls the DescribeCoverage method from the server and retrieves metadata specific to that coverage. For example, a call to retrieve coverage information for AirTemperature and place it in the object airtemp is:
airtemp=wcs['AirTemperature']
The spatial extent of the coverage is discovered via:
airtemp.boundingBoxWGS84
(1.875, -88.767123287700002, 358.125, 88.767123287700002)
Similarly, the temporal extent is found via:
airtemp.timelimits
['2024-01-15T00:00:00.0','2054-12-15T00:00:00.0']
The supported formats are discovered via:
airtemp.supportedFormats
['cf-netcdf','GeoTiff']
All of this information allows us to formulate and send a GetCoverage request, e.g.
output="wcs.getCoverage(identifier='AirTemperature',time=['2024-01-15T00:00:00.0'],bbox=(-80,30,50,60),format='cf-netcdf')
This output coverage NetCDF file can be written to disk via:
f=open('test.nc','wb')
f.write(output.read())
f.close()
after which the disk file can be further processed with the usual suite of tools that can handle NetCDF files.


The method for accessing the THREDDS WCS server is found at:

http://www.unidata.ucar.edu/projects/THREDDS/tech/reference/WCS.html

All WCS requests start with the form:

http://servername:8080/thredds/wcs/ 
Thus, an OWSLib call to discover this WCS server would be:
from owslib.wcs import WebCoverageService
wcs=WebCoverageService('http://servername:8080/thredds/wcs/gcoos/seadas[_sst]?service=WCS&version='1.0.0')
or, for the GCOOS SeaDAS part of the server [from zeta]:
from owslib.wcs import WebCoverageService
wcs=WebCoverageService('http://megara.tamu.edu:8080/thredds/wcs/gcoos/seadas?service=WCS&version=1.0.0')

wcs.identification.title
[nada]

wcs.contents
{'Kd_488_lee': ,
 'adg_443_carder': ,
 'adg_443_qaa': ,
 'angstrom_551': ,
 'aph_443_qaa': ,
 'bbp_551_qaa': ,
 'cfe': ,
 'chl_carder': ,
 'chlor_a': ,
 'eps_78': ,
 'flh': ,
 'l2_flags': ,
 'nLw_412': ,
 'nLw_443': ,
 'nLw_488': ,
 'nLw_531': ,
 'nLw_551': ,
 'nLw_667': ,
 'nLw_678': ,
 'nLw_748': ,
 'nLw_869': ,
 'seadas_K_490': ,
 'sena': ,
 'senz': ,
 'taua_551': ,
 'taua_869': ,
 'tsm_clark': }
Similarly, for the GCOOS SeaDAS SST part of the server [from zeta]:
from owslib.wcs import WebCoverageService
wcs=WebCoverageService('http://megara.tamu.edu:8080/thredds/wcs/gcoos/seadas_sst?service=WCS&version=1.0.0')

wcs.contents
{'cloud_mask': ,
 'l2_flags': ,
 'seadas_sst': }
To retrieve data from our server we would do the following:
sst = wcs['seadas_sst']

sst.title
'Sea Surface Temperature'

sst.id
'seadas_sst'

sst.boundingBoxWGS84
(-98.0, 18.010390000000001, -79.010989999999993, 31.0)

sst.timelimits
['2009-10-12T02:59:47Z', '2010-04-21T16:00:47Z']

sst.supportedFormats
['GeoTIFF', 'GeoTIFF_Float', 'NetCDF3']

#  A string for obtaining a spatio-temporal subset of the full dataset follows.
#  Remember that the bbox format is (lower left lon, lower left lat, upper right lon, upper right lat).

output=wcs.getCoverage(identifier='seadas_sst',time=['2009-10-12T02:59:47Z'],bbox=(-95,20,-90,26),format='NetCDF3')

f=open('test.nc','wb')
f.write(output.read())
f.close()