# Projection errors

**URL:** <https://forum.generic-mapping-tools.org/t/projection-errors/2342>\
**Category:** PyGMT Q&A\
**Created:** [November 22, 2021, 9:02pm UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342 "2021-11-22T21:02:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sistjerne](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/sistjerne/32/3772_2.png) [@Sistjerne](https://forum.generic-mapping-tools.org/u/Sistjerne)\
**Post date:** [November 22, 2021, 9:02pm UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/1 "2021-11-22T21:02:54Z")

</div>

Hi PyGMT experts,

Thank you for making PyGMT, and for the great efforts in updating and improving the packages. It is very much appreciated.

I have two issues. Do I need to make two different topics?

I am using

```
pygmt. __version__'v0.5.1.dev15'

```

## The first issue:

This may be a bug. I a trying to make a polar sterographic plot of Antarctica, but it is only working when I use projection -Js and not -JS (using ordinary GMT notation). Here, is an example:

```
grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-180,180,-90,-40])
fig = pygmt.Figure()
fig.basemap(region="-130/-50/45/-50r", projection="S0/-90/-70/8c", frame="a20f20")

```

I get this error:

```
basemap [ERROR]: Option -J parsing failure. Correct syntax:
-Js<lon0>/<lat0>[/<horizon>]/<scale> OR -JS<lon0>/<lat0>[/<horizon>]/<width>
<horizon> is distance from center to perimeter (< 180, default 90)
<scale> is <1:xxxx>, <lat>/<1:xxxx>, or <radius> (in cm)/<lat>, or use <width> in cm
basemap [ERROR]: Offending option -JS0/-90/-70/8c
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/g5/procdata/skr/anaconda3/envs/pygmt4/lib/python3.9/site-packages/pygmt/helpers/decorators.py", line 586, in new_module
    return module_func(*args, **kwargs)
  File "/g5/procdata/skr/anaconda3/envs/pygmt4/lib/python3.9/site-packages/pygmt/helpers/decorators.py", line 726, in new_module
    return module_func(*args, **kwargs)
  File "/g5/procdata/skr/anaconda3/envs/pygmt4/lib/python3.9/site-packages/pygmt/src/basemap.py", line 84, in basemap
    lib.call_module("basemap", build_arg_string(kwargs))
  File "/g5/procdata/skr/anaconda3/envs/pygmt4/lib/python3.9/site-packages/pygmt/clib/session.py", line 500, in call_module
    raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'basemap' failed with status code 72:
basemap [ERROR]: Option -J parsing failure. Correct syntax:
basemap [ERROR]: Offending option -JS0/-90/-70/8c

```

This works with no problems:

```
 grid = pygmt.datasets.load_earth_relief(resolution="05m", region=[-180,180,-90,-40])
 fig = pygmt.Figure()
 fig.basemap(region="-130/-50/45/-50r", projection="s0/-90/-70/1:5000000", frame="a20f20")
 fig.grdimage(grid=grid, cmap="gray")
 fig.savefig('test.png', show=True)

```

Am I doing something wrong? I have tried to plot the same thing with a northern polar stereographic projection (projection="S-45/90/70/8c), but with no issues. I can live with using the “Js” solution, but I just find it strange,

## Second issue

I would like to plot projected data on top of an earth relief grid. How do I do this? Do I need to reproject the earth relief data first? I have used this example [(42) Antarctica and stereographic data — GMT 6.6.0 documentation](https://docs.generic-mapping-tools.org/latest/gallery/ex42.html) to plot fx. coastlines in geographical coordinates on top of my projected data. This works, but when I start by using the geographical coordinates (fx. plotting earth relief as a background) with my projected data on top it goes wrong:

```
# grid_relief = pygmt.datasets.load_earth_relief(resolution="05m", region=[-180, 180, -90, -40)

region = "-130/-52/45/-50r"
fig = pygmt.Figure()
# fig.grdimage(grid=grid_relief, region=regionr, cmap="gray", projection="s0/-90/-70/1:50000000") ## Wanted to make a background map
pygmt.config(PROJ_ELLIPSOID="WGS-84")
pygmt.makecpt(cmap="devon", series=[0,100])
fig.grdimage(grid=ds, cmap=True, projection="x1:50000000") ## My projected data (test.nc)
fig.basemap(region=region, projection="s0/-90/-70/1:50000000", frame=[frame[0], frame[1], f'+t"{title}"'])
fig.coast(shorelines="0.5p,black", projection=""s0/-90/-70/1:50000000, frame=['WSEn', frame[0], frame[1]])

```

I have uncommented the lines that do not work! My workaround right now is to reproject my input data through Pythons pyproj, but I guess it is possible in pyGMT to plot it without the reprojection.!

Below I have attached two figures. The first shows my projected data (satellite tracks) without the background relief and the second figure show the background image, but no projected data.

 ![working_no_relief](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/e/e1cfdd7ca267ddfb1c12d1a94a7ca91d733545dd.png) ![not_working_relief](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/e/e20b03ec2b2f06657a264638ec54ee34a19b268d.png)

I have also played around with grdproject, but this does not give me any valied values:

```
ds_proj = pygmt.grdproject(grid=ds, projection="s0/-90/-70/1:50000000", region=regionr, inverse=True)

```

---

<div class="post-metadata">

**Author:** ![Esteban82](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/esteban82/32/54_2.png) [@Esteban82](https://forum.generic-mapping-tools.org/u/Esteban82)\
**Post date:** [November 22, 2021, 9:11pm UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/2 "2021-11-22T21:11:52Z")

</div>

About the first issue, I think that the horizon parameter of -JS should be a positive number even if you are working on the south pole. Maybe you could try using:

```auto
projection="S0/-90/70/8c",

```

---

<div class="post-metadata">

**Author:** ![weiji14](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/weiji14/32/33_2.png) [@weiji14](https://forum.generic-mapping-tools.org/u/weiji14)\
**Post date:** [November 22, 2021, 10:23pm UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/3 "2021-11-22T22:23:37Z")

</div>

Hi @Sistjerne! Yeah, as @Esteban82 mentioned, the `projection` information might need to be a positive number for some reason, I felt like this was a bug introduced sometime around GMT 6.1 or 6.2…

As for your 2nd problem, instead of the earth\_relief grid (SRTM based), I recommend using the Reference Elevation Model of Antarctica (REMA) since it is already in the Antarctic Stereographic Projection (EPSG:3031), so no need to reproject (plus the earth\_relief grid uses REMA as the source anyway). You can then overlay your projected data on top easily. Get it at:

- [Index of /elev/dem/setsm/REMA/mosaic/v1.1/1km](https://data.pgc.umn.edu/elev/dem/setsm/REMA/mosaic/v1.1/1km/)
- [Index of /elev/dem/setsm/REMA/mosaic/v1.1/200m](https://data.pgc.umn.edu/elev/dem/setsm/REMA/mosaic/v1.1/200m/)

E.g. use `pygmt.which("https://data.pgc.umn.edu/elev/dem/setsm/REMA/mosaic/v1.1/200m/REMA_200m_dem_filled.tif", download=True)` to download the GeoTIFF file.

Tip: If you want to plot the Antarctic grounding line, you could try:

```python
fig.coast(
    region="REMA_200m_dem_filled.tif", # or specify in EPSG:3031 coordinates [minx, maxx, miny, maxy]
    projection="s0/-90/-71/1:30000000",
    area_thresh="+ag",
    resolution="i",
    shorelines="0.25p",
    # frame="ag",
)

```

P.S. I have some code from a poster this year at [https://nbviewer.org/github/weiji14/nzasc2021/blob/main/key\_figure.ipynb#Figure-of-Antarctic-active-subglacial-lake-map](https://nbviewer.org/github/weiji14/nzasc2021/blob/main/key_figure.ipynb#Figure-of-Antarctic-active-subglacial-lake-map) and [nzasc2021/key\_figure.py at 15851c3ea797ae2cccf7b10f3d08f498a5314d3e · weiji14/nzasc2021 · GitHub](https://github.com/weiji14/nzasc2021/blob/15851c3ea797ae2cccf7b10f3d08f498a5314d3e/key_figure.py#L367-L416) that might be helpful

 ![image](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/5/5b93f01733c82ae9060e687c81d8eb0c1b48a697.jpeg)

P.P.S. I have some older code (using PyGMTv0.1/GMT 6.0) that may be helpful at [deepbedmap/paper\_figures.py at 0e766fb5789700e63ac38029bd5a0499838431a5 · weiji14/deepbedmap · GitHub](https://github.com/weiji14/deepbedmap/blob/0e766fb5789700e63ac38029bd5a0499838431a5/paper_figures.py#L521-L584) and [https://nbviewer.org/github/weiji14/deepbedmap/blob/v1.1.0/paper\_figures.ipynb](https://nbviewer.org/github/weiji14/deepbedmap/blob/v1.1.0/paper_figures.ipynb).

---

<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:** [November 23, 2021, 12:05am UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/4 "2021-11-23T00:05:33Z")

</div>

> [@Sistjerne](#):
>
> `S0/-90/-70/8c`

There is no option to select map _width_ ( **-JS** ) **and** also specify a specific _latitude_ and _radius_ (-70/8c). That can only be done when you specify a _scale_ ( **-Js** ).

---

<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:** [November 23, 2021, 3:31am UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/5 "2021-11-23T03:31:38Z")

</div>

I have added a bit more checking in master which would give an error for your failing command. I also improved parsing a bit and updated the docs to be clearer on a few items related to -Js|S.

---

<div class="post-metadata">

**Author:** ![Sistjerne](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/sistjerne/32/3772_2.png) [@Sistjerne](https://forum.generic-mapping-tools.org/u/Sistjerne)\
**Post date:** [November 23, 2021, 9:32am UTC](https://forum.generic-mapping-tools.org/t/projection-errors/2342/6 "2021-11-23T09:32:28Z")

</div>

Thank you very much for the thorough answers. I have fixed all my issues!

I can use the projection:

```
projection="S0/-90/70/8c"

```

@weiji14 I really appreciate all your examples. I have indeed learned a lot new about pyGMT by looking at them!
