[GRASS-user] Precipitation color table?

Hamish hamish_b at yahoo.com
Wed Sep 24 05:34:59 EDT 2008


Hamish:
> > or maybe one of the color scales here do the trick:
> >   http://oceancolor.gsfc.nasa.gov/PRODUCTS/colorbars.html
> >
> > I have converted a couple of those to GRASS r.colors
> > rules files, here: 
http://trac.osgeo.org/grass/browser/grass-addons/raster/r.colors.tools/palettes
> >
> > conversion script are given in the SVN log messages of those if you
> > would like to convert the euphotic depth rules.

Luigi Ponti wrote:
> The SVN conversion script is something I have tried to figure out for
> a while: great! It always challenges me to find ways to dynamically
> generate raster color maps.
>
> I have understood that the algorithm is able to scale a 0-255 color map
> to the 0-65535 range; I am not sure how it could be adapted to scale to
> any range of data. Questions:
> 
> - Why do you use 65535?

it is an artifact of the data. MODIS and SeaWiFS satellite HDF data is
provided as 16-bit (2^16=66536 grains).

> - Slope and Intercept: are they parameter of a linear
> regression to convert 0-255 values to 0-65535?

They come from the meta-data of the HDF file. You apply the slope and
offset to convert 0-66535 into e.g. full range -4 to 35 degree C sea
surface temperature values.

I would note that it is not always linear. If you look on the MODIS page
in the GRASS wiki you will see that the chlorophyll-a map uses those
coefficients in a logarithmic scale. (r.mapcalc used for conversion)

> - In the line:
>         10((Slope * (($1 +1)2 -1)) + Intercept), $2, $3, $4)}'
> I am not sure what (($1 +1)2 -1)) does.

(that's for the logarithmically scaled 16-bit chlorophyll-a data)

the trac is a bit too smart for it's own good there. It translated ^2
and 10^ to superscript-2 and 10. It's back-transforming  from log10.
The ^2 is to go from the 0-255 color rule range to 0-66535 data range.
I think there the data range (given in the metadata) did not match the
given color rules, and the '+1)^2 -1' part was because the 255 rule
for NULL should only cover 66535 and not all data in 254^2 to (255^2 -1).

input: http://oceancolor.gsfc.nasa.gov/DOCS/palette_chl_etc.txt
0 r:g:b
1 r:g:b
....
254 r:g:b
255 0:0:0

and the script converts to real data (milligrams/m^3) like:
0.010000 0:0:0
0.010004 144:0:111
....
60.304498 105:0:0
64.574061 100:0:0



> The goal would be to develop a script which would take the
> data range of any raster and scale a 0-255 color rule to it.

scale 0-255 to 0-100 and add a % sign. r.colors will do the rest.

r=
g=
b=
RULE="`echo $EIGHTBIT | awk '{print $1 / 2.55}'`% $r:$g:$b"

 -> if $EIGHTBIT=255 then $RULE becomes "100% r:g:b"


Hamish



      



More information about the grass-user mailing list