Gridding issue with gmt grdproejct

Hi, I am trying to reproject my geographical data into the XY grid. Before that, data were regridded at 0.1-degree resolution using the grdsample command.

gmt grdsample infile.nc -Gregridded.nc -R-180/180/89/89 -I0.1/0.1
gmt grdproject regridded.nc -R-180/180/89/89 -Jm0.1/1:1 -Goufile.nc -C -F

This works fine but always provides a warning.

grdproject [WARNING]: x_inc does not divide 180; geographic boundary condition changed to natural.

I know that a warning is related to the grid spacing not evenly dividing the 180-degree range and GMT handles by itself. This doesn’t affect much in the output. But when I try to inverse the projection of the output file after performing divergence calculation again into the geographical grid. It does not provide the same grinding as the original. This stops me to do further computation on it. I am keeping the line I used to reproject the divergence file again into the geographical data just for reference.

gmt grdproject divergence_xy.nc -Jm0.1/1:1 -I -F -C -Gdivergence_outfile.nc --PROJ_ELLIPSOID=WGS-84

It will be greatly appreciated if I will get any solution for this.

Did you try -D to set desired spacing?

Hi @pwessel, Thank you for the suggestion. I tried -D but not working out.

After performing grdsample, gedproject (twice: geographic to xy and xy to geographic), and grdmath (for divergence calculation and others). I have file A having a slight variation in latitude and longitude values in comparison to file B. I want to further perform some calculations between them using grdmath, but it always gives me an error that grdmath [ERROR]: grid files not of same size!

File A:

-103.665 34.0000000002 2.88402838903e-15
-103.64 34.0000000002 3.18012252003e-15
-103.615 34.0000000002 2.11042091632e-15
-103.59 34.0000000002 -1.30888335275e-16
-103.565 34.0000000002 -2.21518639816e-15
-103.54 34.0000000002 -1.11898441579e-15
-103.515 34.0000000002 1.89716364295e-15
-103.49 34.0000000002 2.98107316556e-15
-103.465 34.0000000002 7.36234632067e-16
-103.44 34.0000000002 8.10574584562e-16

File B:

-103.65 34 1.63771729511e-09
-103.625 34 1.64051716656e-09
-103.6 34 1.65075497716e-09
-103.575 34 1.65993085943e-09
-103.55 34 1.65832425569e-09
-103.525 34 1.64457814034e-09
-103.5 34 1.66362656984e-09
-103.475 34 1.69267455608e-09
-103.45 34 1.71454062059e-09
-103.425 34 1.71289060713e-09

Converting xy to lat-lon grid on File A is changing a grid structure and making a slight variation in it. Do you have any suggestions to fix this?

No, it can’t be. 0.1 360 divides into an exact integer number. Maybe that -Jm0.1
And pushing the Mercator projection up to ± 89 latitude seams asking for troubles.
If the grid is global the best is probably to do the calculations in spherical coordinates directly.

@Joaquim, I agree with you. That -Jm is only making trouble.

I want to perform a divergence calculation by converting geographical data into xy data. So I can’t use spherical coordinates directly. Therefore, first, I convert geographical data to xy, and after performing divergence, again converting xy data to geographical data again. Here only the trouble arises.

And can’t grdmath compute derivatives in geographical coordinates? I would be surprised.

@Joaquim, I do not deny that grdmath cannot compute derivatives in geographic coordinates. But my study requires things in the xy grid for calculating the emission flux in the horizontal direction, which needs calculation in meters, which I can only achieve via converting geographical to xy and then performing divergence. I found GMT perform this with ease, but I encounter a grid mismatch issue when I try to perform a same.