Grdimage transparency of NAN values

,

Hi,
I just updated to 6.5 from 6.3, and i find that my grdimage can no longer use the -Q option to plot NAN values as completely transparent if i also have intensity set by -I+d.
example:
gmt grdimage $filename1 -R$region -I+d -C$CPT_FILE -J$Jparam -Q,
which returns the error:
grdimage [ERROR]: Option -Q: Cannot specify a transparent color for grids when intensities are also used

This is relevant because i am trying to plot two grids (.grd format) on top of each other, but now the one plotted second plots all the NAN vaules in white, instead of transparent. Is there a way around this?

I know that i can add -T+s to grdimage, but it makes it quite slow and makes the file size 10x larger. I can also use grdblend to combine the 2 grids, which is also very slow.
gmt grdblend $filename1 $filename2 -Gblended.grd -I25e -R$region -Vq

in makecpt maybe ?

-A transparency[+a]
Sets a constant level of transparency (0-100) for all color slices. Append +a to also affect the fore-, back-, and nan-colors [Default is no transparency, i.e., 0 (opaque)].

Can you provide a (minimum) reproducible example?

I had the similar issue. I think I solved it using grdmask (I could share the code later).

I liked when it was possibly to do it directly. I think something changed when grdimage was improved.

This is from memory only, thus low trusting, but NaN transparency was a grdview only feature up to recent extension of of it to grdimage. So, I’m having difficulties seeing the backward compat breaking side of this.

As far as I can tell, this will affect the entire cpt, whereas I only want to affect the NaN values. And I am not even using makecpt, I manually make the cpt (taken from MB-System/haxby). In that sense, I do not specify foreground/background/NaN colors, so perhaps there is a way to set COLOR_NAN to transparent?

echo Making color palette table file…
cat << EOF > $CPT_FILE
-6000 37 57 175 -5500 40 127 251
-5500 40 127 251 -5000 50 190 255
-5000 50 190 255 -4500 106 235 255
-4500 106 235 255 -4000 138 236 174
-4000 138 236 174 -3500 205 255 162
-3500 205 255 162 -3000 240 236 121
-3000 240 236 121 -2500 255 189 87
-2500 255 189 87 -2000 255 161 68
-2000 255 161 68 -1500 255 186 133
-1500 255 186 133 -1000 255 255 255
EOF

Previously I was using this:

echo Creating Gridded bathymetry map
gmt grdimage $filename2 -R$region -I+d -C$CPT_FILE -J$Jparam -Q -Xc -Y0.75i
gmt grdimage $filename1 -R$region -I+d -C$CPT_FILE -J$Jparam -Q

which plotted the $filename1 on top of $filename2 (both .grd files). $filename2 is larger and covers more area, but $filename1 is at a higher resolution, so I dont want the background of $filename1 (just NaN values from mbgrid in mb-system) covering the bathymetry of $filename2.

Now, when I updated to GMT 6.5, that was giving an error, so I had to switch to

echo Creating Gridded bathymetry map
gmt grdimage $filename2 -R$region -I+d -C$CPT_FILE -J$Jparam -Xc -Y0.75i
gmt grdimage $filename1 -R$region -I+d -C$CPT_FILE -J$Jparam -T+s

which skips plotting nodes with z = NaN, but doesnt really seem to be for plotting bathymetry data. This method increased the file size about 4 times as well, making it much slower to open, going from ~20mb to 80mb.

A third method is possible, but produces a filesize of ~280mb, although the significant increase is likely due to resampling (-I25e) at a 25m resolution, which $filename1 can handle, but $filename2 is really a 100m grid:

echo Combining the grids
gmt grdblend $filename1 $filename2 -Gblended.grd -I25e -R$region -Vq
echo Creating Gridded bathymetry map
gmt grdimage blended.grd -R$region -I+d -C$CPT_FILE -J$Jparam -Xc -Y0.75i

Here is a link to a drive with the photos:
https://drive.google.com/drive/folders/1DIIWQTdl9lm0jroqwt616wgXcdTwsEcE?usp=sharing

Image 25b is the old method with -Q.
Image 25c is the method with -T+s
Image 25f is the method with resampling and blending the grids.

Let me ask it again.

Can you provide a (minimum) REPRODUCIBLE example of the error? (and no unix syntax please, I’m on Windows)

This will produce the error with the files in the drive folder:

gmt begin Chain1 ps
gmt grdimage Chain_Bathy_100m_neg.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM11i -Q -Xc -Y0.75i
gmt grdimage MGL2411_multibeam.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM11i -Q
gmt end

which produces the error:
grdimage [ERROR]: Option -Q: Cannot specify a transparent color for grids when intensities are also used

This is the second method:

gmt begin Chain2 ps
gmt grdimage Chain_Bathy_100m_neg.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM11i -Xc -Y0.75i
gmt grdimage MGL2411_multibeam.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM11i -T+s
gmt end

and this is the 3rd method:

gmt begin Chain3 ps
gmt grdblend MGL2411_multibeam.grd Chain_Bathy_100m_neg.grd -Gblended.grd -I25e -R16.3W/12.8W/2.2S/0.3S
gmt grdimage blended.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM11i -Xc -Y0.75i
gmt end

Thanks, now I see what is happening.

Don’t know why Paul add that condition of if -I than no -Q, which doesn’t seem to be necessary. If I comment it in the code, I get a PS like this

image

but converting to png or jpg those blacks disappear and we see what’s under them.

But you can save your day using grdview -Qc. This (and I odified the z.cpt to have a B,F,N all equal to white)

gmt grdview Chain_Bathy_100m_neg.grd -R16.3W/12.8W/2.2S/0.3S -I+d -Cz.cpt -JM15c -Qc -P -K > lixo.ps
gmt grdview MGL2411_multibeam.grd -R -I+d -Cz.cpt -JM -Qc -O >> lixo.ps

gives similar to your Chain_25b_MGL2411_ProgressUpdated.ps

1 Like

Thank you! it also reduced the file size back to normal.