Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Set minimum supported version to GMT>=6.4.0 #3450

Merged
merged 18 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, macos-12, windows-2019]
gmt_version: ['6.3', '6.4']
gmt_version: ['6.4']
timeout-minutes: 30
defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ the problem:

python <test>.py 2>&1 | awk -F': ' '$2=="GMT_Call_Command string" {print $3}'

where `<test>` is the name of your test script. Note that this script works only with GMT>=6.4
where `<test>` is the name of your test script.
* If the bug is produced when passing an in-memory data object (e.g., a
pandas.DataFrame or xarray.DataArray) to a PyGMT function, try writing the
data to a file (e.g., a netCDF or ASCII txt file) and passing the data file
Expand Down
2 changes: 1 addition & 1 deletion pygmt/clib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pygmt.clib.session import Session, __gmt_version__
from pygmt.exceptions import GMTVersionError

required_gmt_version = "6.3.0"
required_gmt_version = "6.4.0"

# Check if the GMT version is older than the required version.
if Version(__gmt_version__) < Version(required_gmt_version):
Expand Down
12 changes: 2 additions & 10 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
import pandas as pd
import xarray as xr
from packaging.version import Version
from pygmt.clib.conversion import (
array_to_datetime,
as_c_contiguous,
Expand Down Expand Up @@ -198,16 +197,9 @@ def info(self):
"library path": self.get_default("API_LIBRARY"),
"cores": self.get_default("API_CORES"),
"grid layout": self.get_default("API_GRID_LAYOUT"),
"image layout": self.get_default("API_IMAGE_LAYOUT"),
Copy link
Member

Choose a reason for hiding this comment

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

I'm getting a blank value with this as mentioned at #3468 (comment). Are you getting any output?

import pygmt

with pygmt.clib.Session() as lib:
    print(lib.info["image layout"])  # API_IMAGE_LAYOUT

output from lib.info dict:

{'version': '6.5.0',
 'padding': '2',
 'share dir': '~/mambaforge/envs/pygmt/share/gmt',
 'plugin dir': '~/mambaforge/envs/pygmt/lib/gmt/plugins',
 'library path': '~/mambaforge/envs/pygmt/lib/libgmt.so',
 'cores': '16',
 'grid layout': 'rows',
 'image layout': '',
 'binary version': '6.5.0'}

"binary version": self.get_default("API_BIN_VERSION"),
}
# For GMT<6.4.0, API_IMAGE_LAYOUT is not defined if GMT is not
# compiled with GDAL. Since GMT 6.4.0, GDAL is a required GMT
# dependency. The code block can be refactored after we bump
# the minimum required GMT version to 6.4.0.
with contextlib.suppress(GMTCLibError):
self._info["image layout"] = self.get_default("API_IMAGE_LAYOUT")
# API_BIN_VERSION is new in GMT 6.4.0.
if Version(self._info["version"]) >= Version("6.4.0"):
self._info["binary version"] = self.get_default("API_BIN_VERSION")
return self._info

def __enter__(self):
Expand Down
8 changes: 4 additions & 4 deletions pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def timestamp(
kwdict["U"] += f"{label}"
kwdict["U"] += f"+j{justify}"

if Version(__gmt_version__) <= Version("6.4.0") and "/" not in str(offset):
# Giving a single offset doesn't work in GMT <= 6.4.0.
if Version(__gmt_version__) < Version("6.5.0") and "/" not in str(offset):
# Giving a single offset doesn't work in GMT < 6.5.0.
# See https://github.com/GenericMappingTools/gmt/issues/7107.
offset = f"{offset}/{offset}"
kwdict["U"] += f"+o{offset}"
Expand All @@ -98,8 +98,8 @@ def timestamp(
"The given text string will be truncated to 64 characters."
)
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
if Version(__gmt_version__) <= Version("6.4.0"):
# workaround for GMT<=6.4.0 by overriding the 'timefmt' parameter
if Version(__gmt_version__) < Version("6.5.0"):
# Workaround for GMT<6.5.0 by overriding the 'timefmt' parameter
timefmt = text[:64]
else:
kwdict["U"] += f"+t{text}"
Expand Down
4 changes: 0 additions & 4 deletions pygmt/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ def test_accessor_set_non_boolean():
grid.gmt.gtype = 2


@pytest.mark.skipif(
Version(__gmt_version__) < Version("6.4.0"),
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/6615",
)
@pytest.mark.xfail(
condition=sys.platform == "win32" and Version(__gmt_version__) < Version("6.5.0"),
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7573",
Expand Down
3 changes: 2 additions & 1 deletion pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xarray as xr
from packaging.version import Version
from pygmt import Figure, clib
from pygmt.clib import required_gmt_version
from pygmt.clib.conversion import dataarray_to_matrix
from pygmt.clib.session import FAMILIES, VIAS
from pygmt.exceptions import (
Expand Down Expand Up @@ -531,7 +532,7 @@ def test_get_default():
with clib.Session() as lib:
assert lib.get_default("API_GRID_LAYOUT") in {"rows", "columns"}
assert int(lib.get_default("API_CORES")) >= 1
assert Version(lib.get_default("API_VERSION")) >= Version("6.3.0")
assert Version(lib.get_default("API_VERSION")) >= Version(required_gmt_version)
assert lib.get_default("PROJ_LENGTH_UNIT") == "cm"


Expand Down
4 changes: 1 addition & 3 deletions pygmt/tests/test_datasets_load_remote_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ def test_load_remote_dataset_benchmark_with_region():
assert data.attrs["horizontal_datum"] == "WGS84"
assert data.gmt.registration == 0
assert data.shape == (11, 21)
# The cpt attribute was added since GMT 6.4.0
# Can't access the cpt attribute using virtual files
# if Version(__gmt_version__) >= Version("6.4.0"):
# assert data.attrs["cpt"] == "@earth_age.cpt"
# assert data.attrs["cpt"] == "@earth_age.cpt"
Copy link
Member

Choose a reason for hiding this comment

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

Is this something that could be obtained from the GMT_GRID struct somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the cpt information is stored in the private, hidden structure GMT_GRID_HEADER_HIDDEN:

https://github.com/GenericMappingTools/gmt/blob/426abad288ef4b87c2cecf4c9633fd849866e45d/src/gmt_hidden.h#L163

We can't access it unless we decide to wrap the non-public GMT structure.



def test_load_remote_dataset_invalid_resolutions():
Expand Down
9 changes: 1 addition & 8 deletions pygmt/tests/test_grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import numpy as np
import pytest
import xarray as xr
from packaging.version import Version
from pygmt import grdfill, load_dataarray
from pygmt.clib import __gmt_version__
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief
Expand Down Expand Up @@ -86,16 +84,11 @@ def test_grdfill_dataarray_out(grid, expected_grid):
xr.testing.assert_allclose(a=result, b=expected_grid)


@pytest.mark.skipif(
Version(__gmt_version__) < Version("6.4.0"),
reason="Upstream bug/crash fixed in https://github.com/GenericMappingTools/gmt/pull/6418.",
)
def test_grdfill_asymmetric_pad(grid, expected_grid):
"""
Test grdfill using a region that includes the edge of the grid.

Regression test for
https://github.com/GenericMappingTools/pygmt/issues/1745.
Regression test for https://github.com/GenericMappingTools/pygmt/issues/1745.
"""
result = grdfill(grid=grid, mode="c20", region=[-55, -50, -24, -16])
# check information of the output grid
Expand Down
7 changes: 1 addition & 6 deletions pygmt/tests/test_grdfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
import numpy as np
import pytest
import xarray as xr
from packaging.version import Version
from pygmt import grdfilter, load_dataarray
from pygmt.clib import __gmt_version__
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief

# GMT 6.3 on conda-forge doesn't have OpenMP enabled.
cores = 2 if Version(__gmt_version__) > Version("6.3.0") else None


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
Expand Down Expand Up @@ -51,7 +46,7 @@ def test_grdfilter_dataarray_in_dataarray_out(grid, expected_grid):
Test grdfilter with an input DataArray, and output as DataArray.
"""
result = grdfilter(
grid=grid, filter="g600", distance="4", region=[-53, -49, -20, -17], cores=cores
grid=grid, filter="g600", distance="4", region=[-53, -49, -20, -17], cores=2
)
# check information of the output grid
assert isinstance(result, xr.DataArray)
Expand Down
7 changes: 1 addition & 6 deletions pygmt/tests/test_grdlandmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

import pytest
import xarray as xr
from packaging.version import Version
from pygmt import grdlandmask, load_dataarray
from pygmt.clib import __gmt_version__
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile

# GMT 6.3 on conda-forge doesn't have OpenMP enabled.
cores = 2 if Version(__gmt_version__) > Version("6.3.0") else None


@pytest.fixture(scope="module", name="expected_grid")
def fixture_expected_grid():
Expand Down Expand Up @@ -55,7 +50,7 @@ def test_grdlandmask_no_outgrid(expected_grid):
"""
Test grdlandmask with no set outgrid.
"""
result = grdlandmask(spacing=1, region=[125, 130, 30, 35], cores=cores)
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
Expand Down
7 changes: 1 addition & 6 deletions pygmt/tests/test_grdsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

import pytest
import xarray as xr
from packaging.version import Version
from pygmt import grdsample, load_dataarray
from pygmt.clib import __gmt_version__
from pygmt.helpers import GMTTempFile
from pygmt.helpers.testing import load_static_earth_relief

# GMT 6.3 on conda-forge doesn't have OpenMP enabled.
cores = 2 if Version(__gmt_version__) > Version("6.3.0") else None


@pytest.fixture(scope="module", name="grid")
def fixture_grid():
Expand Down Expand Up @@ -80,7 +75,7 @@ def test_grdsample_dataarray_out(grid, expected_grid, region, spacing):
"""
Test grdsample with no outgrid set and the spacing is changed.
"""
result = grdsample(grid=grid, spacing=spacing, region=region, cores=cores)
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
Expand Down
7 changes: 1 addition & 6 deletions pygmt/tests/test_sph2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@

import numpy.testing as npt
import pytest
from packaging.version import Version
from pygmt import sph2grd
from pygmt.clib import __gmt_version__
from pygmt.helpers import GMTTempFile

# GMT 6.3 on conda-forge doesn't have OpenMP enabled.
cores = 2 if Version(__gmt_version__) > Version("6.3.0") else None


def test_sph2grd_outgrid():
"""
Expand All @@ -32,7 +27,7 @@ def test_sph2grd_no_outgrid():
"""
Test sph2grd with no set outgrid.
"""
temp_grid = sph2grd(data="@EGM96_to_36.txt", spacing=1, region="g", cores=cores)
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
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_subplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_subplot_nrows_ncols_less_than_one_error():
pass


# Increase tolerance for compatibility with GMT 6.3 and 6.4, see
# Increase tolerance for compatibility with GMT 6.4, see
# https://github.com/GenericMappingTools/pygmt/pull/2454
@pytest.mark.mpl_image_compare(tolerance=4.0)
def test_subplot_outside_plotting_positioning():
Expand Down