Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly allow for either pixel or gridline registered grids #476

Merged
merged 41 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ebd3e00
Add registration (r) to common options
weiji14 Jun 10, 2020
bb7afdc
Allow virtualfile_from_grid to accept a registration argument
weiji14 Jun 10, 2020
08edf6f
Try using GMT_GRID_PIXEL_REG as default instead of GMT_GRID_NODE_REG
weiji14 Jun 19, 2020
8ce734d
Merge branch 'master' into grid_registration
seisman Jun 22, 2020
47b5b68
Let pygmt know about geographic grids
weiji14 Jun 22, 2020
522ceba
Revert back to using Cartesian mode, but be explicit this time
weiji14 Jun 22, 2020
d203cd5
Set valid GMT data mode as GMT_IS_OUTPUT
weiji14 Jun 22, 2020
90b22a4
Revert "Try using GMT_GRID_PIXEL_REG as default instead of GMT_GRID_N…
weiji14 Jun 19, 2020
6d4ece4
Automatically detect grid registration from xarray data source
weiji14 Jun 23, 2020
b252b9d
Prevent segfault crash when passing pixel registered grids on GMT < 6.1
weiji14 Jun 23, 2020
93881c5
Merge branch 'master' into grid_registration
weiji14 Jun 23, 2020
572b499
Have `grdinfo` and `grdtrack` autodetect registration type too
weiji14 Jun 23, 2020
0812c50
Put autodetect_registration code directly inside virtualfile_from_grid
weiji14 Jun 23, 2020
5cb2cee
Lint
weiji14 Jun 23, 2020
16d9240
Autodetect grid type as Cartesian or Geographic coordinate system
weiji14 Jun 25, 2020
046a5e3
Merge branch 'master' into grid_registration
weiji14 Jun 25, 2020
3215b0c
Patch to fix crash when registration is GMT_GRID_PIXEL_REG in GMT 6.0
weiji14 Jun 25, 2020
88ceba2
Separate input and output registration
weiji14 Jun 25, 2020
bc2c2f0
Merge branch 'master' into grid_registration
weiji14 Jun 28, 2020
bff3254
Remove unused-import, silence redefined-outer-name warning
weiji14 Jun 28, 2020
1fc91f8
Expect registration type in dataarray's node_offset attribute
weiji14 Jun 28, 2020
6892e4b
Simplify grid region extent calculation
weiji14 Jun 28, 2020
d8fd6b5
Merge branch 'master' into grid_registration
weiji14 Jun 29, 2020
0e593d8
Expect gtype in dataarray's geocoord_type attribute
weiji14 Jun 29, 2020
00a46ca
Merge branch 'master' into grid_registration
weiji14 Jul 11, 2020
0f84f04
Refactor virtualfile_from_grid and dataarray_to_matrix to use accessor
weiji14 Jul 12, 2020
5c5be94
Fix tests where virtual grid had wrong region, registration and gtype
weiji14 Jul 12, 2020
22dfe74
Expect failures from two grdview tests that used wrong coordinate system
weiji14 Jul 12, 2020
53dc9c9
Fix test_grdimage_over_dateline by using gridline instead of pixel reg
weiji14 Jul 12, 2020
0a73114
Run test_grdimage_over_dateline with debug mode on
weiji14 Jul 12, 2020
fe0fbc5
Replace unnecessary comprehension with generator
weiji14 Jul 12, 2020
5a0c639
Flip grid array left right in xarray instead of in numpy
weiji14 Jul 12, 2020
5a685b2
Deep copy grid using xarray.DataArray.copy instead of numpy.copy
weiji14 Jul 12, 2020
40bc7f9
Merge branch 'master' into grid_registration
weiji14 Jul 15, 2020
d0be1c5
Reduce image size from 1 inch to 1 cm
weiji14 Jul 15, 2020
46c8471
Test with a grid that does not reach the North Pole
weiji14 Jul 15, 2020
3499047
Try just running test_grdimage_over_dateline first before other tests
weiji14 Jul 15, 2020
bf03e5b
Don't use pytest --no-summary which is a pytest 6.0.0rc1 feature
weiji14 Jul 15, 2020
60c791d
Revert "Deep copy grid using xarray.DataArray.copy instead of numpy.c…
weiji14 Jul 12, 2020
c411a95
Say why we need to run test_grdimage_over_dateline before other tests
weiji14 Jul 16, 2020
217a7d7
Register the custom runfirst pytest marker
weiji14 Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def dataarray_to_matrix(grid):
dim
)
)
region.extend([coord.min(), coord.max()])
region.extend([coord.min() - coord_inc / 2, coord.max() + coord_inc / 2])
inc.append(coord_inc)

if any([i < 0 for i in inc]): # Sort grid when there are negative increments
Expand Down
13 changes: 9 additions & 4 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def create_data(self, family, geometry, mode, **kwargs):
registration : int
The node registration (what the coordinates mean). Can be
``'GMT_GRID_PIXEL_REG'`` or ``'GMT_GRID_NODE_REG'``. Defaults to
``'GMT_GRID_NODE_REG'``.
``'GMT_GRID_PIXEL_REG'``.
pad : int
The grid padding. Defaults to ``GMT_PAD_DEFAULT``.

Expand Down Expand Up @@ -565,7 +565,7 @@ def create_data(self, family, geometry, mode, **kwargs):
)
geometry_int = self._parse_constant(geometry, valid=GEOMETRIES)
registration_int = self._parse_constant(
kwargs.get("registration", "GMT_GRID_NODE_REG"), valid=REGISTRATIONS
kwargs.get("registration", "GMT_GRID_PIXEL_REG"), valid=REGISTRATIONS
)

# Convert dim, ranges, and inc to ctypes arrays if given (will be None
Expand Down Expand Up @@ -1171,7 +1171,7 @@ def virtualfile_from_matrix(self, matrix):
yield vfile

@contextmanager
def virtualfile_from_grid(self, grid):
def virtualfile_from_grid(self, grid, registration="GMT_GRID_PIXEL_REG"):
"""
Store a grid in a virtual file.

Expand Down Expand Up @@ -1240,7 +1240,12 @@ def virtualfile_from_grid(self, grid):
family = "GMT_IS_GRID|GMT_VIA_MATRIX"
geometry = "GMT_IS_SURFACE"
gmt_grid = self.create_data(
family, geometry, mode="GMT_CONTAINER_ONLY", ranges=region, inc=inc
family,
geometry,
mode="GMT_CONTAINER_ONLY|GMT_GRID_IS_GEO",
Copy link
Member

@seisman seisman Jun 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I didn't mean this change. Users can pass both Cartesian and geographic grids to GMT. We need to use GMT_CONTAINER_ONLY or GMT_CONTAINER_ONLY|GMT_GRID_IS_GEO for different grid types.

BTW, GMT_CONTAINER_ONLY is equivalent to GMT_CONTAINER_ONLY|GMT_GRID_IS_CARTESIAN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I thought it 'knew' automatically what the grid type was. Should actually get some tests in for this.

BTW, GMT_CONTAINER_ONLY is equivalent to GMT_CONTAINER_ONLY|GMT_GRID_IS_CARTESIAN.

Ok, good to know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ranges=region,
inc=inc,
registration=registration,
)
self.put_matrix(gmt_grid, matrix)
args = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", gmt_grid)
Expand Down
5 changes: 5 additions & 0 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
- 'c' for bicubic [Default]
- 'l' for bilinear
- 'n' for nearest-neighbor""",
"r": """\
registration : str
``[g|p]``
Force gridline (g) or pixel (p) node registration. Default is
gridline.""",
}


Expand Down