2

I am trying to assign a raster/grid a custom color palette in GRASS using the "r.colors" function.

r.colors map=Consensus_BRT_RCP85 colors=rules

This allows me to input my rules for my color palette:

0 238:238:238
0.06 0:0:255
0.33 0:255:255
0.67 255:255:0
1.0 255:0:0 
end

This function operates, but it doesn't create the color palette I would like. enter image description here

I'd like it to be like my custom GMT color palette:

0.000000 238 238 238 0.060000 238 238 238
0.060000   0   0 255 0.333333   0   0 255
0.333333   0 255 255 0.666667 255 255   0
0.666667 255 255   0 1.000000 255   0   0

My GMT palette looks like this (I want my probabilistic map to have this color ramp):enter image description here

I've seen that there is a function called "r.cpt2grass" but this function isn't found on my GRASS installation (not sure what to do about GRASS GIS "add-ons").

1

A way to do this is with a "reclass" map, set up to classify the continuous data into fixed categories. The format of the reclass file might be:

GRASS 7.0.0 (WGS84):~ >cat concensus_reclass.txt
0.000000 thru 0.059999 = 1
0.060000 thru 0.333332 = 2
0.333333 thru 0.666666 = 3
0.666667 thru 1.0 = 4

Your color rules file will be changed to:

1 238:238:238
2 0:0:255
3 0:255:255
4 255:255:0
default 255:0:0 

Now you run:

GRASS 7.0.0 (WGS84):~ >r.reclass input=Consensus_BRT_RCP85 output=Consensus_BRT_RCP85_reclass rules=concensus_reclass.txt
GRASS 7.0.0 (WGS84):~ >r.colors Consensus_BRT_RCP85_reclass rules=new_rules.txt
0

As you say, r.cpt2grass is an add-on. Simply download the script and make it executable. It should be executed in the Grass environment (GRASS shell for example)

GRASS 6.4.4 (geol):~ > r.cpt2grass --help # or GRASS 7
Description:
Convert or apply a GMT color table to a GRASS raster map
Usage:
r.cpt2grass [-s] input=string [map=string] [output=string]
[--verbose] [--quiet]
Flags:
-s   Stretch color scale to match map data extent
--v   Verbose module output
--q   Quiet module output
Parameters:
 input   Name of input GMT color table (.cpt file)
 map   Raster map to apply it to
 output   Name for new rules file, or "-" for stdout

Therefore with your original palette (named your.cpt here):

# COLOR_MODEL = RGB
0.000000 238 238 238 0.060000 238 238 238
0.060000   0   0 255 0.333333   0   0 255
0.333333   0 255 255 0.666667 255 255   0
0.666667 255 255   0 1.000000 255   0   0

Simple conversion (without applying to a particular raster)

GRASS 6.4.4 (geol):~ > r.cpt2grass input=your.cpt  output=your

And the result

# GMT color map created with r.cpt2grass
#  from [/Users/Shared/your.cpt]...
# COLOR_MODEL = RGB
0.000000 238:238:238
0.060000 238:238:238
0.060000 0:0:255
0.333333 0:0:255
0.333333 0:255:255
0.666667 255:255:0
1.000000 255:0:0

But I don't know if it works (it is and old script,2007), especially if you want to apply the resulting table to a particular raster.

 ERROR: bad rule (percentage not in range 0-100): [125% 20:20:20]

Note that most of the original GMT palettes have been integrated into GRASS GIS.

0

@Micha & @gene your answers were helpful for me to get to my desired results.

GRASS 6.4.4 (my_project) :~ sudo vim $GISBASE/etc/colors bcyr_custom.txt

(enter my password). Now I slightly change the "bcyr" color palette.

-0.000001 255:255:255
 0.000000 255:255:255
 0.060000 255:255:255
 0.060001 blue
 0.333333 cyan
 0.666667 yellow
 1.000000 red
 default 255:0:0

Apply my custom color palette.

r.colors map=Consensus_BRT_RCP85 color=bcyr_custom.txt
d.mon start=x0
d.rast Consensus_BRT_RCP85

My map. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.