From 921674cbf9f324515bf0f97cb8b5ec85a2f51e33 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 18 Mar 2024 22:34:50 +0800 Subject: [PATCH 01/17] Wrap GMT's standard data type GMT_IMAGE for images --- pygmt/clib/session.py | 22 ++++++++----- pygmt/datatypes/__init__.py | 1 + pygmt/datatypes/image.py | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 pygmt/datatypes/image.py diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 1b8b5483a28..a3caf907322 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -26,7 +26,7 @@ vectors_to_arrays, ) from pygmt.clib.loading import load_libgmt -from pygmt.datatypes import _GMT_DATASET, _GMT_GRID +from pygmt.datatypes import _GMT_DATASET, _GMT_GRID, _GMT_IMAGE from pygmt.exceptions import ( GMTCLibError, GMTCLibNoSessionError, @@ -1789,7 +1789,9 @@ def virtualfile_from_data( @contextlib.contextmanager def virtualfile_out( - self, kind: Literal["dataset", "grid"] = "dataset", fname: str | None = None + self, + kind: Literal["dataset", "grid", "image"] = "dataset", + fname: str | None = None, ) -> Generator[str, None, None]: r""" Create a virtual file or an actual file for storing output data. @@ -1802,8 +1804,8 @@ def virtualfile_out( Parameters ---------- kind - The data kind of the virtual file to create. Valid values are ``"dataset"`` - and ``"grid"``. Ignored if ``fname`` is specified. + The data kind of the virtual file to create. Valid values are ``"dataset"``, + ``"grid"``, and ``"image"``. Ignored if ``fname`` is specified. fname The name of the actual file to write the output data. No virtual file will be created. @@ -1846,8 +1848,11 @@ def virtualfile_out( family, geometry = { "dataset": ("GMT_IS_DATASET", "GMT_IS_PLP"), "grid": ("GMT_IS_GRID", "GMT_IS_SURFACE"), + "image": ("GMT_IS_IMAGE", "GMT_IS_SURFACE"), }[kind] - with self.open_virtualfile(family, geometry, "GMT_OUT", None) as vfile: + with self.open_virtualfile( + family, geometry, "GMT_OUT|GMT_IS_REFERENCE", None + ) as vfile: yield vfile def inquire_virtualfile(self, vfname: str) -> int: @@ -1893,7 +1898,8 @@ def read_virtualfile( Name of the virtual file to read. kind Cast the data into a GMT data container. Valid values are ``"dataset"``, - ``"grid"`` and ``None``. If ``None``, will return a ctypes void pointer. + ``"grid"``, ``"image"`` and ``None``. If ``None``, will return a ctypes void + pointer. Returns ------- @@ -1943,9 +1949,9 @@ def read_virtualfile( # _GMT_DATASET). if kind is None: # Return the ctypes void pointer return pointer - if kind in {"image", "cube"}: + if kind == "cube": raise NotImplementedError(f"kind={kind} is not supported yet.") - dtype = {"dataset": _GMT_DATASET, "grid": _GMT_GRID}[kind] + dtype = {"dataset": _GMT_DATASET, "grid": _GMT_GRID, "image": _GMT_IMAGE}[kind] return ctp.cast(pointer, ctp.POINTER(dtype)) def virtualfile_to_dataset( diff --git a/pygmt/datatypes/__init__.py b/pygmt/datatypes/__init__.py index 237a050a9f7..3489dd19d10 100644 --- a/pygmt/datatypes/__init__.py +++ b/pygmt/datatypes/__init__.py @@ -4,3 +4,4 @@ from pygmt.datatypes.dataset import _GMT_DATASET from pygmt.datatypes.grid import _GMT_GRID +from pygmt.datatypes.image import _GMT_IMAGE diff --git a/pygmt/datatypes/image.py b/pygmt/datatypes/image.py new file mode 100644 index 00000000000..74af128dc3c --- /dev/null +++ b/pygmt/datatypes/image.py @@ -0,0 +1,66 @@ +""" +Wrapper for the GMT_IMAGE data type. +""" + +import ctypes as ctp +from typing import ClassVar + +from pygmt.datatypes.grid import _GMT_GRID_HEADER + + +class _GMT_IMAGE(ctp.Structure): # noqa: N801 + """ + GMT image data structure. + + Examples + -------- + >>> from pygmt.clib import Session + >>> import numpy as np + >>> import xarray as xr + >>> import rioxarray + + >>> with Session() as lib: + ... with lib.virtualfile_out(kind="image") as voutimg: + ... lib.call_module("read", f"@earth_day_01d {voutimg} -Ti") + ... ds = lib.read_virtualfile(vfname=voutimg, kind="image").contents + ... header = ds.header.contents + ... pad = header.pad[:] + ... print(ds.type, header.n_bands, header.n_rows, header.n_columns) + ... print(header.pad[:]) + ... data = np.reshape( + ... ds.data[: header.n_bands * header.mx * header.my], + ... (header.my, header.mx, header.n_bands), + ... ) + ... data = data[pad[2] : header.my - pad[3], pad[0] : header.mx - pad[1], :] + ... x = ds.x[: header.n_columns] + ... y = ds.y[: header.n_rows] + >>> data = xr.DataArray( + ... data, dims=["y", "x", "band"], coords={"y": y, "x": x, "band": [1, 2, 3]} + ... ) + >>> data = data.transpose("band", "y", "x") + >>> data = data.sortby(list(data.dims)) + >>> data.plot.imshow() + """ + + _fields_: ClassVar = [ + # Data type, e.g. GMT_FLOAT + ("type", ctp.c_int), + # Array with color lookup values + ("colormap", ctp.POINTER(ctp.c_int)), + # Number of colors in a paletted image + ("n_indexed_colors", ctp.c_int), + # Pointer to full GMT header for the image + ("header", ctp.POINTER(_GMT_GRID_HEADER)), + # Pointer to actual image + ("data", ctp.POINTER(ctp.c_ubyte)), + # Pointer to an optional transparency layer stored in a separate variable + ("alpha", ctp.POINTER(ctp.c_ubyte)), + # Color interpolation + ("color_interp", ctp.c_char_p), + # Pointer to the x-coordinate vector + ("x", ctp.POINTER(ctp.c_double)), + # Pointer to the y-coordinate vector + ("y", ctp.POINTER(ctp.c_double)), + # Book-keeping variables "hidden" from the API + ("hidden", ctp.c_void_p), + ] From c01d6abe524febca3d2454bf74f0f3a866fa87ee Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 19 Jul 2024 20:58:31 +0800 Subject: [PATCH 02/17] Use GMT_OUT|GMT_IS_REFERENCE for images and GMT_OUT for others --- pygmt/clib/session.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index a3caf907322..5c3150a44b6 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1850,9 +1850,8 @@ def virtualfile_out( "grid": ("GMT_IS_GRID", "GMT_IS_SURFACE"), "image": ("GMT_IS_IMAGE", "GMT_IS_SURFACE"), }[kind] - with self.open_virtualfile( - family, geometry, "GMT_OUT|GMT_IS_REFERENCE", None - ) as vfile: + direction = "GMT_OUT|GMT_IS_REFERENCE" if kind == "image" else "GMT_OUT" + with self.open_virtualfile(family, geometry, direction, None) as vfile: yield vfile def inquire_virtualfile(self, vfname: str) -> int: From 36430c8b9d1c53e216804b9ffb674af64d273819 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 19 Jul 2024 21:11:56 +0800 Subject: [PATCH 03/17] Add image support to Session.read_data --- pygmt/clib/session.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 5c3150a44b6..8eb7abf0e4d 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -1070,7 +1070,7 @@ def put_matrix(self, dataset, matrix, pad=0): def read_data( self, infile: str, - kind: Literal["dataset", "grid"], + kind: Literal["dataset", "grid", "image"], family: str | None = None, geometry: str | None = None, mode: str = "GMT_READ_NORMAL", @@ -1088,8 +1088,8 @@ def read_data( infile The input file name. kind - The data kind of the input file. Valid values are ``"dataset"`` and - ``"grid"``. + The data kind of the input file. Valid values are ``"dataset"``, ``"grid"`` + and ``"image"``. family A valid GMT data family name (e.g., ``"GMT_IS_DATASET"``). See the ``FAMILIES`` attribute for valid names. If ``None``, will determine the data @@ -1140,6 +1140,7 @@ def read_data( _family, _geometry, dtype = { "dataset": ("GMT_IS_DATASET", "GMT_IS_PLP", _GMT_DATASET), "grid": ("GMT_IS_GRID", "GMT_IS_SURFACE", _GMT_GRID), + "image": ("GMT_IS_IMAGE", "GMT_IS_SURFACE", _GMT_IMAGE), }[kind] if family is None: family = _family From a918cfd1220a92872db3d8e2b37716ceb867aa7f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 8 Jul 2024 21:56:58 +0800 Subject: [PATCH 04/17] Add tests for reading images --- pygmt/tests/test_clib_read_data.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index 43978b291c2..9b2e0c71085 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -132,6 +132,60 @@ def test_clib_read_data_grid_actual_image(): ) +# Note: Simplify the tests for images after GMT_IMAGE.to_dataarray() is implemented. +def test_clib_read_data_image(): + """ + Test the Session.read_data method for images. + """ + with Session() as lib: + image = lib.read_data("@earth_day_01d_p", kind="image").contents + header = image.header.contents + assert header.n_rows == 180 + assert header.n_columns == 360 + assert header.n_bands == 3 + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + assert image.data + + +def test_clib_read_data_image_two_steps(): + """ + Test the Session.read_data method for images in two steps, first reading the header + and then the data. + """ + infile = "@earth_day_01d_p" + with Session() as lib: + # Read the header first + data_ptr = lib.read_data(infile, kind="image", mode="GMT_CONTAINER_ONLY") + grid = data_ptr.contents + header = grid.header.contents + assert header.n_rows == 180 + assert header.n_columns == 360 + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + assert header.n_bands == 3 # Explicitly check n_bands + assert not grid.data # The data is not read yet + + # Read the data + lib.read_data(infile, kind="image", mode="GMT_DATA_ONLY", data=data_ptr) + assert grid.data + + +def test_clib_read_data_image_actual_grid(): + """ + Test the Session.read_data method for grid, but actually the file is an image. + """ + with Session() as lib: + data_ptr = lib.read_data( + "@earth_relief_01d_p", kind="grid", mode="GMT_CONTAINER_ONLY" + ) + image = data_ptr.contents + header = image.header.contents + assert header.n_rows == 180 + assert header.n_columns == 360 + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + # Explicitly check n_bands. Grid has only one band. + assert header.n_bands == 1 + + def test_clib_read_data_fails(): """ Test that the Session.read_data method raises an exception if there are errors. From 1983b7e463ddd51e289bab415bde3c4d2bb66187 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 19 Jul 2024 23:35:16 +0800 Subject: [PATCH 05/17] Improve image doctest --- pygmt/datatypes/image.py | 64 +++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/pygmt/datatypes/image.py b/pygmt/datatypes/image.py index 74af128dc3c..63c267b1ca0 100644 --- a/pygmt/datatypes/image.py +++ b/pygmt/datatypes/image.py @@ -14,32 +14,60 @@ class _GMT_IMAGE(ctp.Structure): # noqa: N801 Examples -------- - >>> from pygmt.clib import Session >>> import numpy as np - >>> import xarray as xr - >>> import rioxarray - + >>> from pygmt.clib import Session >>> with Session() as lib: ... with lib.virtualfile_out(kind="image") as voutimg: - ... lib.call_module("read", f"@earth_day_01d {voutimg} -Ti") - ... ds = lib.read_virtualfile(vfname=voutimg, kind="image").contents - ... header = ds.header.contents - ... pad = header.pad[:] - ... print(ds.type, header.n_bands, header.n_rows, header.n_columns) + ... lib.call_module("read", ["@earth_day_01d", voutimg, "-Ti"]) + ... # Read the image from the virtual file + ... image = lib.read_virtualfile(vfname=voutimg, kind="image").contents + ... # The image header + ... header = image.header.contents + ... # Access the header properties + ... print(header.n_rows, header.n_columns, header.registration) + ... print(header.wesn[:], header.inc[:]) + ... print(header.z_scale_factor, header.z_add_offset) + ... print(header.x_units, header.y_units, header.z_units) + ... print(header.title) + ... print(header.command) + ... print(header.remark) + ... print(header.nm, header.size, header.complex_mode) + ... print(header.type, header.n_bands, header.mx, header.my) ... print(header.pad[:]) + ... print(header.mem_layout, header.nan_value, header.xy_off) + ... # Image-specific attributes. + ... print(image.type, image.n_indexed_colors) + ... # The x and y coordinates + ... x = image.x[: header.n_columns] + ... y = image.y[: header.n_rows] + ... # The data array (with paddings) ... data = np.reshape( - ... ds.data[: header.n_bands * header.mx * header.my], + ... image.data[: header.n_bands * header.mx * header.my], ... (header.my, header.mx, header.n_bands), ... ) + ... # The data array (without paddings) + ... pad = header.pad[:] ... data = data[pad[2] : header.my - pad[3], pad[0] : header.mx - pad[1], :] - ... x = ds.x[: header.n_columns] - ... y = ds.y[: header.n_rows] - >>> data = xr.DataArray( - ... data, dims=["y", "x", "band"], coords={"y": y, "x": x, "band": [1, 2, 3]} - ... ) - >>> data = data.transpose("band", "y", "x") - >>> data = data.sortby(list(data.dims)) - >>> data.plot.imshow() + 180 360 1 + [-180.0, 180.0, -90.0, 90.0] [1.0, 1.0] + 1.0 0.0 + b'x' b'y' b'z' + b'' + b'' + b'' + 64800 66976 0 + 0 3 364 184 + [2, 2, 2, 2] + b'BRPa' 0.0 0.5 + 1 0 + >>> x + [-179.5, -178.5, ..., 178.5, 179.5] + >>> y + [89.5, 88.5, ..., -88.5, -89.5] + >>> data.shape + (180, 360, 3) + >>> data.min(), data.max() + (10, 255) """ _fields_: ClassVar = [ From 84cbd113be4956fdf8e3bd9b26e2ecdb8791e7b8 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 19 Jul 2024 23:44:21 +0800 Subject: [PATCH 06/17] Fix one test --- pygmt/tests/test_clib_read_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index 9b2e0c71085..da1e2628b68 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -171,11 +171,11 @@ def test_clib_read_data_image_two_steps(): def test_clib_read_data_image_actual_grid(): """ - Test the Session.read_data method for grid, but actually the file is an image. + Test the Session.read_data method for image, but actually the file is a grid. """ with Session() as lib: data_ptr = lib.read_data( - "@earth_relief_01d_p", kind="grid", mode="GMT_CONTAINER_ONLY" + "@earth_relief_01d_p", kind="image", mode="GMT_CONTAINER_ONLY" ) image = data_ptr.contents header = image.header.contents From 95275b02ef3c6db9d9a4ca393bfa512476d30bd3 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Jul 2024 10:52:33 +0800 Subject: [PATCH 07/17] Fix tests --- pygmt/tests/test_clib_read_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index da1e2628b68..5579cf6ca48 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -142,8 +142,8 @@ def test_clib_read_data_image(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 + assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] assert header.n_bands == 3 - assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] assert image.data @@ -160,7 +160,7 @@ def test_clib_read_data_image_two_steps(): header = grid.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] assert header.n_bands == 3 # Explicitly check n_bands assert not grid.data # The data is not read yet @@ -181,7 +181,7 @@ def test_clib_read_data_image_actual_grid(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] # Explicitly check n_bands. Grid has only one band. assert header.n_bands == 1 From d43f2e9fdd7e6b09abd75dbec9ea1652acd08f46 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Jul 2024 11:00:15 +0800 Subject: [PATCH 08/17] Revert "Fix tests" This reverts commit 95275b02ef3c6db9d9a4ca393bfa512476d30bd3. --- pygmt/tests/test_clib_read_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index 5579cf6ca48..da1e2628b68 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -142,8 +142,8 @@ def test_clib_read_data_image(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] assert header.n_bands == 3 + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] assert image.data @@ -160,7 +160,7 @@ def test_clib_read_data_image_two_steps(): header = grid.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] assert header.n_bands == 3 # Explicitly check n_bands assert not grid.data # The data is not read yet @@ -181,7 +181,7 @@ def test_clib_read_data_image_actual_grid(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] + assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] # Explicitly check n_bands. Grid has only one band. assert header.n_bands == 1 From 47d4e4a38974586060a8b0320bbdbff545de6569 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Jul 2024 13:16:44 +0800 Subject: [PATCH 09/17] Update pygmt/tests/test_clib_read_data.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/tests/test_clib_read_data.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index da1e2628b68..1af18a146fe 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -156,17 +156,17 @@ def test_clib_read_data_image_two_steps(): with Session() as lib: # Read the header first data_ptr = lib.read_data(infile, kind="image", mode="GMT_CONTAINER_ONLY") - grid = data_ptr.contents - header = grid.header.contents + image = data_ptr.contents + header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] assert header.n_bands == 3 # Explicitly check n_bands - assert not grid.data # The data is not read yet + assert not image.data # The data is not read yet # Read the data lib.read_data(infile, kind="image", mode="GMT_DATA_ONLY", data=data_ptr) - assert grid.data + assert image.data def test_clib_read_data_image_actual_grid(): From bb0efe386680acc8231c70edfc1f9661a92a50f3 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Jul 2024 15:31:32 +0800 Subject: [PATCH 10/17] Temporarily add libgdal-hdf5 --- .github/workflows/ci_tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 362c8c5df76..552a073aa8e 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -135,6 +135,7 @@ jobs: pytest-mpl pytest-rerunfailures pytest-xdist + libgdal-hdf5 # Download cached remote files (artifacts) from GitHub - name: Download remote data from GitHub From 994de3ac66413728d6703d78374231a3b84987b5 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sat, 20 Jul 2024 16:00:21 +0800 Subject: [PATCH 11/17] Fix one failure --- pygmt/tests/test_clib_read_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index 1af18a146fe..ed2c1d3600d 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -181,7 +181,7 @@ def test_clib_read_data_image_actual_grid(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-180.0, 180.0, -90.0, 90.0] + assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] # Explicitly check n_bands. Grid has only one band. assert header.n_bands == 1 From dc1a64968e5592aefe5bef6c411aec5856ac761f Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Jul 2024 08:52:09 +0800 Subject: [PATCH 12/17] Revert "Temporarily add libgdal-hdf5" This reverts commit bb0efe386680acc8231c70edfc1f9661a92a50f3. --- .github/workflows/ci_tests.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 552a073aa8e..362c8c5df76 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -135,7 +135,6 @@ jobs: pytest-mpl pytest-rerunfailures pytest-xdist - libgdal-hdf5 # Download cached remote files (artifacts) from GitHub - name: Download remote data from GitHub From 0638dabf4ecbaca554d9e04a31acda50e108b5ce Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Jul 2024 08:52:52 +0800 Subject: [PATCH 13/17] Remove the test_clib_read_data_image_actual_grid test --- pygmt/tests/test_clib_read_data.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index ed2c1d3600d..b2f92403df0 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -169,23 +169,6 @@ def test_clib_read_data_image_two_steps(): assert image.data -def test_clib_read_data_image_actual_grid(): - """ - Test the Session.read_data method for image, but actually the file is a grid. - """ - with Session() as lib: - data_ptr = lib.read_data( - "@earth_relief_01d_p", kind="image", mode="GMT_CONTAINER_ONLY" - ) - image = data_ptr.contents - header = image.header.contents - assert header.n_rows == 180 - assert header.n_columns == 360 - assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] - # Explicitly check n_bands. Grid has only one band. - assert header.n_bands == 1 - - def test_clib_read_data_fails(): """ Test that the Session.read_data method raises an exception if there are errors. From 7080d8bbc3eae455b896d78df1d3763047dd4493 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Jul 2024 09:52:36 +0800 Subject: [PATCH 14/17] Revert "Remove the test_clib_read_data_image_actual_grid test" This reverts commit 0638dabf4ecbaca554d9e04a31acda50e108b5ce. --- pygmt/tests/test_clib_read_data.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index b2f92403df0..ed2c1d3600d 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -169,6 +169,23 @@ def test_clib_read_data_image_two_steps(): assert image.data +def test_clib_read_data_image_actual_grid(): + """ + Test the Session.read_data method for image, but actually the file is a grid. + """ + with Session() as lib: + data_ptr = lib.read_data( + "@earth_relief_01d_p", kind="image", mode="GMT_CONTAINER_ONLY" + ) + image = data_ptr.contents + header = image.header.contents + assert header.n_rows == 180 + assert header.n_columns == 360 + assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] + # Explicitly check n_bands. Grid has only one band. + assert header.n_bands == 1 + + def test_clib_read_data_fails(): """ Test that the Session.read_data method raises an exception if there are errors. From 8692161a48f9ac8c6533dcbec216265d626f882c Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Jul 2024 09:52:43 +0800 Subject: [PATCH 15/17] Reapply "Temporarily add libgdal-hdf5" This reverts commit dc1a64968e5592aefe5bef6c411aec5856ac761f. --- .github/workflows/ci_tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 362c8c5df76..552a073aa8e 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -135,6 +135,7 @@ jobs: pytest-mpl pytest-rerunfailures pytest-xdist + libgdal-hdf5 # Download cached remote files (artifacts) from GitHub - name: Download remote data from GitHub From aeb2ea3a5ac399a2d725802837bf481d1c2cc75d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Sun, 21 Jul 2024 09:53:28 +0800 Subject: [PATCH 16/17] Do not check header.wesn --- pygmt/tests/test_clib_read_data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index ed2c1d3600d..837622d770c 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -181,7 +181,8 @@ def test_clib_read_data_image_actual_grid(): header = image.header.contents assert header.n_rows == 180 assert header.n_columns == 360 - assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] + # The header.wesn value may depend on GDAL version. + # assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] # Explicitly check n_bands. Grid has only one band. assert header.n_bands == 1 From 74b889fe22420013ffbaf5fccbff8e3ecfc1903e Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 24 Jul 2024 00:47:28 +0800 Subject: [PATCH 17/17] Remove the test for reading grid as image --- .github/workflows/ci_tests.yaml | 1 - pygmt/tests/test_clib_read_data.py | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/.github/workflows/ci_tests.yaml b/.github/workflows/ci_tests.yaml index 552a073aa8e..362c8c5df76 100644 --- a/.github/workflows/ci_tests.yaml +++ b/.github/workflows/ci_tests.yaml @@ -135,7 +135,6 @@ jobs: pytest-mpl pytest-rerunfailures pytest-xdist - libgdal-hdf5 # Download cached remote files (artifacts) from GitHub - name: Download remote data from GitHub diff --git a/pygmt/tests/test_clib_read_data.py b/pygmt/tests/test_clib_read_data.py index 837622d770c..b2f92403df0 100644 --- a/pygmt/tests/test_clib_read_data.py +++ b/pygmt/tests/test_clib_read_data.py @@ -169,24 +169,6 @@ def test_clib_read_data_image_two_steps(): assert image.data -def test_clib_read_data_image_actual_grid(): - """ - Test the Session.read_data method for image, but actually the file is a grid. - """ - with Session() as lib: - data_ptr = lib.read_data( - "@earth_relief_01d_p", kind="image", mode="GMT_CONTAINER_ONLY" - ) - image = data_ptr.contents - header = image.header.contents - assert header.n_rows == 180 - assert header.n_columns == 360 - # The header.wesn value may depend on GDAL version. - # assert header.wesn[:] == [-179.5, 179.5, -89.5, 89.5] - # Explicitly check n_bands. Grid has only one band. - assert header.n_bands == 1 - - def test_clib_read_data_fails(): """ Test that the Session.read_data method raises an exception if there are errors.