How do `-R` and `-I` options with differing units interact with each other in `gmt`?

Hi everyone,

I am a gmt novice trying to understand how grdsample works exactly, when I specify a ROI in degrees and an increment in meters.
I am using gmt 6.1.1 on Windows 10 via git bash.

What I am confused by is the following:
Calling
gmt grdsample original.nc -Gresampled.nc -I150e -Vd
seems to work as expected (increment of 150 meters is converted to degrees according to the log):

grdsample [DEBUG]: Grid/Image dimensions imply w/e/s/n = -123.002/-121.994/47.9979/49.0063, inc = 150/150, gridline registration, n_layers = 1
grdsample [DEBUG]: Geographic input grid, longitudes span less than 360
grdsample [INFORMATION]: Distance to degree conversion implies x_inc = 0.00203591
grdsample [INFORMATION]: Given domain implies x_inc = 0.00203704
grdsample [INFORMATION]: Distance to degree conversion implies y_inc = 0.00134898
grdsample [INFORMATION]: Given domain implies y_inc = 0.00134984

but calling the same + specifying the ROI in degrees (using ud)

gmt grdsample original.nc -Gresampled.nc -R-123.00208333333333/-121.99375/47.99791666666666/49.00625ud -I150e -Vd

gives me

grdsample [DEBUG]: Grid/Image dimensions imply w/e/s/n = -123.002/-121.994/197.998/49.0063, inc = 150/150, gridline registration, n_layers = 1
grdsample [DEBUG]: Geographic input grid, longitudes span less than 360
grdsample [INFORMATION]: Distance to degree conversion implies x_inc = -0.00244395
grdsample [INFORMATION]: Given domain implies x_inc = 2.34771e-10
grdsample [INFORMATION]: Distance to degree conversion implies y_inc = 0.00134898
grdsample [INFORMATION]: Given domain implies y_inc = -3.46907e-08
grdsample [ERROR]: Grid y increment <= 0.0
grdsample (gmtapi_init_grdheader): Please select compatible -R and -I values

As far as I can tell, this seems to add the increment (150, which should be interpreted as metres because I specify e) to the ymin value of the ROI (47, which should be interpreted as degrees because I specify ud) and deducing that the dimensions imply a Southern boundary (197) further north than its Northern boundary (49)? Could someone explain where I am going wrong?

I’ve attached the example file as a zipped NetCDF I am trying to grdsample below:
original.zip (67.5 KB)

Any help with this would be much appreciated! Thanks in advance!

Best,
Alessandro

Per the cookbook, the +u modifer is used to specify projected dimensions, but yours are geographic degrees. Unfortunately, there are no checks on this to disallow it, leading to errors. If your command above is literal then you also forgot the leading + on the modifier. Without it I get different errors but all from the same reason. So no +ud should be allowed - I will see if I can add a check for that.

We have fixed a bug that affected your case and it has been merged into master. There is no good workaround for this I think other than manually computing the 150m increment in degrees and give that instead. Thanks for pointing it out!

1 Like

Thanks a lot for your help @pwessel!