I am trying to modify only negative Z values in a GeoTIFF file but I am still scratching my head about how to achieve this. My first thought was to use the neat grdmath, but after checking the operators I found the IFELSE and I think I would need to use an IF operator instead. Is there another GMT tool that may solve this issue? I also considered to use awk to do the job:
so, re-gridding the result but I would prefer to avoid this way because this will be a time consuming process considering the amount of TIF files I have to analyze. I have uploaded a test file here as a MWE test.tif (314.5 KB), so I will be very much appreciated in case you can take a look at it and suggest me some GMT tools and/or ideas.
Unfortunately no luck so far, it seems that operations cannot be included, eg. -Sb0/((z-180)*-1) so everything below 0 should be positive after adding -180 to the Z value, perhaps I am misunderstanding something here…
I tried grdmath out of curiosity and came up with the following code:
gmt grdmath test.tif 0 LT 180 test.tif SUB MUL test.tif 0 GE test.tif MUL ADD = out.tif
my conclusion is that your code remains very much readable for humans, not only for that RPN calculator of grdmath. A big advantage for so many of us!
Funny thing is that the topic starter has actually got the result from gdal_calc.py. It could happily end up there but gdal_calc.py has not been able to recognize coordinate system from test.tif and silently threw it away. The result was a Cartesian grid without any CRS definition and swapped coordinates (gmt reads tiffs using gdal and gdal obviously assumes latitude comes first in a raster without any CRS). gmt appeared to be more forgiving and thoroughly kept coordinate system definition from test.tif.