diff --git a/pygmt/accessors.py b/pygmt/accessors.py index ec73f69238f..711778b7d11 100644 --- a/pygmt/accessors.py +++ b/pygmt/accessors.py @@ -6,6 +6,7 @@ from pathlib import Path import xarray as xr +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.src.grdinfo import grdinfo @@ -15,110 +16,122 @@ class GMTDataArrayAccessor: """ GMT accessor for :class:`xarray.DataArray`. - The accessor extends :class:`xarray.DataArray` to store GMT-specific - properties about grids, which are important for PyGMT to correctly process - and plot the grids. + The *gmt* accessor extends :class:`xarray.DataArray` to store GMT-specific + properties for grids, which are important for PyGMT to correctly process and plot + the grids. The *gmt* accessor contains the following properties: - Notes - ----- - - Due to the limitations of xarray accessors, the GMT accessors are created - once per :class:`xarray.DataArray` instance. You may lose these - GMT-specific properties when manipulating grids (e.g., arithmetic and slice - operations) or when accessing a :class:`xarray.DataArray` from a - :class:`xarray.Dataset`. In these cases, you need to manually set these - properties before passing the grid to PyGMT. + - ``registration``: Grid registration type :class:`pygmt.enums.GridRegistration`. + - ``gtype``: Grid coordinate system type :class:`pygmt.enums.GridType`. Examples -------- - - For GMT's built-in remote datasets, these GMT-specific properties are - automatically determined and you can access them as follows: + For GMT's built-in remote datasets, these GMT-specific properties are automatically + determined and you can access them as follows: >>> from pygmt.datasets import load_earth_relief >>> # Use the global Earth relief grid with 1 degree spacing >>> grid = load_earth_relief(resolution="01d", registration="pixel") - >>> # See if grid uses Gridline (0) or Pixel (1) registration + >>> # See if grid uses Gridline or Pixel registration >>> grid.gmt.registration - 1 - >>> # See if grid uses Cartesian (0) or Geographic (1) coordinate system + + >>> # See if grid is in Cartesian or Geographic coordinate system >>> grid.gmt.gtype - 1 + - For :class:`xarray.DataArray` grids created by yourself, grid properties - ``registration`` and ``gtype`` default to 0 (i.e., a gridline-registered, - Cartesian grid). You need to set the correct properties before - passing it to PyGMT functions: + For :class:`xarray.DataArray` grids created by yourself, ``registration`` and + ``gtype`` default to ``GridRegistration.GRIDLINE`` and ``GridType.CARTESIAN`` (i.e., + a gridline-registered, Cartesian grid). You need to set the correct properties + before passing it to PyGMT functions: >>> import numpy as np - >>> import pygmt >>> import xarray as xr - >>> # create a DataArray in gridline coordinates of sin(lon) * cos(lat) + >>> import pygmt + >>> from pygmt.enums import GridRegistration, GridType + >>> # Create a DataArray in gridline coordinates of sin(lon) * cos(lat) >>> interval = 2.5 >>> lat = np.arange(90, -90 - interval, -interval) >>> lon = np.arange(0, 360 + interval, interval) >>> longrid, latgrid = np.meshgrid(lon, lat) >>> data = np.sin(np.deg2rad(longrid)) * np.cos(np.deg2rad(latgrid)) >>> grid = xr.DataArray(data, coords=[("latitude", lat), ("longitude", lon)]) - >>> # default to a gridline-registered Cartesian grid - >>> grid.gmt.registration, grid.gmt.gtype - (0, 0) - >>> # set it to a gridline-registered geographic grid - >>> grid.gmt.registration = 0 - >>> grid.gmt.gtype = 1 - >>> grid.gmt.registration, grid.gmt.gtype - (0, 1) - - Note that the accessors are created once per :class:`xarray.DataArray` - instance, so you may lose these GMT-specific properties after manipulating - your grid. + >>> # Default to a gridline-registered Cartesian grid + >>> grid.gmt.registration + + >>> grid.gmt.gtype + + >>> # Manually set it to a gridline-registered geographic grid + >>> grid.gmt.registration = GridRegistration.GRIDLINE + >>> grid.gmt.gtype = GridType.GEOGRAPHIC + >>> grid.gmt.registration + + >>> grid.gmt.gtype + + + Notes + ----- + Due to the limitations of xarray accessors, the GMT accessors are created once per + :class:`xarray.DataArray` instance. You may lose these GMT-specific properties when + manipulating grids (e.g., arithmetic and slice operations) or when accessing a + :class:`xarray.DataArray` from a :class:`xarray.Dataset`. In these cases, you need + to manually set these properties before passing the grid to PyGMT. Inplace assignment operators like ``*=`` don't create new instances, so the properties are still kept: >>> grid *= 2.0 - >>> grid.gmt.registration, grid.gmt.gtype - (0, 1) + >>> grid.gmt.registration + + >>> grid.gmt.gtype + - Other grid operations (e.g., arithmetic or slice operations) create new - instances, so the properties will be lost: + Other grid operations (e.g., arithmetic or slice operations) create new instances, + so the properties will be lost: >>> # grid2 is a slice of the original grid >>> grid2 = grid[0:30, 50:80] - >>> # properties are reset to the default values for new instance - >>> grid2.gmt.registration, grid2.gmt.gtype - (0, 0) - >>> # need to set these properties before passing the grid to PyGMT + >>> # Properties are reset to the default values for new instance + >>> grid2.gmt.registration + + >>> grid2.gmt.gtype + + >>> # Need to set these properties before passing the grid to PyGMT >>> grid2.gmt.registration = grid.gmt.registration >>> grid2.gmt.gtype = grid.gmt.gtype - >>> grid2.gmt.registration, grid2.gmt.gtype - (0, 1) + >>> grid2.gmt.registration + + >>> grid2.gmt.gtype + - Accessing a :class:`xarray.DataArray` from a :class:`xarray.Dataset` always - creates new instances, so these properties are always lost. The workaround - is to assign the :class:`xarray.DataArray` into a variable: + Accessing a :class:`xarray.DataArray` from a :class:`xarray.Dataset` always creates + new instances, so these properties are always lost. The workaround is to assign the + :class:`xarray.DataArray` into a variable: >>> ds = xr.Dataset({"zval": grid}) + >>> ds.zval.gmt.registration + + >>> ds.zval.gmt.gtype + + >>> # Manually set these properties won't work as expected + >>> ds.zval.gmt.registration = GridRegistration.GRIDLINE + >>> ds.zval.gmt.gtype = GridType.GEOGRAPHIC >>> ds.zval.gmt.registration, ds.zval.gmt.gtype - (0, 0) - >>> # manually set these properties won't work as expected - >>> ds.zval.gmt.registration, ds.zval.gmt.gtype = 0, 1 - >>> ds.zval.gmt.registration, ds.zval.gmt.gtype - (0, 0) + (, ) >>> # workaround: assign the DataArray into a variable >>> zval = ds.zval >>> zval.gmt.registration, zval.gmt.gtype - (0, 0) - >>> zval.gmt.registration, zval.gmt.gtype = 0, 1 + (, ) + >>> zval.gmt.registration = GridRegistration.GRIDLINE + >>> zval.gmt.gtype = GridType.GEOGRAPHIC >>> zval.gmt.registration, zval.gmt.gtype - (0, 1) + (, ) """ def __init__(self, xarray_obj): self._obj = xarray_obj + # Default to Gridline registration and Cartesian grid type - self._registration = 0 - self._gtype = 0 + self._registration = GridRegistration.GRIDLINE + self._gtype = GridType.CARTESIAN # If the source file exists, get grid registration and grid type from the last # two columns of the shortened summary information of grdinfo. @@ -131,33 +144,35 @@ def __init__(self, xarray_obj): @property def registration(self): """ - Registration type of the grid, either 0 (Gridline) or 1 (Pixel). + Grid registration type :class:`pygmt.enums.GridRegistration`. """ return self._registration @registration.setter def registration(self, value): - if value not in {0, 1}: + # TODO(Python>=3.12): Simplify to `if value not in GridRegistration`. + if value not in GridRegistration.__members__.values(): msg = ( - f"Invalid grid registration value: {value}, should be either " - "0 for Gridline registration or 1 for Pixel registration." + f"Invalid grid registration: '{value}'. Should be either " + "GridRegistration.GRIDLINE (0) or GridRegistration.PIXEL (1)." ) raise GMTInvalidInput(msg) - self._registration = value + self._registration = GridRegistration(value) @property def gtype(self): """ - Coordinate system type of the grid, either 0 (Cartesian) or 1 (Geographic). + Grid coordinate system type :class:`pygmt.enums.GridType`. """ return self._gtype @gtype.setter def gtype(self, value): - if value not in {0, 1}: + # TODO(Python>=3.12): Simplify to `if value not in GridType`. + if value not in GridType.__members__.values(): msg = ( - f"Invalid coordinate system type: {value}, should be " - "either 0 for Cartesian or 1 for Geographic." + f"Invalid grid coordinate system type: '{value}'. " + "Should be either GridType.CARTESIAN (0) or GridType.GEOGRAPHIC (1)." ) raise GMTInvalidInput(msg) - self._gtype = value + self._gtype = GridType(value) diff --git a/pygmt/datatypes/grid.py b/pygmt/datatypes/grid.py index 18ad679aeef..8b4426b01c5 100644 --- a/pygmt/datatypes/grid.py +++ b/pygmt/datatypes/grid.py @@ -165,7 +165,7 @@ def to_dataarray(self) -> xr.DataArray: axis: Y actual_range: [-24. -10.] >>> da.gmt.registration, da.gmt.gtype - (1, 1) + (, ) """ # The grid header header = self.header.contents diff --git a/pygmt/datatypes/image.py b/pygmt/datatypes/image.py index 8534bfaacb3..3cd3a106bc1 100644 --- a/pygmt/datatypes/image.py +++ b/pygmt/datatypes/image.py @@ -166,7 +166,7 @@ def to_dataarray(self) -> xr.DataArray: axis: Y actual_range: [-90. 90.] >>> da.gmt.registration, da.gmt.gtype - (1, 1) + (, ) """ # The image header header = self.header.contents diff --git a/pygmt/src/tilemap.py b/pygmt/src/tilemap.py index e61cd82e868..0748c83a2c9 100644 --- a/pygmt/src/tilemap.py +++ b/pygmt/src/tilemap.py @@ -6,6 +6,7 @@ from pygmt.clib import Session from pygmt.datasets.tile_map import load_tile_map +from pygmt.enums import GridType from pygmt.helpers import build_arg_list, fmt_docstring, kwargs_to_strings, use_alias try: @@ -121,7 +122,7 @@ def tilemap( zoom_adjust=zoom_adjust, ) if lonlat: - raster.gmt.gtype = 1 # Set to geographic type + raster.gmt.gtype = GridType.GEOGRAPHIC # Only set region if no_clip is None or False, so that plot is clipped to exact # bounding box region diff --git a/pygmt/tests/test_accessor.py b/pygmt/tests/test_accessor.py index 07ece609b69..7931c39313d 100644 --- a/pygmt/tests/test_accessor.py +++ b/pygmt/tests/test_accessor.py @@ -11,66 +11,96 @@ from pygmt import which from pygmt.clib import __gmt_version__ from pygmt.datasets import load_earth_relief +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput def test_accessor_gridline_cartesian(): """ - Check that a grid returns a registration value of 0 when Gridline registered, and a - gtype value of 1 when using Geographic coordinates. + Check that the accessor returns the correct registration and gtype values for a + Cartesian, gridline-registered grid. """ fname = which(fname="@test.dat.nc", download="a") - grid = xr.open_dataarray(fname) - assert grid.gmt.registration == 0 # gridline registration - assert grid.gmt.gtype == 0 # cartesian coordinate type + grid = xr.open_dataarray(fname, engine="netcdf4") + assert grid.gmt.registration == GridRegistration.GRIDLINE + assert grid.gmt.gtype == GridType.CARTESIAN def test_accessor_pixel_geographic(): """ - Check that a grid returns a registration value of 1 when Pixel registered, and a - gtype value of 0 when using Cartesian coordinates. + Check that the accessor returns the correct registration and gtype values for a + geographic, pixel-registered grid. """ fname = which(fname="@earth_relief_01d_p", download="a") grid = xr.open_dataarray(fname, engine="netcdf4") - assert grid.gmt.registration == 1 # pixel registration - assert grid.gmt.gtype == 1 # geographic coordinate type + assert grid.gmt.registration == GridRegistration.PIXEL + assert grid.gmt.gtype == GridType.GEOGRAPHIC -def test_accessor_set_pixel_registration(): +def test_accessor_set_registration(): """ - Check that we can set a grid to be Pixel registered with a registration value of 1. + Check that we can set the registration of a grid. """ grid = xr.DataArray(data=[[0.1, 0.2], [0.3, 0.4]]) - assert grid.gmt.registration == 0 # default to gridline registration - grid.gmt.registration = 1 # set to pixel registration - assert grid.gmt.registration == 1 # ensure changed to pixel registration + # Default to gridline registration + assert grid.gmt.registration == GridRegistration.GRIDLINE == 0 + + # Set the registration to pixel + grid.gmt.registration = GridRegistration.PIXEL + assert grid.gmt.registration == GridRegistration.PIXEL == 1 + + # Set the registration to gridline + grid.gmt.registration = GridRegistration.GRIDLINE + assert grid.gmt.registration == GridRegistration.GRIDLINE == 0 + + # Set the registration to pixel but using a numerical value + grid.gmt.registration = 1 + assert grid.gmt.registration == GridRegistration.PIXEL == 1 + + # Set the registration to gridline but using a numerical value + grid.gmt.registration = 0 + assert grid.gmt.registration == GridRegistration.GRIDLINE == 0 @pytest.mark.benchmark -def test_accessor_set_geographic_cartesian_roundtrip(): +def test_accessor_set_gtype(): """ - Check that we can set a grid to switch between the default Cartesian coordinate type - using a gtype of 1, set it to Geographic 0, and then back to Cartesian again 1. + Check that we can set the gtype of a grid. """ grid = xr.DataArray(data=[[0.1, 0.2], [0.3, 0.4]]) - assert grid.gmt.gtype == 0 # default to cartesian coordinate type - grid.gmt.gtype = 1 # set to geographic type - assert grid.gmt.gtype == 1 # ensure changed to geographic coordinate type - grid.gmt.gtype = 0 # set back to cartesian type - assert grid.gmt.gtype == 0 # ensure changed to cartesian coordinate type + assert grid.gmt.gtype == GridType.CARTESIAN == 0 # Default gtype + + # Set the gtype to geographic + grid.gmt.gtype = GridType.GEOGRAPHIC + assert grid.gmt.gtype == GridType.GEOGRAPHIC == 1 + # Set the gtype to Cartesian + grid.gmt.gtype = GridType.CARTESIAN + assert grid.gmt.gtype == GridType.CARTESIAN == 0 -def test_accessor_set_non_boolean(): + # Set the gtype to geographic but using a numerical value + grid.gmt.gtype = 1 + assert grid.gmt.gtype == GridType.GEOGRAPHIC == 1 + + # Set the gtype to Cartesian but using a numerical value + grid.gmt.gtype = 0 + assert grid.gmt.gtype == GridType.CARTESIAN == 0 + + +def test_accessor_set_invalid_registration_and_gtype(): """ - Check that setting non boolean values on registration and gtype do not work. + Check that setting invalid values on registration and gtype do not work. """ grid = xr.DataArray(data=[[0.1, 0.2], [0.3, 0.4]]) with pytest.raises(GMTInvalidInput): grid.gmt.registration = "2" - + with pytest.raises(GMTInvalidInput): + grid.gmt.registration = "pixel" with pytest.raises(GMTInvalidInput): grid.gmt.gtype = 2 + with pytest.raises(GMTInvalidInput): + grid.gmt.gtype = "geographic" # TODO(GMT>=6.5.0): Remove the xfail marker for GMT>=6.5.0. @@ -94,8 +124,8 @@ def test_accessor_sliced_datacube(): with xr.open_dataset(fname) as dataset: grid = dataset.sel(level=500, month=1, drop=True).z - assert grid.gmt.registration == 0 # gridline registration - assert grid.gmt.gtype == 1 # geographic coordinate type + assert grid.gmt.registration == GridRegistration.GRIDLINE + assert grid.gmt.gtype == GridType.GEOGRAPHIC finally: Path(fname).unlink() @@ -105,24 +135,24 @@ def test_accessor_grid_source_file_not_exist(): Check that the accessor fallbacks to the default registration and gtype when the grid source file (i.e., grid.encoding["source"]) doesn't exist. """ - # Load the 05m earth relief grid, which is stored as tiles + # Load the 05m earth relief grid, which is stored as tiles. grid = load_earth_relief( resolution="05m", region=[0, 5, -5, 5], registration="pixel" ) - # Registration and gtype are correct - assert grid.gmt.registration == 1 - assert grid.gmt.gtype == 1 + # Registration and gtype are correct. + assert grid.gmt.registration == GridRegistration.PIXEL + assert grid.gmt.gtype == GridType.GEOGRAPHIC # The source grid file is undefined. assert grid.encoding.get("source") is None - # For a sliced grid, fallback to default registration and gtype, - # because the source grid file doesn't exist. + # For a sliced grid, fallback to default registration and gtype, because the source + # grid file doesn't exist. sliced_grid = grid[1:3, 1:3] - assert sliced_grid.gmt.registration == 0 - assert sliced_grid.gmt.gtype == 0 - - # Still possible to manually set registration and gtype - sliced_grid.gmt.registration = 1 - sliced_grid.gmt.gtype = 1 - assert sliced_grid.gmt.registration == 1 - assert sliced_grid.gmt.gtype == 1 + assert sliced_grid.gmt.registration == GridRegistration.GRIDLINE + assert sliced_grid.gmt.gtype == GridType.CARTESIAN + + # Still possible to manually set registration and gtype. + sliced_grid.gmt.registration = GridRegistration.PIXEL + sliced_grid.gmt.gtype = GridType.GEOGRAPHIC + assert sliced_grid.gmt.registration == GridRegistration.PIXEL + assert sliced_grid.gmt.gtype == GridType.GEOGRAPHIC diff --git a/pygmt/tests/test_binstats.py b/pygmt/tests/test_binstats.py index b8a1a39e8ad..eeaa22020d5 100644 --- a/pygmt/tests/test_binstats.py +++ b/pygmt/tests/test_binstats.py @@ -7,6 +7,7 @@ import numpy.testing as npt import pytest from pygmt import binstats +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile @@ -42,8 +43,8 @@ def test_binstats_no_outgrid(): region="g", ) assert temp_grid.dims == ("y", "x") - assert temp_grid.gmt.gtype == 0 # Cartesian grid - assert temp_grid.gmt.registration == 0 # Gridline registration + assert temp_grid.gmt.gtype == GridType.CARTESIAN + assert temp_grid.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(temp_grid.max(), 35971536) npt.assert_allclose(temp_grid.min(), 53) npt.assert_allclose(temp_grid.median(), 1232714.5) diff --git a/pygmt/tests/test_datasets_earth_age.py b/pygmt/tests/test_datasets_earth_age.py index 67ade3dd3d9..3407ac0776a 100644 --- a/pygmt/tests/test_datasets_earth_age.py +++ b/pygmt/tests/test_datasets_earth_age.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_age +from pygmt.enums import GridRegistration def test_earth_age_01d(): @@ -18,7 +19,7 @@ def test_earth_age_01d(): assert data.attrs["units"] == "Myr" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), 0.37, atol=0.01) @@ -31,7 +32,7 @@ def test_earth_age_01d_with_region(): """ data = load_earth_age(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 11.13, atol=0.01) @@ -45,7 +46,7 @@ def test_earth_age_01m_default_registration(): """ data = load_earth_age(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_earth_day.py b/pygmt/tests/test_datasets_earth_day.py index f04d7f7f970..f04269135f8 100644 --- a/pygmt/tests/test_datasets_earth_day.py +++ b/pygmt/tests/test_datasets_earth_day.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_blue_marble +from pygmt.enums import GridRegistration, GridType def test_blue_marble_01d(): @@ -18,8 +19,8 @@ def test_blue_marble_01d(): assert data.attrs["description"] == "NASA Day Images" assert data.shape == (3, 180, 360) assert data.dtype == "uint8" - assert data.gmt.registration == 1 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.PIXEL + assert data.gmt.gtype == GridType.GEOGRAPHIC npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1)) npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1)) npt.assert_allclose(data.min(), 10, atol=1) @@ -33,8 +34,8 @@ def test_blue_marble_01d_with_region(): data = load_blue_marble(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (3, 10, 20) assert data.dtype == "uint8" - assert data.gmt.registration == 1 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.PIXEL + assert data.gmt.gtype == GridType.GEOGRAPHIC npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1)) npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1)) npt.assert_allclose(data.min(), 10, atol=1) diff --git a/pygmt/tests/test_datasets_earth_deflection.py b/pygmt/tests/test_datasets_earth_deflection.py index 9118779a379..a30eab07902 100644 --- a/pygmt/tests/test_datasets_earth_deflection.py +++ b/pygmt/tests/test_datasets_earth_deflection.py @@ -6,6 +6,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_deflection +from pygmt.enums import GridRegistration def test_earth_edefl_01d(): @@ -19,7 +20,7 @@ def test_earth_edefl_01d(): assert data.attrs["units"] == "micro-radians" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -142.64, atol=0.04) @@ -32,7 +33,7 @@ def test_earth_edefl_01d_with_region(): """ data = load_earth_deflection(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -28.92, atol=0.04) @@ -46,7 +47,7 @@ def test_earth_edefl_01m_default_registration(): """ data = load_earth_deflection(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (120, 60) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) @@ -66,7 +67,7 @@ def test_earth_ndefl_01d(): assert data.attrs["units"] == "micro-radians" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -214.8, atol=0.04) @@ -81,7 +82,7 @@ def test_earth_ndefl_01d_with_region(): resolution="01d", region=[-10, 10, -5, 5], component="north" ) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -48.08, atol=0.04) @@ -97,7 +98,7 @@ def test_earth_ndefl_01m_default_registration(): resolution="01m", region=[-10, -9, 3, 5], component="north" ) assert data.shape == (120, 60) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index a5f61a0b5f2..78c2b24c988 100644 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_dist +from pygmt.enums import GridRegistration def test_earth_dist_01d(): @@ -17,7 +18,7 @@ def test_earth_dist_01d(): assert data.attrs["units"] == "kilometers" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -2655.7, atol=0.01) @@ -30,7 +31,7 @@ def test_earth_dist_01d_with_region(): """ data = load_earth_dist(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -1081.94, atol=0.01) @@ -44,7 +45,7 @@ def test_earth_dist_01m_default_registration(): """ data = load_earth_dist(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_earth_free_air_anomaly.py b/pygmt/tests/test_datasets_earth_free_air_anomaly.py index 7ce5fc2662c..a60c1fec2e6 100644 --- a/pygmt/tests/test_datasets_earth_free_air_anomaly.py +++ b/pygmt/tests/test_datasets_earth_free_air_anomaly.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_free_air_anomaly +from pygmt.enums import GridRegistration def test_earth_faa_01d(): @@ -18,7 +19,7 @@ def test_earth_faa_01d(): assert data.attrs["units"] == "mGal" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -188.85, atol=0.025) @@ -31,7 +32,7 @@ def test_earth_faa_01d_with_region(): """ data = load_earth_free_air_anomaly(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -36.125, atol=0.025) @@ -45,7 +46,7 @@ def test_earth_faa_01m_default_registration(): """ data = load_earth_free_air_anomaly(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (120, 60) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) @@ -65,7 +66,7 @@ def test_earth_faaerror_01d(): assert data.attrs["units"] == "mGal" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), 0.0, atol=0.04) @@ -80,7 +81,7 @@ def test_earth_faaerror_01d_with_region(): resolution="01d", region=[-10, 10, -5, 5], uncertainty=True ) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 0.72, atol=0.04) @@ -96,7 +97,7 @@ def test_earth_faaerror_01m_default_registration(): resolution="01m", region=[-10, -9, 3, 5], uncertainty=True ) assert data.shape == (120, 60) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) diff --git a/pygmt/tests/test_datasets_earth_geoid.py b/pygmt/tests/test_datasets_earth_geoid.py index af72969b032..bb7f09102d9 100644 --- a/pygmt/tests/test_datasets_earth_geoid.py +++ b/pygmt/tests/test_datasets_earth_geoid.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_geoid +from pygmt.enums import GridRegistration def test_earth_geoid_01d(): @@ -18,7 +19,7 @@ def test_earth_geoid_01d(): assert data.attrs["units"] == "meters" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -106.06, atol=0.01) @@ -31,7 +32,7 @@ def test_earth_geoid_01d_with_region(): """ data = load_earth_geoid(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 5.57, atol=0.01) @@ -45,7 +46,7 @@ def test_earth_geoid_01m_default_registration(): """ data = load_earth_geoid(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py index 65e1a57601c..e580e565094 100644 --- a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py +++ b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py @@ -6,6 +6,7 @@ import numpy.testing as npt import pytest from pygmt.datasets import load_earth_magnetic_anomaly +from pygmt.enums import GridRegistration from pygmt.exceptions import GMTInvalidInput @@ -20,7 +21,7 @@ def test_earth_mag_01d(): assert data.attrs["units"] == "nT" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -336.2, atol=0.2) @@ -33,7 +34,7 @@ def test_earth_mag_01d_with_region(): """ data = load_earth_magnetic_anomaly(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -54.4, atol=0.2) @@ -47,7 +48,7 @@ def test_earth_mag_02m_default_registration(): """ data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5]) assert data.shape == (60, 30) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667) npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333) npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333) @@ -67,7 +68,7 @@ def test_earth_mag4km_01d(): assert data.attrs["units"] == "nT" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -436.8, atol=0.2) @@ -102,7 +103,7 @@ def test_earth_mag4km_02m_default_registration(): data_source="emag2_4km", ) assert data.shape == (60, 90) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 4.01666667) npt.assert_allclose(data.coords["lat"].data.max(), 5.98333333) npt.assert_allclose(data.coords["lon"].data.min(), -114.98333333) @@ -154,7 +155,7 @@ def test_earth_mag_03m_wdmam_with_region(): data = load_earth_magnetic_anomaly( resolution="03m", region=[10, 13, -60, -58], data_source="wdmam" ) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.shape == (41, 61) assert data.lat.min() == -60 assert data.lat.max() == -58 diff --git a/pygmt/tests/test_datasets_earth_mask.py b/pygmt/tests/test_datasets_earth_mask.py index c449e1a79a7..3e33ab1172b 100644 --- a/pygmt/tests/test_datasets_earth_mask.py +++ b/pygmt/tests/test_datasets_earth_mask.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_mask +from pygmt.enums import GridRegistration, GridType def test_earth_mask_01d(): @@ -16,8 +17,8 @@ def test_earth_mask_01d(): assert data.attrs["description"] == "GSHHG Earth mask" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.GRIDLINE + assert data.gmt.gtype == GridType.GEOGRAPHIC assert data.dtype == "int8" npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) @@ -32,8 +33,8 @@ def test_earth_mask_01d_with_region(): """ data = load_earth_mask(resolution="01d", region=[-7, 4, 13, 19]) assert data.shape == (7, 12) - assert data.gmt.registration == 0 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.GRIDLINE + assert data.gmt.gtype == GridType.GEOGRAPHIC assert data.dtype == "int8" npt.assert_allclose(data.lat, np.arange(13, 20, 1)) npt.assert_allclose(data.lon, np.arange(-7, 5, 1)) diff --git a/pygmt/tests/test_datasets_earth_mean_sea_surface.py b/pygmt/tests/test_datasets_earth_mean_sea_surface.py index 84b2b7123cc..7206cbf911f 100644 --- a/pygmt/tests/test_datasets_earth_mean_sea_surface.py +++ b/pygmt/tests/test_datasets_earth_mean_sea_surface.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_mean_sea_surface +from pygmt.enums import GridRegistration def test_earth_mss_01d(): @@ -17,7 +18,7 @@ def test_earth_mss_01d(): assert data.attrs["units"] == "meters" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -104.71, atol=0.01) @@ -30,7 +31,7 @@ def test_earth_mss_01d_with_region(): """ data = load_earth_mean_sea_surface(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 6.53, atol=0.01) @@ -44,7 +45,7 @@ def test_earth_mss_01m_default_registration(): """ data = load_earth_mean_sea_surface(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_earth_night.py b/pygmt/tests/test_datasets_earth_night.py index dd6b3374033..0865feaa1e8 100644 --- a/pygmt/tests/test_datasets_earth_night.py +++ b/pygmt/tests/test_datasets_earth_night.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_black_marble +from pygmt.enums import GridRegistration, GridType def test_black_marble_01d(): @@ -18,8 +19,8 @@ def test_black_marble_01d(): assert data.attrs["description"] == "NASA Night Images" assert data.shape == (3, 180, 360) assert data.dtype == "uint8" - assert data.gmt.registration == 1 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.PIXEL + assert data.gmt.gtype == GridType.GEOGRAPHIC npt.assert_allclose(data.y, np.arange(89.5, -90.5, -1)) npt.assert_allclose(data.x, np.arange(-179.5, 180.5, 1)) npt.assert_allclose(data.min(), 3, atol=1) @@ -33,8 +34,8 @@ def test_black_marble_01d_with_region(): data = load_black_marble(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (3, 10, 20) assert data.dtype == "uint8" - assert data.gmt.registration == 1 - assert data.gmt.gtype == 1 + assert data.gmt.registration == GridRegistration.PIXEL + assert data.gmt.gtype == GridType.GEOGRAPHIC npt.assert_allclose(data.y, np.arange(4.5, -5.5, -1)) npt.assert_allclose(data.x, np.arange(-9.5, 10.5, 1)) npt.assert_allclose(data.min(), 3, atol=1) diff --git a/pygmt/tests/test_datasets_earth_relief.py b/pygmt/tests/test_datasets_earth_relief.py index b0851430907..73f543915a5 100644 --- a/pygmt/tests/test_datasets_earth_relief.py +++ b/pygmt/tests/test_datasets_earth_relief.py @@ -8,6 +8,7 @@ from packaging.version import Version from pygmt.clib import __gmt_version__ from pygmt.datasets import load_earth_relief +from pygmt.enums import GridRegistration from pygmt.exceptions import GMTInvalidInput @@ -25,7 +26,7 @@ def test_earth_relief_01d_igpp_synbath(data_source): assert data.attrs["vertical_datum"] == "EGM96" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -7174.0, atol=0.5) @@ -45,7 +46,7 @@ def test_earth_relief_01d_gebco(data_source): assert data.attrs["vertical_datum"] == "EGM96" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -7169.0, atol=1.0) @@ -62,7 +63,7 @@ def test_earth_relief_01d_with_region_srtm(): data_source="igpp", ) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5118.0, atol=0.5) @@ -79,7 +80,7 @@ def test_earth_relief_01d_with_region_gebco(): data_source="gebco", ) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5118.0, atol=1.0) @@ -92,7 +93,7 @@ def test_earth_relief_30m(): """ data = load_earth_relief(resolution="30m") assert data.shape == (361, 721) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 90.5, 0.5)) npt.assert_allclose(data.lon, np.arange(-180, 180.5, 0.5)) npt.assert_allclose(data.min(), -8279.5, atol=0.5) @@ -110,7 +111,7 @@ def test_earth_gebcosi_15m_with_region(): data_source="gebcosi", ) assert data.shape == (16, 8) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.lat, np.arange(-87.875, -84, 0.25)) npt.assert_allclose(data.lon, np.arange(85.125, 87, 0.25)) npt.assert_allclose(data.min(), -492, atol=1.0) @@ -183,7 +184,7 @@ def test_earth_relief_15s_default_registration(): """ data = load_earth_relief(resolution="15s", region=[-10, -9.5, 4, 5]) assert data.shape == (240, 120) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 4.002083) npt.assert_allclose(data.coords["lat"].data.max(), 4.997917) npt.assert_allclose(data.coords["lon"].data.min(), -9.997917) @@ -204,7 +205,7 @@ def test_earth_relief_03s_default_registration(): """ data = load_earth_relief(resolution="03s", region=[-10, -9.8, 4.9, 5]) assert data.shape == (121, 241) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.coords["lat"].data.min(), 4.9) npt.assert_allclose(data.coords["lat"].data.max(), 5) npt.assert_allclose(data.coords["lon"].data.min(), -10) diff --git a/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py b/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py index 67070e46541..9851f8ceea9 100644 --- a/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py +++ b/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_vertical_gravity_gradient +from pygmt.enums import GridRegistration def test_earth_vertical_gravity_gradient_01d(): @@ -18,7 +19,7 @@ def test_earth_vertical_gravity_gradient_01d(): assert data.attrs["units"] == "Eotvos" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -40.1875, atol=1 / 32) @@ -34,7 +35,7 @@ def test_earth_vertical_gravity_gradient_01d_with_region(): resolution="01d", region=[-10, 10, -5, 5] ) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5.34375, atol=1 / 32) @@ -50,7 +51,7 @@ def test_earth_vertical_gravity_gradient_01m_default_registration(): resolution="01m", region=[-10, -9, 3, 5] ) assert data.shape == (120, 60) - assert data.gmt.registration == 1 + assert data.gmt.registration == GridRegistration.PIXEL npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) diff --git a/pygmt/tests/test_datasets_load_remote_datasets.py b/pygmt/tests/test_datasets_load_remote_datasets.py index b2de1ebddfa..1f0c49bc4ed 100644 --- a/pygmt/tests/test_datasets_load_remote_datasets.py +++ b/pygmt/tests/test_datasets_load_remote_datasets.py @@ -4,6 +4,7 @@ import pytest from pygmt.datasets.load_remote_dataset import _load_remote_dataset +from pygmt.enums import GridRegistration from pygmt.exceptions import GMTInvalidInput @@ -30,7 +31,7 @@ def test_load_remote_dataset_benchmark_with_region(): assert data.attrs["long_name"] == "ages (Myr)" assert data.attrs["units"] == "Myr" assert data.attrs["horizontal_datum"] == "WGS84" - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.shape == (11, 21) # Can't access the cpt attribute using virtual files # assert data.attrs["cpt"] == "@earth_age.cpt" diff --git a/pygmt/tests/test_datasets_mars_relief.py b/pygmt/tests/test_datasets_mars_relief.py index 88c437848f6..e60265b6044 100644 --- a/pygmt/tests/test_datasets_mars_relief.py +++ b/pygmt/tests/test_datasets_mars_relief.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_mars_relief +from pygmt.enums import GridRegistration def test_mars_relief_01d(): @@ -17,7 +18,7 @@ def test_mars_relief_01d(): assert data.attrs["description"] == "NASA Mars (MOLA) relief" assert data.attrs["units"] == "meters" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -7421.0, atol=0.5) @@ -30,7 +31,7 @@ def test_mars_relief_01d_with_region(): """ data = load_mars_relief(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -2502.0, atol=0.5) @@ -44,7 +45,7 @@ def test_mars_relief_01m_default_registration(): """ data = load_mars_relief(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_mean_dynamic_topography.py b/pygmt/tests/test_datasets_mean_dynamic_topography.py index deae6e90a60..c373b727e79 100644 --- a/pygmt/tests/test_datasets_mean_dynamic_topography.py +++ b/pygmt/tests/test_datasets_mean_dynamic_topography.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_earth_mean_dynamic_topography +from pygmt.enums import GridRegistration def test_earth_mdt_01d(): @@ -17,7 +18,7 @@ def test_earth_mdt_01d(): assert data.attrs["units"] == "meters" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -1.4668, atol=0.0001) @@ -30,7 +31,7 @@ def test_earth_mdt_01d_with_region(): """ data = load_earth_mean_dynamic_topography(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 0.346, atol=0.0001) @@ -44,7 +45,7 @@ def test_earth_mdt_07m_default_registration(): """ data = load_earth_mean_dynamic_topography(resolution="07m", region=[-10, -9, 3, 5]) assert data.shape == (17, 9) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_mercury_relief.py b/pygmt/tests/test_datasets_mercury_relief.py index 65dbe62e0d1..a81af88066e 100644 --- a/pygmt/tests/test_datasets_mercury_relief.py +++ b/pygmt/tests/test_datasets_mercury_relief.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_mercury_relief +from pygmt.enums import GridRegistration def test_mercury_relief_01d(): @@ -17,7 +18,7 @@ def test_mercury_relief_01d(): assert data.attrs["description"] == "USGS Mercury relief" assert data.attrs["units"] == "meters" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -5103.5, atol=0.5) @@ -30,7 +31,7 @@ def test_mercury_relief_01d_with_region(): """ data = load_mercury_relief(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -327.0, atol=0.5) @@ -44,7 +45,7 @@ def test_mercury_relief_01m_default_registration(): """ data = load_mercury_relief(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_moon_relief.py b/pygmt/tests/test_datasets_moon_relief.py index 87f10ded098..50d20e910ee 100644 --- a/pygmt/tests/test_datasets_moon_relief.py +++ b/pygmt/tests/test_datasets_moon_relief.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_moon_relief +from pygmt.enums import GridRegistration def test_moon_relief_01d(): @@ -17,7 +18,7 @@ def test_moon_relief_01d(): assert data.attrs["description"] == "USGS Moon (LOLA) relief" assert data.attrs["units"] == "meters" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -7669.0, atol=0.5) @@ -30,7 +31,7 @@ def test_moon_relief_01d_with_region(): """ data = load_moon_relief(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -1122.0, atol=0.5) @@ -44,7 +45,7 @@ def test_moon_relief_01m_default_registration(): """ data = load_moon_relief(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_pluto_relief.py b/pygmt/tests/test_datasets_pluto_relief.py index 9979f5915a5..dd6ac599ab4 100644 --- a/pygmt/tests/test_datasets_pluto_relief.py +++ b/pygmt/tests/test_datasets_pluto_relief.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_pluto_relief +from pygmt.enums import GridRegistration def test_pluto_relief_01d(): @@ -17,7 +18,7 @@ def test_pluto_relief_01d(): assert data.attrs["description"] == "USGS Pluto relief" assert data.attrs["units"] == "meters" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -3021.0, atol=0.25) @@ -30,7 +31,7 @@ def test_pluto_relief_01d_with_region(): """ data = load_pluto_relief(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -1319.25, atol=0.25) @@ -44,7 +45,7 @@ def test_pluto_relief_01m_default_registration(): """ data = load_pluto_relief(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_datasets_venus_relief.py b/pygmt/tests/test_datasets_venus_relief.py index f2dc9a9489f..2790ad247e7 100644 --- a/pygmt/tests/test_datasets_venus_relief.py +++ b/pygmt/tests/test_datasets_venus_relief.py @@ -5,6 +5,7 @@ import numpy as np import numpy.testing as npt from pygmt.datasets import load_venus_relief +from pygmt.enums import GridRegistration def test_venus_relief_01d(): @@ -17,7 +18,7 @@ def test_venus_relief_01d(): assert data.attrs["description"] == "NASA Magellan Venus relief" assert data.attrs["units"] == "meters" assert data.shape == (181, 361) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -2069.0, atol=0.5) @@ -30,7 +31,7 @@ def test_venus_relief_01d_with_region(): """ data = load_venus_relief(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -1244.0, atol=0.5) @@ -44,7 +45,7 @@ def test_venus_relief_01m_default_registration(): """ data = load_venus_relief(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) - assert data.gmt.registration == 0 + assert data.gmt.registration == GridRegistration.GRIDLINE assert data.coords["lat"].data.min() == 3.0 assert data.coords["lat"].data.max() == 5.0 assert data.coords["lon"].data.min() == -10.0 diff --git a/pygmt/tests/test_dimfilter.py b/pygmt/tests/test_dimfilter.py index 9e998ac9980..3de660e9b4b 100644 --- a/pygmt/tests/test_dimfilter.py +++ b/pygmt/tests/test_dimfilter.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import dimfilter, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -69,8 +70,8 @@ def test_dimfilter_no_outgrid(grid, expected_grid): grid=grid, filter="m600", distance=4, sectors="l6", region=[-55, -51, -24, -19] ) assert result.dims == ("lat", "lon") - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL xr.testing.assert_allclose(a=result, b=expected_grid) diff --git a/pygmt/tests/test_grdclip.py b/pygmt/tests/test_grdclip.py index a0f2e4a8d7c..d759e28eb91 100644 --- a/pygmt/tests/test_grdclip.py +++ b/pygmt/tests/test_grdclip.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import grdclip, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -51,8 +52,8 @@ def test_grdclip_outgrid(grid, expected_grid): assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists temp_grid = load_dataarray(tmpfile.name) assert temp_grid.dims == ("lat", "lon") - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 1 # Pixel registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.PIXEL xr.testing.assert_allclose(a=temp_grid, b=expected_grid) @@ -65,6 +66,6 @@ def test_grdclip_no_outgrid(grid, expected_grid): grid=grid, below=[550, -1000], above=[700, 1000], region=[-53, -49, -19, -16] ) assert temp_grid.dims == ("lat", "lon") - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 1 # Pixel registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.PIXEL xr.testing.assert_allclose(a=temp_grid, b=expected_grid) diff --git a/pygmt/tests/test_grdfill.py b/pygmt/tests/test_grdfill.py index f7c4730b744..8d36125c279 100644 --- a/pygmt/tests/test_grdfill.py +++ b/pygmt/tests/test_grdfill.py @@ -8,6 +8,7 @@ import pytest import xarray as xr from pygmt import grdfill, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -78,8 +79,8 @@ def test_grdfill_dataarray_out(grid, expected_grid): result = grdfill(grid=grid, mode="c20") # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) @@ -93,8 +94,8 @@ def test_grdfill_asymmetric_pad(grid, expected_grid): result = grdfill(grid=grid, mode="c20", region=[-55, -50, -24, -16]) # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose( a=result, b=expected_grid.sel(lon=slice(-55, -50), lat=slice(-24, -16)) diff --git a/pygmt/tests/test_grdfilter.py b/pygmt/tests/test_grdfilter.py index 5cbe3574767..67c94f6a52c 100644 --- a/pygmt/tests/test_grdfilter.py +++ b/pygmt/tests/test_grdfilter.py @@ -8,6 +8,7 @@ import pytest import xarray as xr from pygmt import grdfilter, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -50,8 +51,8 @@ def test_grdfilter_dataarray_in_dataarray_out(grid, expected_grid): ) # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) diff --git a/pygmt/tests/test_grdgradient.py b/pygmt/tests/test_grdgradient.py index dc082d50d90..c8b6695fa7d 100644 --- a/pygmt/tests/test_grdgradient.py +++ b/pygmt/tests/test_grdgradient.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import grdgradient, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -66,8 +67,8 @@ def test_grdgradient_no_outgrid(grid, expected_grid): ) # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) diff --git a/pygmt/tests/test_grdhisteq.py b/pygmt/tests/test_grdhisteq.py index 3c5a3df2d8d..3a9f0740adf 100644 --- a/pygmt/tests/test_grdhisteq.py +++ b/pygmt/tests/test_grdhisteq.py @@ -9,6 +9,7 @@ import pytest import xarray as xr from pygmt import grdhisteq, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -78,8 +79,8 @@ def test_equalize_grid_no_outgrid(grid, expected_grid, region): temp_grid = grdhisteq.equalize_grid( grid=grid, divisions=2, region=region, outgrid=None ) - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 1 # Pixel registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.PIXEL xr.testing.assert_allclose(a=temp_grid, b=expected_grid) diff --git a/pygmt/tests/test_grdimage.py b/pygmt/tests/test_grdimage.py index 907886eb0b3..9f11e6a2923 100644 --- a/pygmt/tests/test_grdimage.py +++ b/pygmt/tests/test_grdimage.py @@ -9,6 +9,7 @@ from pygmt import Figure from pygmt.clib import __gmt_version__ from pygmt.datasets import load_earth_relief +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers.testing import check_figures_equal @@ -164,14 +165,15 @@ def test_grdimage_over_dateline(xrgrid): """ Ensure no gaps are plotted over the 180 degree international dateline. - Specifically checking that `xrgrid.gmt.gtype = 1` sets `GMT_GRID_IS_GEO`, - and that `xrgrid.gmt.registration = 0` sets `GMT_GRID_NODE_REG`. Note that - there would be a gap over the dateline if a pixel registered grid is used. + Specifically checking that ``xrgrid.gmt.gtype = GridType.GEOGRAPHIC`` sets + ``GMT_GRID_IS_GEO``, and that ``xrgrid.gmt.registration = GridRegistration.GRIDLINE` + sets ``GMT_GRID_NODE_REG``. Note that there would be a gap over the dateline if a + pixel-registered grid is used. See also https://github.com/GenericMappingTools/pygmt/issues/375. """ fig = Figure() - assert xrgrid.gmt.registration == 0 # gridline registration - xrgrid.gmt.gtype = 1 # geographic coordinate system + assert xrgrid.gmt.registration == GridRegistration.GRIDLINE + xrgrid.gmt.gtype = GridType.GEOGRAPHIC fig.grdimage(grid=xrgrid, region="g", projection="A0/0/1c") return fig @@ -188,8 +190,8 @@ def test_grdimage_global_subset(grid_360): """ # Get a slice of South America and Africa only (lat=-90:31, lon=-180:41) sliced_grid = grid_360[0:121, 0:221] - assert sliced_grid.gmt.registration == 0 # gridline registration - assert sliced_grid.gmt.gtype == 0 # Cartesian coordinate system + assert sliced_grid.gmt.registration == GridRegistration.GRIDLINE + assert sliced_grid.gmt.gtype == GridType.CARTESIAN fig = Figure() fig.grdimage( @@ -275,14 +277,16 @@ def test_grdimage_grid_no_redundant_360(): # Global grid [-180, 179, -90, 90] without redundant longitude at 180/-180 da3 = da1[:, 0:360] - da3.gmt.registration, da3.gmt.gtype = 0, 1 + da3.gmt.registration = GridRegistration.GRIDLINE + da3.gmt.gtype = GridType.GEOGRAPHIC assert da3.shape == (181, 360) assert da3.lon.to_numpy().min() == -180.0 assert da3.lon.to_numpy().max() == 179.0 # Global grid [0, 359, -90, 90] without redundant longitude at 360/0 da4 = da2[:, 0:360] - da4.gmt.registration, da4.gmt.gtype = 0, 1 + da4.gmt.registration = GridRegistration.GRIDLINE + da4.gmt.gtype = GridType.GEOGRAPHIC assert da4.shape == (181, 360) assert da4.lon.to_numpy().min() == 0.0 assert da4.lon.to_numpy().max() == 359.0 diff --git a/pygmt/tests/test_grdlandmask.py b/pygmt/tests/test_grdlandmask.py index ae51ba2eda4..bfae4cc965c 100644 --- a/pygmt/tests/test_grdlandmask.py +++ b/pygmt/tests/test_grdlandmask.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import grdlandmask, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -53,8 +54,8 @@ def test_grdlandmask_no_outgrid(expected_grid): result = grdlandmask(spacing=1, region=[125, 130, 30, 35], cores=2) # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 0 # Gridline registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.GRIDLINE # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) diff --git a/pygmt/tests/test_grdproject.py b/pygmt/tests/test_grdproject.py index 644ac311c54..efd8ae7503d 100644 --- a/pygmt/tests/test_grdproject.py +++ b/pygmt/tests/test_grdproject.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import grdproject, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -70,12 +71,12 @@ def test_grdproject_no_outgrid(grid, projection, expected_grid): Also check that providing the projection as an EPSG code or PROJ4 string works. """ - assert grid.gmt.gtype == 1 # Geographic grid + assert grid.gmt.gtype == GridType.GEOGRAPHIC result = grdproject( grid=grid, projection=projection, spacing=3, region=[-53, -51, -20, -17] ) - assert result.gmt.gtype == 0 # Rectangular grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.CARTESIAN + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py index 4c9e64139c3..7559a791623 100644 --- a/pygmt/tests/test_grdsample.py +++ b/pygmt/tests/test_grdsample.py @@ -7,6 +7,7 @@ import pytest import xarray as xr from pygmt import grdsample, load_dataarray +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile from pygmt.helpers.testing import load_static_earth_relief @@ -78,8 +79,8 @@ def test_grdsample_dataarray_out(grid, expected_grid, region, spacing): result = grdsample(grid=grid, spacing=spacing, region=region, cores=2) # check information of the output grid assert isinstance(result, xr.DataArray) - assert result.gmt.gtype == 1 # Geographic grid - assert result.gmt.registration == 1 # Pixel registration + assert result.gmt.gtype == GridType.GEOGRAPHIC + assert result.gmt.registration == GridRegistration.PIXEL # check information of the output grid xr.testing.assert_allclose(a=result, b=expected_grid) @@ -88,8 +89,8 @@ def test_grdsample_registration_changes(grid): """ Test grdsample with no set outgrid and applying registration changes. """ - assert grid.gmt.registration == 1 # Pixel registration + assert grid.gmt.registration == GridRegistration.PIXEL translated_grid = grdsample(grid=grid, translate=True) - assert translated_grid.gmt.registration == 0 # Gridline registration + assert translated_grid.gmt.registration == GridRegistration.GRIDLINE registration_grid = grdsample(grid=translated_grid, registration="p") - assert registration_grid.gmt.registration == 1 # Pixel registration + assert registration_grid.gmt.registration == GridRegistration.PIXEL diff --git a/pygmt/tests/test_io.py b/pygmt/tests/test_io.py index 90ae4f2df83..ade706486e3 100644 --- a/pygmt/tests/test_io.py +++ b/pygmt/tests/test_io.py @@ -5,6 +5,7 @@ import numpy as np import pytest import xarray as xr +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile from pygmt.io import load_dataarray @@ -22,10 +23,9 @@ def test_io_load_dataarray(): ) grid.to_netcdf(tmpfile.name) dataarray = load_dataarray(tmpfile.name) - assert dataarray.gmt.gtype == 0 # Cartesian grid - assert dataarray.gmt.registration == 1 # Pixel registration - # this would fail if we used xr.open_dataarray instead of - # load_dataarray + assert dataarray.gmt.gtype == GridType.CARTESIAN + assert dataarray.gmt.registration == GridRegistration.PIXEL + # this would fail if we used xr.open_dataarray instead of load_dataarray dataarray.to_netcdf(tmpfile.name) diff --git a/pygmt/tests/test_nearneighbor.py b/pygmt/tests/test_nearneighbor.py index 9d08aa0e8d1..aa25c6a0fa3 100644 --- a/pygmt/tests/test_nearneighbor.py +++ b/pygmt/tests/test_nearneighbor.py @@ -10,6 +10,7 @@ import xarray as xr from pygmt import nearneighbor from pygmt.datasets import load_sample_data +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -32,8 +33,8 @@ def test_nearneighbor_input_data(array_func, ship_data): data=data, spacing="5m", region=[245, 255, 20, 30], search_radius="10m" ) assert isinstance(output, xr.DataArray) - assert output.gmt.registration == 0 # Gridline registration - assert output.gmt.gtype == 1 # Geographic type + assert output.gmt.registration == GridRegistration.GRIDLINE + assert output.gmt.gtype == GridType.GEOGRAPHIC assert output.shape == (121, 121) npt.assert_allclose(output.mean(), -2378.2385) diff --git a/pygmt/tests/test_sph2grd.py b/pygmt/tests/test_sph2grd.py index 89b4abeff25..e3c71293621 100644 --- a/pygmt/tests/test_sph2grd.py +++ b/pygmt/tests/test_sph2grd.py @@ -7,6 +7,7 @@ import numpy.testing as npt import pytest from pygmt import sph2grd +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile @@ -29,8 +30,8 @@ def test_sph2grd_no_outgrid(): """ temp_grid = sph2grd(data="@EGM96_to_36.txt", spacing=1, region="g", cores=2) assert temp_grid.dims == ("y", "x") - assert temp_grid.gmt.gtype == 0 # Cartesian grid - assert temp_grid.gmt.registration == 0 # Gridline registration + assert temp_grid.gmt.gtype == GridType.CARTESIAN + assert temp_grid.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(temp_grid.max(), 0.00021961, rtol=1e-4) npt.assert_allclose(temp_grid.min(), -0.0004326, rtol=1e-4) npt.assert_allclose(temp_grid.median(), -0.00010894, rtol=1e-4) diff --git a/pygmt/tests/test_sphdistance.py b/pygmt/tests/test_sphdistance.py index be8cbd1a066..ac3701fb0c3 100644 --- a/pygmt/tests/test_sphdistance.py +++ b/pygmt/tests/test_sphdistance.py @@ -8,6 +8,7 @@ import numpy.testing as npt import pytest from pygmt import sphdistance +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -29,8 +30,8 @@ def test_sphdistance_xy_inputs(): x = [85.5, 82.3, 85.8, 86.5] temp_grid = sphdistance(x=x, y=y, spacing=[1, 2], region=[82, 87, 22, 24]) assert temp_grid.dims == ("lat", "lon") - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 0 # Gridline registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(temp_grid.max(), 232977.546875) npt.assert_allclose(temp_grid.min(), 0) npt.assert_allclose(temp_grid.median(), 0) @@ -56,8 +57,8 @@ def test_sphdistance_no_outgrid(array): """ temp_grid = sphdistance(data=array, spacing=[1, 2], region=[82, 87, 22, 24]) assert temp_grid.dims == ("lat", "lon") - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 0 # Gridline registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(temp_grid.max(), 232977.546875) npt.assert_allclose(temp_grid.min(), 0) npt.assert_allclose(temp_grid.median(), 0) diff --git a/pygmt/tests/test_sphinterpolate.py b/pygmt/tests/test_sphinterpolate.py index d7e24eba780..7b91f00b24e 100644 --- a/pygmt/tests/test_sphinterpolate.py +++ b/pygmt/tests/test_sphinterpolate.py @@ -8,6 +8,7 @@ import pytest from pygmt import sphinterpolate from pygmt.datasets import load_sample_data +from pygmt.enums import GridRegistration, GridType from pygmt.helpers import GMTTempFile @@ -36,8 +37,8 @@ def test_sphinterpolate_no_outgrid(mars): """ temp_grid = sphinterpolate(data=mars, spacing=1, region="g") assert temp_grid.dims == ("lat", "lon") - assert temp_grid.gmt.gtype == 1 # Geographic grid - assert temp_grid.gmt.registration == 0 # Gridline registration + assert temp_grid.gmt.gtype == GridType.GEOGRAPHIC + assert temp_grid.gmt.registration == GridRegistration.GRIDLINE npt.assert_allclose(temp_grid.max(), 14628.144) npt.assert_allclose(temp_grid.min(), -6908.1987) npt.assert_allclose(temp_grid.median(), 118.96849) diff --git a/pygmt/tests/test_surface.py b/pygmt/tests/test_surface.py index e8ec0cf3445..b49e6875304 100644 --- a/pygmt/tests/test_surface.py +++ b/pygmt/tests/test_surface.py @@ -8,6 +8,7 @@ import pytest import xarray as xr from pygmt import surface, which +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -72,8 +73,8 @@ def check_values(grid, expected_grid): Check the attributes and values of the DataArray returned by surface. """ assert isinstance(grid, xr.DataArray) - assert grid.gmt.registration == 0 # Gridline registration - assert grid.gmt.gtype == 0 # Cartesian type + assert grid.gmt.registration == GridRegistration.GRIDLINE + assert grid.gmt.gtype == GridType.CARTESIAN xr.testing.assert_allclose(a=grid, b=expected_grid) diff --git a/pygmt/tests/test_triangulate.py b/pygmt/tests/test_triangulate.py index f0a47c6e4ae..5f9c7a4c319 100644 --- a/pygmt/tests/test_triangulate.py +++ b/pygmt/tests/test_triangulate.py @@ -9,6 +9,7 @@ import pytest import xarray as xr from pygmt import triangulate, which +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -139,8 +140,8 @@ def test_regular_grid_no_outgrid(dataframe, expected_grid): data = dataframe.to_numpy() output = triangulate.regular_grid(data=data, spacing=1, region=[2, 4, 5, 6]) assert isinstance(output, xr.DataArray) - assert output.gmt.registration == 0 # Gridline registration - assert output.gmt.gtype == 0 # Cartesian type + assert output.gmt.registration == GridRegistration.GRIDLINE + assert output.gmt.gtype == GridType.CARTESIAN xr.testing.assert_allclose(a=output, b=expected_grid) @@ -157,6 +158,6 @@ def test_regular_grid_with_outgrid_param(dataframe, expected_grid): assert Path(tmpfile.name).stat().st_size > 0 # check that outgrid exists with xr.open_dataarray(tmpfile.name) as grid: assert isinstance(grid, xr.DataArray) - assert grid.gmt.registration == 0 # Gridline registration - assert grid.gmt.gtype == 0 # Cartesian type + assert grid.gmt.registration == GridRegistration.GRIDLINE + assert grid.gmt.gtype == GridType.CARTESIAN xr.testing.assert_allclose(a=grid, b=expected_grid) diff --git a/pygmt/tests/test_xyz2grd.py b/pygmt/tests/test_xyz2grd.py index 56b2d1167e2..9e22d376695 100644 --- a/pygmt/tests/test_xyz2grd.py +++ b/pygmt/tests/test_xyz2grd.py @@ -9,6 +9,7 @@ import xarray as xr from pygmt import load_dataarray, xyz2grd from pygmt.datasets import load_sample_data +from pygmt.enums import GridRegistration, GridType from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import GMTTempFile @@ -48,8 +49,8 @@ def test_xyz2grd_input_array(array_func, ship_data, expected_grid): """ output = xyz2grd(data=array_func(ship_data), spacing=5, region=[245, 255, 20, 30]) assert isinstance(output, xr.DataArray) - assert output.gmt.registration == 0 # Gridline registration - assert output.gmt.gtype == 0 # Cartesian type + assert output.gmt.registration == GridRegistration.GRIDLINE + assert output.gmt.gtype == GridType.CARTESIAN xr.testing.assert_allclose(a=output, b=expected_grid)