Plotting across a meridian on a 360 degree grid - does a workaround exist?

Hi,

I am currently trying to create a grid which runs across the Grenwich Meridian, yet using a 360 degree grid. So in essence my region becomes 335/10/40/60.

I have an XYZ dataset which runs across these co-ordinates, and then use the surface tool to interpolate and later plot:

surface NormalGrid.txt -GGrid.nc -I0.03 -R335/10/40/60

It seems that I am easily able to plot one side of the meridian (i.e 335 - 360 or 0 - 10), however not across a single image.

I have experimented with plotting as a whole with an 180 longitudinal offset, and trying to find a way to then shift it around by 180 degrees once in a .grd format.

I realise that this can be done on a 180 to -180 basis, however this is not the final output I am looking for.

Is there a way to do this, through any of the following options, in order of preference:

  • Plot these using the original dataset with X values ranging from 335 to 10, plotting across the zero meridian
  • Offset the data (outside of GMT), plot it out of longitudinal alignment, then somehow shift it within GMT into the correct longitudes
  • Plot on a 180 to -180 basis, and somehow change the labels of the final plot to show the 360 dgeree longitudes.

Any advice, even if it is a bit of a messy workaround, would be greatly appreciated.

If you need, I am happy to send the copy of the XYZ data, however I don’t seem to be able to attach it within this forum unless I am attaching an image.

Thank you in advance,

Jack

There is no indication in your command that you want a geographic grid (with periodic longitudes) so you should add -fg. Or, you could use -I1.8m. Either way will tell GMT that you are gridding long/lat, otherwise it is Cartesian and of course nothing will work across 360.
Your grid will be continuous. Whether you want a map to plot annotations in 0-360 range or -180/180 is a separate issue. The grid still needs to have xmax > xmin in its header.

Hi @pwessel,

Thanks so much for getting back to me so quickly.

In principle I understand your solution, in that I need to change my command to ensure I am requesting a geographic grid.

I have tried both adding -fg and changing the -I to 1.8m rather than the 0.03. Both stop the surface command from producing an output.

Do you think I will need to change the input XYZ data from decimal degrees into a reprojected format such as WSG meters, currently they just look like:

335.016667,59.983333,2304.494873
335.050000,59.983333,2304.489258
335.083333,59.983333,2294.762207
335.116667,59.983333,2286.321777
335.150000,59.983333,2282.494629
335.183333,59.983333,2282.076660
335.216667,59.983333,2279.631836
etc…

Thanks again for your time and expertise!

Your data file looks fine. So what happens if you run

gmt surface NormalGrid.txt -GGrid.nc -I0.03 -R-25/10/40/60

If it fails, please report what it says. Also let us know what GMT version and what OS you are on.

Please see below the output this achieves:

It does achieve perfectly the output ranges I would like, as shown in the border, but crops out the data West of 0.

I am using GMT version 5.4.5 using Cygwin on Windows via a bash shell script.

Hope this helps.

Thanks again!

Does gmt grdinfo Grid.nc -M report that there are lots of NaNs or not? If not then the grid is OK and the plotting fails. If so please post your command for making the plot.

Not that I can see:

grdinfo Grid.nc -M

Grid.nc: Title: Data gridded with continuous surface splines in tension
Grid.nc: Command: surface NormalGrid.txt -GGrid.nc -I0.03 -R-R-25/10/40/60
Grid.nc: Remark:
Grid.nc: Gridline node registration used [Cartesian grid]
Grid.nc: Grid file format: nf = GMT netCDF format (32-bit float), COARDS, CF-1.5
Grid.nc: x_min: 0 x_max: 10 x_inc: 0 name: x n_columns: 334
Grid.nc: y_min: 40 y_max: 60 y_inc: 0 name: y n_rows: 668
Grid.nc: z_min: -3946 at x = 8 y = 46 z_max: 2987 at x = 7 y = 41
Grid.nc: scale_factor: 1 add_offset: 0
Grid.nc: format: netCDF-4 chunk_size: 167,134 shuffle: on deflation_level: 3

Also, when using ncdump to see values for X, the range simply goes from 0 to 10, and does not show any NaNs or numbers in the 300s. However, the number of X nodes has been reduced from c. 1170 to 334.

I have also tried to plot without the -Q option flag, which should then plot NANs, which it does elsewhere but not West of 0.

Perhaps I am wrong, but to me this would suggest that there is no data West of 0?

To plot the data I am using the following:

grdimage Grid.nc -R-25/10/40/60 -JM360/0/3i -Bf1a10NsWe -Q > $dir/$fig

Thanks again!

Looks like you have a typo in your -R command and hence you get xmin = 0.

:man_facepalming:t2: Well spotted! Thank you! Now all of my grid is being filled, however the West side still isn’t plotting how I would like:

I have checked and plotted the data in Matlab to check it’s as it should be in XYZ format, which it is, so I’m not sure why it’s doing this here!

Thanks.

Hard to tell from here if GMT 5.4.5 had a bug. If you can post your xyz file then I can have a look.

Sure, I can’t seem to attach it here, only images will upload, but here is a google drive link to the .txt file:

https://drive.google.com/file/d/1hY5K-Bgv6IBjVUZrgqp89b2hlaWWY3K8/view?usp=sharing

Thanks, works great here. I see z is positive down in your case. I flipped it to positive up:

gmt surface NormalGrid.txt -GGrid.nc -I0.03 -fg -Vl -R-25/10/40/60
gmt grdimage Grid.nc+s-1 -JM4i -Cgeo -Baf > map.ps

if I leave off -fg I get your wrong plot.

Note that your choise of -R and -I yields a grid of prime dimensions. Run surface with -V and find

surface [WARNING]: Your grid dimensions are mutually prime. Convergence is very unlikely.

See surface -Q.

Great, thank you so much! Getting my head around it now!

I now have exactly the result I was after, thank you for your help and persistence!

You’re welcome. Take that -Q option seriously (surface).

1 Like