Hosted by "1PLs Agency"

Marine Data Literacy 2.0

Providing instruction for managing, converting, analyzing and displaying oceanographic station data, marine meteorological data, GIS-compatible marine and coastal data or model simulations, and mapped remote sensing imagery





Home > 5. Gridded Data > 5.6 Color Scripts

5.6 Creating Color Palettes for Standard Product Grids/Rasters in Saga

1.  This exercise absolutely requires that you have completed the companion exercise Creating "Standard" Grid Products with Saga The above links are provided for reference, as they are nearly the same as for that exercise.
2.  This is the appearance of the SST images from that exercise, with their palette.
3.  Just take a few minutes to explore the use of other available "Preset" palettes in Saga.
4.  Here are 4 random examples of other palettes, using the January data (top) and the July data (bottom).
5.  Of course you can simply save these images in PNG format (with their PGW and KML georeferencing files) and use them in publications, GIS, or Google Earth.  In the panels that follow, however, we will discover how to control their color palettes much more closely, for use in a web mapping server.
6.  Select the January grid in the data object panel.  Then examine the settings to make sure this is what you see.
7.  Find the ellipsis (...) control to the right of 100 COLORS and click it.
8.  This opens the COLORS window.  It should still show the rainbow preset palette we selected originally.
9.  The simplest palette for the 23-29 degree range here would be 6 colors.  Use the COUNT control to set the palette for 6 colors.

Then click OK.

Also select SETTINGS > APPLY in the properties panel to show these colors for the January grid.

10.  Perform the same steps for the July grid.  Now you can see both of them with a very simple, 6-color palette.

NOTE:  If you see anything wrong or different from these images, try re-setting the rainbow palette and resetting the count to 6.  Also the value range must be 23-29.

11.  This new appearance is how these images would look in a web mapping server, using this palette.
12.  Unfortunately there is no direct connection between Saga palettes and web mapping server scripts, so we must write our own.  In the next few panels you'll find how to get the data you need to do this.
13.  In the bottom right corner of the properties panel is the SAVE command.  It saves the display properties of the currently selected grid object (January SST).
14.  Save the properties to the folder PRODUCTS > SAGA > AUXILIARY with the filename sst_jan_liberia_modisa_ocweb_11u_daytime_0.05deg_hdf_saga_descaled.sprm
15.  Open the SPRM file in any ASCII editor and examine it to find the color palette.

You can see that it has the red (R), green (G) and blue (B) numeric values to specify each of the colors you can in the legend in Panel 11, above.

16.  Here are those values, together with color samples.

NOTE:  Integer values like 26 occur at the top of one bin and the bottom of the next in Saga.  Processing occurs from bottom to top, so exact SST values of 26 are assigned the yellow color, etc. etc.

Temperature Color RGB Values
28 < 29   255 000 000
27 < 28   255 127 000
26 < 27   255 255 000
25 < 26   000 255 255
24 < 25   000 000 255
23 < 24   127 000 127
17.  Although there is an example below of a script from one web mapping server (University of Minnesota Mapserver), at this point you must find out from your own editors and system administrators what format is needed from your own system.  It will certainly use the data in Panel 16, but there are many variations and formats.

You can always simply avoid the work and use a PNG image plus PGW or KML georeferencing.  But if you want to use the full power of web mapping, then a digital palette is necessary.

18.  There is no magic formula to create a perfect color palette/value range combination for a non-logarithmic presentation.  [For logarithmic presentations, as in the case of the chlorophyll grid, see below.]  To get a good looking combination, you must juggle the number of colors and the value range to arrive at either whole integer unit values (e.g. 24 deg, 25 deg, etc), or perhaps half-unit steps (e.g. 24.5 deg, 25 deg, 25.5 deg, etc).  The easiest palettes to capture with Saga contain 15 or fewer colors.  Use "trial and error" methods to find the best palette.  If you select a large number of colors, in order to get a smooth color gradation effect, then you will have many color combinations to write into your palette script, which creates lots of extra work and many possibilities for errors.
19.  Just for your information, here's the same grids as above, using the same rainbow palette, but with half-degree steps.  Just use 12 colors instead of 6 to get this change.  Saga can also give you these values in a new SPRM file, and you can write a script with these temperature values.
20.  Now we're going to look at the chlorophyll image, which requires a logarithmic presentation.
21.  Here's the same image we created in the companion exercise, using a log stretch factor of 100.

As we said above, it is perfectly good for use as a PNG image in GIS or Google Earth.  In the panels below, we experiment with the palette to get the script information for a web mapping service image.

22.  In the next panel we'll view the chlorophyll image with a limited number of colors.  By "limit" we mean that too few would give us an image without much information, and too many would require more work than is reasonable.  A practical limit is 15, because above that number Saga does not show individual color bins.  So a default selection would be 15.
23.  Here you can see a rainbow palette with 15 colors applied to the log presentation.

The bins have different temperature ranges (the effect of the stretch factor), and they are not integers.  Log images can be set for integer values (with much more work) if that's what you need.

24.  Here is the COLOR portion of the SPRM file for the above image.


25.  And here are some rows from the corresponding Saga palette.

It can be used to write palettes in other systems.

Chlorophyll ug/l Color RGB Values
46.88 < 64.0   169 000 000
34.29 < 46.88   212 000 000
etc. etc. etc. etc. etc.
etc. etc. etc. etc. etc.
0.23 < 0.54   63 000 191
0 < 0.23   127 000 127
26.  And now we're going to explore the use of the GEBCO 08 grid that we discovered will require special methods to discriminate clearly between marine and land portions.  The use of the simple rainbow palette did not accomplish this in the EXERCISE Creating "Standard" Grid Products with Saga.  Make sure the GEBCO 08 grid (link above) for Liberia is open now.
27.  Here's the GEBCO 08 grid, using a rainbow palette.  The real coastline is the black linear feature.
28.  Depending on the GIS system you're using (and/or the web mapping server) there are many palettes you can download from the web. Many major global datasets have their own published palettes.  Unfortunately Saga doesn't import any of them!  In the next few panels we'll look at a major source of palettes, and select one for use especially with global relief grids (e.g. ETOPO1 the predecessor to GEBCO 08).
29.  Open the CPT-CITY website, listed in the resources above.
30.  Find and click on the ETOPO1 palette.
31.  Click on the palette icon to find these links.  IF we could use them in Saga, there are 8 different versions of this special palette.

32.  Mercifully, Mr. Greg Reed has taken this palette (originally consisting of 80 color bins!) and simplified it to 14 color bins shown below (Panel 33).  Reed's original text is in Mapserver script in Panel 46 below.

33.  This is the Reed-ETOPO1 palette, which is also suitable for GEBCO 98.  Notice that the color scheme changes abruptly from blues to greens at exactly the coastline.  Also, the highest elevations have shades of brown and gray.

These colors roughly mimic the appearance of the earth from space, although there are some extreme differences from reality.

Depth (m) Color RGB Values
< -8000   16 6 180
-8000 < -6000   0 14 203
-6000 < -4000   12 68 231
-4000 < -2000   21 158 252
-2000 < -1000   65 200 255
-1000 < -500   94 223 255
-500 < 0   138 227 255
0 < 100   51 102 0
100 < 500   51 204 102
500 < 1000   255 220 185
1000 < 2000   243 202 137
2000 < 4000   217 166 39
4000 < 6000   159 123 13
>6000   178 118 118
34.  Now to get some experience, we're going to enter these values into Saga.
35.  Select TYPE > LOOKUP TABLE in the properties panel.
36.  Locate the ellipsis (...) to the right of the COLUMNS/ROWS item, and click on it.
37.  This opens the table editor.
38.  Right-click on ROW 1 or ROW 2 and select ADD RECORD.
39.  Repeat this until you have 14 rows.
40.  Click on ROW 1 > COLOR
41.  Insert the RGB numbers for the deepest level in Reed's palette.

Then click OK.

42.  Repeat this for all the COLORS.

The column labelled NAME is for text labels that identify the bins.  You can use Reed's names (Panel 46 below) or the names in Panel 33.

43.  Here are the MINIMUM and MAXIMUM values attached to the colors.

Integer values like -6000 occur at the top of one bin and the bottom of the next in Saga.  Processing occurs from bottom to top, so exact SST values of -6000 are assigned the third color, etc. etc.

You could use values like -5999.999     or -6000.001 etc to refine the ranges, but there are very few points with exact values of -6000 (etc.) so this is unnecessary.

44.  Here is the complete lookup table.
45.  Click OK and you'll see this very much better image.  If you use these colors and relief values in your web mapping server script, then this is also how it would appear there.
46.  Finally, here is an example of the color script part of a University of Minnesota Mapserver mapfile.  This is Reed's original text for the ETOPO1 palette (which we are using here with the GEBCO 08 grid), and was used to write the table shown above in Panel 33. CLASS
      NAME "<-8000m"
      EXPRESSION ([pixel]<-8000)
      COLOR 16 6 180
      NAME "-8000 to -6000m"
      EXPRESSION ([pixel]>=-8000 && [pixel]<-6000)
      COLOR 0 14 203
      NAME "-6000 to -4000m"
      EXPRESSION ([pixel]>=-6000 && [pixel]<-4000)
      COLOR 12 68 231
      NAME "-4000 to -2000m"
      EXPRESSION ([pixel]>=-4000
&& [pixel]<-2000)
      COLOR 21 158 252
      NAME "-2000 to -1000m"
      EXPRESSION ([pixel]>=-2000 && [pixel]<-1000)
      COLOR 65 200 255
      NAME "-1000 to -500m"
      EXPRESSION ([pixel]>=-1000 && [pixel]<-500)
      COLOR 94 223 255
      NAME "-500 to 0m"
      EXPRESSION ([pixel]>=-500 && [pixel]<0)
      COLOR 138 227 255
      NAME "0 to 100m"
      EXPRESSION ([pixel]>=0 && [pixel]<100)
      COLOR 51 102 0
      NAME "100 to 500m"
      EXPRESSION ([pixel]>=100 && [pixel]<500)
      COLOR 51 204 102
      NAME "500 to 1000m"
      EXPRESSION ([pixel]>=500 && [pixel]<1000)
      COLOR 255 220 185
      NAME "1000 to 2000m"
      EXPRESSION ([pixel]>=1000 && [pixel]<2000)
      COLOR 243 202 137
      NAME "2000 to 4000m"
      EXPRESSION ([pixel]>=2000 && [pixel]<4000)
      COLOR 217 166 39
      NAME "4000 to 6000m"
      EXPRESSION ([pixel]>=4000 && [pixel]<6000)
      COLOR 159 123 13
      NAME ">6000m"
      EXPRESSION ([pixel]>=6000)
      COLOR 178 118 118
47.  Don't forget to save these files for future display of the above grids, using the same palettes:
  • sst_jan_liberia_modisa_ocweb_11u_daytime_0.05deg_hdf_saga_descaled.sprm
  • sst_jul_liberia_modisa_ocweb_11u_daytime_0.05deg_hdf_saga_descaled.sprm
  • chloro_jul_liberia_modisa_ocweb_0.05deg_hdfview_saga.sprm
  • relief_liberia_gebco08_gridviewer_saga_1min.sprm