WMS Response

The WMS response allows pydap to work as a Web Map Service server, returning maps from requested variables and regions. In practice, if you have a dataset at

http://example.com/file

the request

http://example.com/file.wms?LAYERS=var&BBOX=-180,-90,180,90&FORMAT=image/png

will return a global map of variable var as a PNG file. The response only works for variables of a certain type and with the proper metadata, as described below. It is possible to combine two or more variables in a single map:

http://example.com/file.wms?LAYERS=a,b&TRANSPARENT=TRUE

This will overlay the maps from variables a and b in a single image.

Variables

The response can generate maps from grids, sequences and structures; simple arrays and base types cannot be easily georeferenced to be plotted on a map. It is important that the variables have metadata describing their location. If your data follows the COARDS convention (for gridded data) or the Dapper specification (for sequential data) it will probably work.

Gridded data

Grids should have the dimensions ordered as (T, Z, Y, X). Latitude and longitude should have the proper units, as described in the COARDS convention. If a grid has more than two dimensions it will be averaged successively until it becomes 2D. This mean that if you have a climatology SST of shape (12, 90, 180) the request:

http://example.com/climatology.wms?LAYERS=SST

will return the annual average, i.e., the average of 12 months. OTOH, the request:

http://example.com/climatology.wms?SST[0]&LAYERS=SST

Will return a map for the first month only. The dataset can be constrained in any way to produce the desired map. As an example, if SST has shape (120, 90, 180) and contains 10 years of monthly data, a map of sea surface temperatures for January can be made with the following request:

http://example.com/climatology.wms?SST[0:12:120]&LAYERS=SST

Grids are plotted as maps using the jet colormap from matplotlib (but matplotlib is not required). The data range is read from the actual_range attribute from the grid, or calculated in real time for each request. For performance reasons it's better if the attribute is already set, obviously.

Sequential data

Sequences are plotted as red dots indicating positions in the map. Sequences must follow a subset of the Dapper specification: the outer sequence should have values for latitude and longitude identified by the axis attribute (with values Y and X, respectively). Sequences should also have a lon_range attribute in the outer sequence, though this is not mandatory.

Structures

When a structure is requested it returns a composite map of the variables it contains. Requesting a structure with a grid and a sequence will result in a map with the positions specified in the sequence overlaid on the field from the grid. No mistery here.

Requirements

This response uses the Python Imaging Library to create the maps. PIL can be installed with easy_install:

$ easy_install -f http://www.pythonware.com/products/pil/ Imaging

You'll also need to install numpy manually. Other dependencies (templess, Python Paste, etc.) are installed automatically. To install the WMS response just type:

$ easy_install dap.responses.wms

You can test your installation by checking a given dataset for the layers it is able to plot. Just access the URL:

http://your-server/some-file.wms?REQUEST=GetCapabilities

This is a standard request defined in the WMS spec that clients use to inspect the capabilities of a server. The response is a XML document describing the supported image formats, available layers and other metadata.

Google Earth

The WMS response defines a second extension, for visualizing data using Google Earth. Just change the extension from .wms to .kml and Google Earth should automatically open all available layers from the dataset:

http://your-server/some-file.kml

Inside Google Earth you can then check the layers you want to visualize overlaid on Earth.

Note that you can also constrain the dataset before visualizing it, just like with the .wms response. For example, if you open the URL

http://example.com/climatology.kml?SST[0]

Google Earth will open only the first record of the variable SST, as expected.