wiki:ColorScaleRange

How dows ncWMS deal with colour scale ranges?

When a dataset is loaded into ncWMS for the first time, ncWMS performs a test extraction of data from the first timestep. It uses this data sample to guess a suitable colour scale range. Of course, if the first timestep happens to be winter, the selected scale range won't be any good for a summer temperature plot, but it's better than a wild guess. This guess can be overridden for each variable using the ncWMS admin application (click "Edit" for the dataset in question).

ncWMS requests can include a (non-standard) COLORSCALERANGE parameter. If this is omitted, the default (guessed) scale is used. Using a consistent scale as a default ensures that tiled map clients function properly, and that legends can be displayed correctly. Setting this parameter to "auto" causes ncWMS to stretch the colour palette over the exact range of data in the image. Lastly, you can set a comma-separated range of data values.

Standard WMS clients won't generally know how to submit a COLORSCALERANGE parameter, although some do provide a means to set custom parameters. Sometimes you can work around this by specifying this parameter in the address of the WMS endpoint or Capabilities doc, so in some clients you can do this when asked to enter the URL of the Capabilities doc:

 http://myserver.com/ncWMS/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0&DATASET=NCOF_FOAM_ONE&COLORSCALERANGE=foo,bar

Then all these custom parameters will (hopefully) be added to all the GetMap? requests.

Godiva2 can find the colour scale range for a given time, depth and bounding box using a special call to ncWMS. You can replicate this call: it's just another URL request:

 http://myserver.com/ncWMS/wms?item=minmax&layers=NCOF_FOAM_ONE%2FTMP&bbox=-56.953125%2C-1.9326171875%2C-14.765625%2C31.0263671875&elevation=-5&time=2009-10-05T00%3A00%3A00.000Z&crs=EPSG%3A4326&width=50&height=50&request=GetMetadata

This call creates a map with the given parameters (e.g. width/height), then searches the map for the actual min and max data values. You get a JSON response back, which is designed for parsing in Javascript, but could be parsed quite easily in other languages too.

It would certainly be possible to change Godiva2 to automatically contrast-stretch when new variables are loaded. However, this process can be a little slow (e.g. when viewing OPeNDAP data) and so I implemented Godiva2 to simply use the default value when a variable loads. The user can press "auto" to do the contrast-stretching. I know that some will find this inconvenient - please comment on the mailing list.