Longitude system change, masking and format conversion from grd to GeoTIFF

Hello,

I’m a Climate Modelisation PhD student working with WRF and for now, I’m willing to improve my topography using a .grd file at 250m resolution over my region of interest. I need to do 3 things :

  1. Change longitude system from [0;360]° to [-180;180]° in order to be WRF (WPS) compliant
    OK --> gmt grdedit zS_Tahiti_250m_2021.grd -R-150.26/-148.7/-18.3/-16.8
  2. Replace every (underwater) negative topography values by 0
    OK --> gmt grdmath zS_Tahiti_250m_2021.grd 0 MAX = zS_Tahiti_250m_2021_modified.grd
  3. Convert file from .grd to GeoTIFF (so I can use this process for WPS)

I’m willing to learn more about GMT possibilities, but I struggled finding my way within documentation. Also ChatGPT have been of no help, despite I fed it parts of documentation.

The following information might be usefull :

gmt grdinfo zS_Tahiti_250m_2021.grd
zS_Tahiti_250m_2021.grd: Title: Produced by grdcut
zS_Tahiti_250m_2021.grd: Command: grdcut grd/surface_250m_T0.85.corr.grd -R-150.26/-148.7/-18.3/-16.8 -Ggrd/zS_Tahiti_250m_2021.grd
zS_Tahiti_250m_2021.grd: Remark: 
zS_Tahiti_250m_2021.grd: Gridline node registration used [Cartesian grid]
zS_Tahiti_250m_2021.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
zS_Tahiti_250m_2021.grd: x_min: 209.74 x_max: 211.3 x_inc: 0.0025 name: x n_columns: 625
zS_Tahiti_250m_2021.grd: y_min: -18.3 y_max: -16.8 y_inc: 0.0025 name: y n_rows: 601
zS_Tahiti_250m_2021.grd: v_min: -4305.20019531 v_max: 1980.54821777 name: z
zS_Tahiti_250m_2021.grd: scale_factor: 1 add_offset: 0
zS_Tahiti_250m_2021.grd: format: netCDF-4 chunk_size: 157,151 shuffle: on deflation_level: 3
zS_Tahiti_250m_2021.grd: Default CPT:

Thanks a lot for your help

For the 3) step, I tested :

gmt grdconvert zS_Tahiti_250m_2021_modified.grd zS_Tahiti_250m_2021_modified.tif

And got a weird flipped and zoomed-in file as seen in QGIS, despite grdinfo give same informations :

  1. gmt grdedit -R...
  2. gmt grdclip -Sb0/0 -G...
  3. gmt grdconvert ingrid.grd -Gout.tiff=gd:GeoTIFF

Check the man pages of the referred modules. 3 is from memory. Note that if you convert to plain tif you’ll get an image (I think) and not a grid.

1 Like

Thank you very much.

  1. works with :
    gmt grdconvert ingrid.grd -Gout.tiff=gd:GTiff

Thanks also for 2) : both commands work fine (yours and the one using grdmath).

I think I got a weird, flipped grid, in qgis once, when I forgot to add the .nc extension to a netCDF-file (file had no extension). The grid was OK, but qgis got confused I guess.