Unable to generate color change within a region using grdclip

Hi everyone,
I’ve been attempting to plot a region to show color changes within the basemap using grdclip. It’s clipping the region, but the colour change with respect to the data file isn’t happening. I don’t understand why it’s not using the color palette table (CPT). Please let me know if I’ve made any mistakes in the code.

**!/usr/bin/env sh**
**gmt begin jks0 png**
**        gmt basemap -R70.2/80.3/28.2/36 -JM10i -Ba2f2**
**        gmt coast -R70.2/80.3/28.2/36 -JM10i -B -N1/0.8p**
**        gmt makecpt -Crainbow -Ic -T-50/50 -H  > combined.cpt**
**        gmt xyz2grd hima_phi.txt -Ghima.grd -R70.2/80.3/28.2/36 -I0.01**
**        gmt grdclip hima.grd -Gclipped_data.grd -SaNaN/NaN -R74.94/79.07/30.30/33.98**
**        gmt grdimage clipped_data.grd -Ccombined.cpt -R70.2/80.3/28.2/36 -JM10i**
**gmt end show**

This is how my data file looks:

LON      LAT       VALUE
77.644  30.302  0.9747619047619
77.698  30.372  0.97357142857143
77.753  30.443  0.97238095238095
77.807  30.513  0.97130952380952
77.861  30.583  0.97029761904762
77.439  30.415  0.95440476190476
77.496  30.484  0.95345238095238
77.553  30.553  0.95255952380952
77.61   30.622  0.95172619047619
77.667  30.69   0.95095238095238
77.235  30.529  0.93410714285714
77.294  30.596  0.93339285714286
77.353  30.663  0.9327380952381
77.412  30.73   0.93214285714286
77.472  30.797  0.93160714285714
77.03   30.642  0.91380952380952
77.092  30.707  0.91333333333333
77.153  30.773  0.91291666666667
77.215  30.839  0.91255952380952
77.277  30.904  0.9122619047619
76.825  30.755  0.8935119047619
76.889  30.819  0.89321428571429
76.953  30.883  0.89303571428571
77.018  30.947  0.89291666666667
77.082  31.011  0.89291666666667
76.621  30.908  0.87053571428571
76.687  30.971  0.87047619047619
76.753  31.034  0.87053571428571
76.819  31.097  0.87059523809524
76.885  31.16   0.87077380952381
76.418  31.102  0.845
76.485  31.164  0.84511904761905
76.552  31.226  0.84529761904762
76.619  31.288  0.84553571428571
76.687  31.35   0.84589285714286
76.214  31.296  0.81946428571429
76.283  31.357  0.8197619047619
76.351  31.418  0.82011904761905
76.42   31.479  0.82053571428571
76.488  31.54   0.8210119047619
76.011  31.489  0.79392857142857
76.08   31.549  0.79440476190476
76.15   31.609  0.79494047619048
76.22   31.67   0.79553571428571
76.289  31.73   0.79625
75.807  31.683  0.76845238095238
75.878  31.742  0.76910714285714
75.949  31.801  0.7697619047619
76.02   31.861  0.77059523809524
76.091  31.92   0.77142857142857
75.624  31.843  0.74767857142857
75.695  31.902  0.75083333333333
75.766  31.961  0.75404761904762
75.837  32.02   0.75738095238095
75.908  32.08   0.76071428571429
75.459  31.969  0.73154761904762
75.529  32.029  0.73958333333333

This is the output image I am getting on running the above command

1 Like

Not 100% sure what you’d like to see but my guess is that you want to achieve, but my guess is that the issue is with using xyz2grd which will only fill grid cells with data in it, and much of yours seems to fall within the gap. You can instead use, for example,

gmt surface hima_phi.txt -Ghima.grd -R70.2/80.3/28.2/36 -I0.01 -H1

(also note header flag) and see the documentation for more discussion of gridding. I can’t find the right GMT manual pages right now, but see for example

I want to plot this data on the map where the third column will show change in colour on the map wrt the values. It’s not taking the cpt.

Somewhat like this…as here there is a colour change we can see.
images (12)

page 18 of your pdf lecture file

Always make sure you know (by plotting)
your actual data distribution before
interpolation

did you mean spatial distribution here?

thanks! BTW really nice lecture presentations, also the modern pptx ones.

It does use your palette, but:

  1. your grid pixel size is really small (-I0.01 of your xyz2grd call). Zoom in your map and you’ll see some tiny light green pixels inside the gray-painted NaN area. You can try using 10x larger pixel size (-I0.1) and check the difference.
  2. your palette has a range from -50 to 50 (-T-50/50 of your makecpt call) while data values shown in your post are like 0.74 to 0.99. as a result, the pixels are plotted with the same color. Make your palette range realistic, e.g. -T0/1 and check the difference.
  3. try adding -Q to the grdimage call to make the NaN background transparent.
  4. in order to fill the whole grid area from your few points you need to run interpolation. @thwbecker suggested using surface above.

Yes spatial distribution.How will I do that in the map?

plot your point coords as symbols after plotting your grid. something like

gmt plot hima_phi.txt -Sc0.15c -Gyellow -Wthinnest,black

Thank you all for the corrections done.
I have ran the command @warner and getting the plot as point features.How can I paint the polygon with the values in the segment header?
My current plot is coming like this while running the modified script.


How will I fill the polygon? Do I need to use gmtsurface?

My current script:
!/usr/bin/env sh
gmt begin jks0 png
gmt basemap -R70.2/80.3/28.2/36 -JM10i -Ba2f2
gmt coast -R70.2/80.3/28.2/36 -JM10i -B -N1/0.8p
gmt makecpt -Crainbow -Ic -T0/1 -H > combined.cpt
gmt xyz2grd hima_phi.txt -Ghima.grd -R70.2/80.3/28.2/36 -I0.1
gmt grdclip hima.grd -Gclipped_data.grd -SaNaN/NaN
gmt grdimage clipped_data.grd -Ccombined.cpt -R70.2/80.3/28.2/36 -JM10i -Q
gmt end show

1 Like

Yes, and see the -M option

@warner Are you a person? The writing style looks so much a chat. And, BTW; there is no grdclip used in your example.

\o/ just saw this. Nvm

Yeah, I am :man_facepalming::man_facepalming:

This rises a very interesting question.

DO BOTS LIE?