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

**URL:** <https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205>\
**Category:** Q&A\
**Created:** [January 21, 2020, 11:30pm UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205 "2020-01-21T23:30:54Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 21, 2020, 11:30pm UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/1 "2020-01-21T23:30:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 21, 2020, 11:52pm UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/2 "2020-01-21T23:52:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 12:10am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/3 "2020-01-22T00:10:31Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 12:24am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/4 "2020-01-22T00:24:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 12:32am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/5 "2020-01-22T00:32:36Z")

</div>

Please see below the output this achieves:

 ![MegaFigure](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/30870b9c9f6efd6563016d2764c9aaad8f33e7c8.png)

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!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 12:53am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/6 "2020-01-22T00:53:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 1:31am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/7 "2020-01-22T01:31:11Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 2:03am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/8 "2020-01-22T02:03:14Z")

</div>

> [@jdignan](#):
>
> surface NormalGrid.txt -GGrid.nc -I0.03 -R-R-25/10/40/60

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

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 2:16am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/9 "2020-01-22T02:16:14Z")

</div>

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

 ![MegaFigure](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/3adb112dd97690652d23a297fde385a2c551d01a.png)

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.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 3:04am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/10 "2020-01-22T03:04:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 3:13am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/11 "2020-01-22T03:13:59Z")

</div>

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](https://drive.google.com/file/d/1hY5K-Bgv6IBjVUZrgqp89b2hlaWWY3K8/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 3:42am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/12 "2020-01-22T03:42:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdignan](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jdignan](https://forum.generic-mapping-tools.org/u/jdignan)\
**Post date:** [January 22, 2020, 4:09am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/13 "2020-01-22T04:09:38Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [January 22, 2020, 7:39am UTC](https://forum.generic-mapping-tools.org/t/plotting-across-a-meridian-on-a-360-degree-grid-does-a-workaround-exist/205/14 "2020-01-22T07:39:48Z")

</div>

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