Here I propose to create a heatmap (or frequency of events in a given area).
In my case, I have GPS coordinates that I want to map them on a pre-existing grid.
- Area of interest : 235E : 250E / 30N : 45N (these values match a grid points)
- Grid-x resolution : 0.625 deg
- Grid-y resolution : 0.5 deg
Thanks to xyz2grd
and the -An
flag, I can directly “count” the number of events in each grid … convenient !
I also replaced the NaN values by "0"s (-di
) and asked the function to match the coordinates exactly to my grid (+e flag
)
lonW=235
lonE=250
latS=30
latN=45
region="-R${lonW}/${lonE}/${latS}/${latN}"
projection="-JX10c"
# For the colorbar later
clr_sty="-DjCL+ef+w8c/0.3c"
clr_txt="-Bxa+lCount -By"
gmt xyz2grd gps.txt -Ggridded.nc -I0.625/0.5+e $region $projection -An -di0
Next, I got GPS coordinates of the borders of my area of interest (here the Great Basin, Nevada) that I want to clip my region on … in format 0:360 instead of -180:180. The -C0
flag after the file allows me to do the operation on longitude only and keep both longitude and latitude in the output. Had it be placed before, only longitude would have remained.
gmt math basin.txt -C0 360 ADD = gbas.txt
Now the plot :
0. Create a colormap
- Clip the basin
- Plot the heatmap
- Plot the basin
- I shifted the gridlines to match the heatmap (
-Bafg+<phase>
)
- I shifted the gridlines to match the heatmap (
- add a colorbar
gmt begin test01 png
gmt makecpt -Clapaz -T0/150/10
gmt clip $region $projection gbas.txt
gmt grdimage gridded.nc -C -B+t"# events per area"
gmt clip -C
gmt plot -Wthinner,black gbas.txt -L -Bxa5f2g0.625-0.3125 -Bya5f2g0.5-0.25 --MAP_GRID_PEN_PRIMARY=faint,grey
gmt colorbar ${clr_sty} ${clr_txt} -Np
gmt end show
Tadaa !