[GRASS-user] Precipitation color table?

From: Hamish <hamish_b@yahoo.com>
Subject: Re: [GRASS-user] Precipitation color table?
To: GRASS user list <grass-user@lists.osgeo.org>, Markus Neteler
  <neteler@osgeo.org>
Message-ID: <570989.41209.qm@web110014.mail.gq1.yahoo.com>
Content-Type: text/plain; charset=us-ascii

Markus wrote:
  

> anyone having a nice precipitation color table (e.g., range from 0mm
> to 2000mm)?

you might find some nice ones here:
  http://sview01.wiredworkplace.net/pub/cpt-city/

convert those .cpt (ie GMT) color rules to something suitable for r.colors
with the r.cpt2grass addon script.
  
Sorry, I omitted that in my reply to Markus because it had been mentioned several times on the list -- my fault.

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. By the look of it their version
of NDVI is staged and would best be converted by hand.
  

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?
- Slope and Intercept: are they parameter of a linear regression to convert 0-255 values to 0-65535?
- In the line:
        10((Slope * (($1 +1)2 -1)) + Intercept), $2, $3, $4)}'
I am not sure what (($1 +1)2 -1)) does.

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.

Thanks and regards,

Luigi

# scale 0-255 to 0-65535 and then convert to chlor-a values

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

Hamish wrote:

[…]

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:

    
[...]

Thanks for the detailed description of your script. It keeps amazing me how many things an awk script can do in a couple of lines.


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"

  

Really a good tip – will implement it right away.

Regards,

Luigi