# Deciding on default grid registration and grid type for PyGMT

**URL:** <https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583>\
**Category:** PyGMT Q&A\
**Created:** [June 25, 2020, 2:07am UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583 "2020-06-25T02:07:42Z")\
**Posts on this page:** 15\
**Page:** 1

<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:** [June 25, 2020, 2:07am UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/1 "2020-06-25T02:07:42Z")

</div>

PyGMT v0.1.1 assumes that input `xarray.DataArray` grids are gridline registered ( `GMT_GRID_NODE_REG` ), and of cartesian type ( `GMT_GRID_IS_CARTESIAN` ). Currrently we are working on allowing for either **pixel/gridline** registered and **cartesian/geographic** grids at [#476](https://github.com/GenericMappingTools/pygmt/pull/476), by changing the `virtualfile_from_grid` mechanism. But we’ll need to decide on a good **default** going forward (i.e. for v0.2.0).

GMT defaults to using **`gridline`** registration (aka data values represent top left corner of pixel), and PyGMT currently follows this convention. Should we change it to **`pixel`** registration which is what `xarray` follows? Place your vote below!

# Registration type:

 ![Gridline vs Pixel registration](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/1X/26b90849ab1eb5092cfaa1fe5e44f1114cf4fd34.png)

_Poll ([view on site](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/1))_

# Grid type:

_Poll ([view on site](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/1))_

Feel free to leave your comments below, or on Github at [Deciding on default grid registration and grid type for PyGMT · Issue #487 · GenericMappingTools/pygmt · GitHub](https://github.com/GenericMappingTools/pygmt/issues/487) where there will be some more context.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [June 25, 2020, 11:10am UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/2 "2020-06-25T11:10:10Z")

</div>

GMT does not have a default for grid or pixel registration. It simply handles both of them. Some modules, like `surface` do have the gridline default but GMT in itself doesn’t. Can’t PyGMT do the same? If xarrays need to be pixel-registered just make sure they are and no resample is needed. Just do the same as `grdedit -T` does.

---

<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:** [June 25, 2020, 10:58pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/3 "2020-06-25T22:58:25Z")

</div>

Just to clarify, this is a non-issue for users passing in a NetCDF filename directly into PyGMT, in that case, the gridline/pixel registration type will be handled like normal in GMT.

It is when we’re creating a virtualfile grid from an `xarray` object via the C API, and passing that onto GMT, that we have to explicitly state whether it is gridline or pixel registered. For some cases, where an `xarray` is created from a NetCDF file, we can detect whether an `xarray` is gridline/pixel registered (and we’ve almost got this automated method sorted).

The **default** then would really only affect users creating their grid from scratch in pure Python, as there won’t be a NetCDF ‘source’ we can run `grdinfo` on to detect the registration type. In this case, would it be better to assume that the user created a pixel registered or gridline registered grid?

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [June 25, 2020, 11:25pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/4 "2020-06-25T23:25:51Z")

</div>

In case you find it useful, that’s how I deal with it in Julia

> <https://github.com/GenericMappingTools/GMT.jl/blob/master/src/gmt_main.jl#L1819>

---

<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:** [June 25, 2020, 11:46pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/5 "2020-06-25T23:46:27Z")

</div>

Thanks for linking to that! I was thinking of using a boolean flag as well last night (instead of the current implementation which parses a string like `reg="g"` or `reg="p"`). Will take a closer look later, what does HDR stand for?

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [June 25, 2020, 11:50pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/6 "2020-06-25T23:50:06Z")

</div>

HDR is an header vector (explained in the function)  
`HDR 1x9 [xmin xmax ymin ymax zmin zmax reg xinc yinc] header descriptor`  
We have this guy since the very early grdreader in Matlab tens of years ago.

---

<div class="post-metadata">

**Author:** ![arleaman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/arleaman/32/1339_2.png) [@arleaman](https://forum.generic-mapping-tools.org/u/arleaman)\
**Post date:** [August 12, 2023, 5:11pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/7 "2023-08-12T17:11:11Z")

</div>

Hi! I am having a weird new issue that I think is related to this discussion.

I have a text file that I converted to netCDF. It plots fine as the text file, but the netCDF gives me the following error: “grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline”

These are the commands I performed on my data.  
pygmt.xyz2grd(data=‘data.txt’, spacing=.05, region=[-127.5, -65, 20, 50], outgrid=‘data.nc’)

fig = pygmt.Figure()  
with pygmt.config(MAP\_ANNOT\_OFFSET\_PRIMARY=‘0.1c’):  
fig.basemap(frame=[‘af’], region=[-127.5, -65, 20, 50], projection=‘M6i’)  
pygmt.makecpt(cmap=“vik”, reverse=True, series=[7.55,8.5])  
fig.grdimage(grid=‘data.nc’, cmap=True,)  
fig.show()

 ![Screenshot 2023-08-12 at 11.06.05 AM](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/4/435d8c58ca62fb1d999dedd17288dcc173789104.jpeg)

Please let me know if you have any ideas about which (likely missing) parameter is causing the registration error. Figure.grdimage does not have a registration option, so I’m not sure where to start. Thanks for your help!

---

<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:** [August 14, 2023, 10:21am UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/8 "2023-08-14T10:21:54Z")

</div>

`xyz2grd` ([https://www.pygmt.org/v0.9.0/api/generated/pygmt.xyz2grd.html](https://www.pygmt.org/v0.9.0/api/generated/pygmt.xyz2grd.html)) has a `registration` parameter that defaults to `g` for gridline. Maybe try setting it to `p` for pixel to see if it helps?

Could you also post the output of `gmt grdinfo data.nc` or `print(pygmt.grdinfo('data.nc'))` to see if something is acting up?

---

<div class="post-metadata">

**Author:** ![arleaman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/arleaman/32/1339_2.png) [@arleaman](https://forum.generic-mapping-tools.org/u/arleaman)\
**Post date:** [August 14, 2023, 6:59pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/9 "2023-08-14T18:59:33Z")

</div>

@weiji14 Using the pixel registration gives the error “xyz2grd [WARNING]: 1157 values gave bad indices: Pixel vs Gridline registration confusion?” so I reverted to gridline registration.

And this is the output from grdinfo:

/data.nc: Title:  
/data.nc: Command: gmt xyz2grd /data.txt -G/data.nc -I0.05 -R-127.5/-65/20/50 -rgridline  
/data.nc: Remark:  
/data.nc: Gridline node registration used [Cartesian grid]  
/data.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
/data.nc: x\_min: -127.5 x\_max: -65 x\_inc: 0.05 name: x n\_columns: 1251  
/data.nc: y\_min: 20 y\_max: 50 y\_inc: 0.05 name: y n\_rows: 601  
/data.nc: v\_min: 7.35750007629 v\_max: 8.64949989319 name: z  
/data.nc: scale\_factor: 1 add\_offset: 0  
/data.nc: format: netCDF-4 chunk\_size: 139,151 shuffle: on deflation\_level: 3  
/data.nc: Default CPT:

---

<div class="post-metadata">

**Author:** ![arleaman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/arleaman/32/1339_2.png) [@arleaman](https://forum.generic-mapping-tools.org/u/arleaman)\
**Post date:** [August 14, 2023, 7:12pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/10 "2023-08-14T19:12:38Z")

</div>

For reference, a similar dataset has the following output and does not produce an error:

/v.nc: Title:  
/v.nc: Command: gmt xyz2grd /v.txt -G/v.nc -I0.05 -R-127.5/-65/20/50  
/v.nc: Remark:  
/v.nc: Gridline node registration used [Cartesian grid]  
/v.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7  
/v.nc: x\_min: -127.5 x\_max: -65 x\_inc: 0.05 name: x n\_columns: 1251  
/v.nc: y\_min: 20 y\_max: 50 y\_inc: 0.05 name: y n\_rows: 601  
/v.nc: v\_min: 7.6 v\_max: 8.3 name: z  
/v.nc: scale\_factor: 1 add\_offset: 0  
/v.nc: format: netCDF-4 chunk\_size: 139,151 shuffle: on deflation\_level: 3  
/v.nc: Default CPT:

From what I can tell, the only difference is the z range.

---

<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:** [August 14, 2023, 8:00pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/11 "2023-08-14T20:00:09Z")

</div>

What GMT version?

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [August 14, 2023, 8:38pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/12 "2023-08-14T20:38:14Z")

</div>

> [@arleaman](#):
>
> “grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline”

For me this message is clear. The data (the grid) is confused about its identity. `xx` says is gridline while `yy` pixel registration (or vice-versa).

---

<div class="post-metadata">

**Author:** ![arleaman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/arleaman/32/1339_2.png) [@arleaman](https://forum.generic-mapping-tools.org/u/arleaman)\
**Post date:** [August 14, 2023, 10:44pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/13 "2023-08-14T22:44:32Z")

</div>

@pwessel It’s PyGMT version: v0.9.0  
python: 3.11.4  
machine: macOS-13.5-arm64-arm-64bit

Dependency information:  
numpy: 1.25.2  
pandas: 2.0.3  
xarray: 2023.7.0  
netCDF4: 1.6.4  
packaging: 23.1  
ghostscript: 9.54.0

GMT library information:  
binary version: 6.4.0  
grid layout: rows  
padding: 2  
version: 6.4.0

But I was having this issue before I updated to PyGMT v0.9.0 from v0.7.0

---

<div class="post-metadata">

**Author:** ![seisman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/seisman/32/4_2.png) [@seisman](https://forum.generic-mapping-tools.org/u/seisman)\
**Post date:** [August 14, 2023, 11:29pm UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/14 "2023-08-14T23:29:17Z")

</div>

I think we can provide more useful help if you can upload your data.txt files to the forum or Google Drive.

---

<div class="post-metadata">

**Author:** ![arleaman](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/arleaman/32/1339_2.png) [@arleaman](https://forum.generic-mapping-tools.org/u/arleaman)\
**Post date:** [August 19, 2023, 12:44am UTC](https://forum.generic-mapping-tools.org/t/deciding-on-default-grid-registration-and-grid-type-for-pygmt/583/15 "2023-08-19T00:44:14Z")

</div>

I realized I was using the wrong function 😅 … Sorry for the trouble.  
I haven’t worked with this dataset for awhile and forget this version uses an irregular grid.

Everything works perfectly when I triangulate the data. Thanks for your help!
