Skip to content

Commit

Permalink
Drop support for GMT 6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Sep 24, 2024
1 parent 5f96b77 commit d2eb9f8
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 55 deletions.
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 @@ -199,15 +198,8 @@ def info(self):
"cores": self.get_default("API_CORES"),
"grid layout": self.get_default("API_GRID_LAYOUT"),
}
# 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")
self._info["image layout"] = self.get_default("API_IMAGE_LAYOUT")
self._info["binary version"] = self.get_default("API_BIN_VERSION")
return self._info

def __enter__(self):
Expand Down
10 changes: 5 additions & 5 deletions pygmt/src/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def timestamp(
font
Font of the timestamp and the optional label. Since the GMT logo has a fixed
height, the font sizes are fixed to be 8-point for the timestamp and 7-point for
the label. The parameter can't change the font color for GMT<=6.4.0, only the
the label. The parameter can't change the font color for GMT 6.4.0, only the
font style.
timefmt
Format string for the UNIX timestamp. The format string is parsed by the C
Expand Down 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"


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

0 comments on commit d2eb9f8

Please sign in to comment.