Skip to content
Merged
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9c74046
Extend GMTDataAccessor to support grid operations
seisman Mar 15, 2025
fe7612c
Merge branch 'main' into accessor/gridop
seisman Mar 18, 2025
8b95908
Merge branch 'main' into accessor/gridop
seisman Mar 24, 2025
4853128
Add more grid operations to GMTDataArrayAccessor
seisman Mar 24, 2025
8d039aa
Merge branch 'main' into accessor/gridop
seisman Mar 28, 2025
505c9d0
Add docstrings for the new methods
seisman Mar 28, 2025
f49c3d0
Fix docstrings
seisman Mar 28, 2025
58ee6a1
Fix docstrings
seisman Mar 28, 2025
c43e6c6
Merge branch 'main' into accessor/gridop
seisman May 2, 2025
d2527ae
Merge branch 'main' into accessor/gridop
seisman May 4, 2025
49490d5
Update docstrings
seisman May 4, 2025
db42b7a
Add equalize_hist method
seisman May 4, 2025
de29785
Merge branch 'main' into accessor/gridop
seisman May 8, 2025
a341d39
Merge branch 'main' into accessor/gridop
seisman May 10, 2025
ebed146
Merge branch 'main' into accessor/gridop
seisman May 28, 2025
e7445ea
Merge branch 'main' into accessor/gridop
seisman Jun 4, 2025
48c84fe
Merge branch 'main' into accessor/gridop
seisman Jun 24, 2025
d602f71
Merge branch 'main' into accessor/gridop
seisman Jun 25, 2025
397504b
Use functools.wraps
seisman Jun 25, 2025
c3c362c
Add two tests
seisman Jun 25, 2025
3399025
Fix
seisman Jun 25, 2025
1b2aafb
Add a period
seisman Jun 25, 2025
e124192
Fix a typo
seisman Jun 25, 2025
98a322d
Merge branch 'main' into accessor/gridop
seisman Jul 2, 2025
e0ca40b
Merge branch 'main' into accessor/gridop
seisman Jul 13, 2025
d26b56d
Merge remote-tracking branch 'origin/accessor/gridop' into accessor/g…
seisman Jul 13, 2025
5a5fa16
Avoid two unused fixtures
seisman Jul 14, 2025
d6aa952
Merge branch 'main' into accessor/gridop
seisman Jul 15, 2025
39c8c8e
Merge branch 'main' into accessor/gridop
seisman Jul 19, 2025
2d3c6b1
Use histeq for consistency
seisman Jul 19, 2025
c43ae14
Fix the name in tests
seisman Jul 19, 2025
6fd0c50
Fix test name
seisman Jul 19, 2025
7bdf385
Merge branch 'main' into accessor/gridop
seisman Jul 20, 2025
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
85 changes: 84 additions & 1 deletion pygmt/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
import xarray as xr
from pygmt.enums import GridRegistration, GridType
from pygmt.exceptions import GMTInvalidInput
from pygmt.src.grdinfo import grdinfo
from pygmt.src import (
dimfilter,
grdclip,
grdcut,
grdfill,
grdfilter,
grdgradient,
grdinfo,
grdproject,
grdsample,
grdtrack,
)


@xr.register_dataarray_accessor("gmt")
Expand Down Expand Up @@ -176,3 +187,75 @@
)
raise GMTInvalidInput(msg)
self._gtype = GridType(value)

def dimfilter(self, **kwargs) -> xr.DataArray:
"""
Directional filtering of grids in the space domain.
See the :func:`pygmt.dimfilter` function for available parameters.
"""
return dimfilter(grid=self._obj, **kwargs)

Check warning on line 197 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L197

Added line #L197 was not covered by tests

def clip(self, **kwargs) -> xr.DataArray:
"""
Clip the range of grid values.
See the :func:`pygmt.grdclip` function for available parameters.
"""
return grdclip(grid=self._obj, **kwargs)

Check warning on line 205 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L205

Added line #L205 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

Probably best to keep the method name as .gmt.grdclip instead of .gmt.clip, because there is also https://docs.generic-mapping-tools.org/6.5/clip.html (same with the other grd* methods below), and who knows if we might use pandas accessors at some point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even if we decide to implement the pandas accessors in the future (actually, I feel it's a good idea), there are still no conflicts since the two accessors are in different namespaces. E.g.,

  • da.gmt.clip: Clip operation on a xr.DataArray grid/image
  • df.gmt.clip: Clip operation on a pd.DataFrame object


def cut(self, **kwargs) -> xr.DataArray:
"""
Extract subregion from a grid or image or a slice from a cube.
See the :func:`pygmt.grdcut` function for available parameters.
"""
return grdcut(grid=self._obj, **kwargs)

Check warning on line 213 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L213

Added line #L213 was not covered by tests

def fill(self, **kwargs) -> xr.DataArray:
"""
Interpolate across holes in the grid.
See the :func:`pygmt.grdfill` function for available parameters.
"""
return grdfill(grid=self._obj, **kwargs)

Check warning on line 221 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L221

Added line #L221 was not covered by tests

def filter(self, **kwargs) -> xr.DataArray:
"""
Filter a grid in the space (or time) domain.
See the :func:`pygmt.grdfilter` function for available parameters.
"""
return grdfilter(grid=self._obj, **kwargs)

Check warning on line 229 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L229

Added line #L229 was not covered by tests

def gradient(self, **kwargs) -> xr.DataArray:
"""
Compute directional gradients from a grid.
See the :func:`pygmt.grdgradient` function for available parameters.
"""
return grdgradient(grid=self._obj, **kwargs)

Check warning on line 237 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L237

Added line #L237 was not covered by tests

def grdproject(self, **kwargs) -> xr.DataArray:
"""
Forward and inverse map transformation of grids.
See the :func:`pygmt.grdproject` function for available parameters.
"""
return grdproject(grid=self._obj, **kwargs)

Check warning on line 245 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L245

Added line #L245 was not covered by tests

def grdsample(self, **kwargs) -> xr.DataArray:
"""
Resample a grid onto a new lattice.
See the :func:`pygmt.grdsample` function for available parameters.
"""
return grdsample(grid=self._obj, **kwargs)

Check warning on line 253 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L253

Added line #L253 was not covered by tests

def grdtrack(self, **kwargs) -> xr.DataArray:
"""
Sample one or more grids at specified locations.
See the :func:`pygmt.grdtrack` function for available parameters.
"""
return grdtrack(grid=self._obj, **kwargs)

Check warning on line 261 in pygmt/accessors.py

View check run for this annotation

Codecov / codecov/patch

pygmt/accessors.py#L261

Added line #L261 was not covered by tests
Loading