Skip to content

Commit

Permalink
Merge branch 'main' into update-psconvert-syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgrund authored Dec 30, 2021
2 parents 4b8581a + 90cda7f commit 3310f1e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.9']
os: [ubuntu-latest, macOS-latest, windows-latest]
# Is it a draft Pull Request (true or false)?
isDraft:
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/ci_tests_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.10']
os: [ubuntu-latest, macOS-11.0, windows-2022]
gmt_git_ref: [master]
timeout-minutes: 30
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
uses: conda-incubator/setup-miniconda@v2.1.1
with:
activate-environment: pygmt
python-version: ${{ matrix.python-version }}
# python-version: ${{ matrix.python-version }}
channels: conda-forge,nodefaults
channel-priority: strict
miniforge-version: latest
Expand All @@ -88,11 +88,13 @@ jobs:
# Install dependencies from conda-forge
- name: Install dependencies
run: |
mamba install ninja cmake libblas libcblas liblapack fftw gdal geopandas \
ghostscript libnetcdf hdf5 zlib curl pcre make dvc
pip install --pre numpy pandas xarray netCDF4 packaging \
ipython pytest-cov pytest-mpl pytest>=6.0 sphinx-gallery \
tomli
mamba install python=${{ matrix.python-version }} \
ninja cmake libblas libcblas liblapack fftw libgdal \
geopandas ghostscript libnetcdf hdf5 zlib curl pcre make
pip install --pre --prefer-binary \
numpy pandas xarray netCDF4 packaging \
dvc ipython 'pytest>=6.0' pytest-cov \
pytest-mpl sphinx-gallery tomli
# Build and install latest GMT from GitHub
- name: Install GMT ${{ matrix.gmt_git_ref }} branch (Linux/macOS)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Compatibility with GMT/Python/NumPy versions
* - `Dev <https://github.com/GenericMappingTools/pygmt/milestone/9>`_ (upcoming release)
- `Dev Documentation <https://www.pygmt.org/dev>`_ (reflects `main branch <https://github.com/GenericMappingTools/pygmt>`_)
- >=6.3.0
- >=3.7
- >=3.8
- >=1.19
* - `v0.5.0 <https://github.com/GenericMappingTools/pygmt/releases/tag/v0.5.0>`_ (latest release)
- `v0.5.0 Documentation <https://www.pygmt.org/v0.5.0>`_
Expand Down
46 changes: 33 additions & 13 deletions pygmt/tests/test_grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pytest
import xarray as xr
from pygmt import grdfill, grdinfo
from pygmt import grdfill, load_dataarray
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile
Expand All @@ -18,36 +18,56 @@ def fixture_grid():
Load the grid data from the sample earth_relief file and set value(s) to
NaN.
"""
grid = load_earth_relief(registration="pixel", region=[-5, 5, -5, 5])
grid[3:5, 3:5] = np.nan
grid[5:7, 5:7] = np.inf
grid = load_earth_relief(registration="pixel", region=[125, 130, -25, -20])
grid[2:4, 1:3] = np.nan
grid[0:2, 2:4] = np.inf
return grid


def test_grdfill_dataarray_out(grid):
@pytest.fixture(scope="module", name="expected_grid")
def fixture_grid_result():
"""
grdfill with a DataArray output.
Load the expected grdfill grid result.
"""
return xr.DataArray(
data=[
[442.5, 439.0, np.inf, np.inf, 508.0],
[393.0, 364.5, np.inf, np.inf, 506.5],
[362.0, 20.0, 20.0, 373.5, 402.5],
[321.5, 20.0, 20.0, 356.0, 422.5],
[282.5, 318.0, 326.5, 379.5, 383.5],
],
coords=dict(
lon=[125.5, 126.5, 127.5, 128.5, 129.5],
lat=[-24.5, -23.5, -22.5, -21.5, -20.5],
),
dims=["lat", "lon"],
)


def test_grdfill_dataarray_out(grid, expected_grid):
"""
Test grdfill with a DataArray output.
"""
result = grdfill(grid=grid, mode="c20")
# check information of the output grid
assert isinstance(result, xr.DataArray)
assert result[4, 4] == 20
assert result[5, 5] == np.inf
assert not result.isnull().all() # check that no NaN values exists
assert result.gmt.gtype == 1 # Geographic grid
assert result.gmt.registration == 1 # Pixel registration
# check information of the output grid
xr.testing.assert_allclose(a=result, b=expected_grid)


def test_grdfill_file_out(grid):
def test_grdfill_file_out(grid, expected_grid):
"""
grdfill with an outgrid set.
Test grdfill with an outgrid set.
"""
with GMTTempFile(suffix=".nc") as tmpfile:
result = grdfill(grid=grid, mode="c20", outgrid=tmpfile.name)
assert result is None # return value is None
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
result = grdinfo(tmpfile.name, per_column=True).strip()
assert result == "-5 5 -5 5 -5130.5 inf 1 1 10 10 1 1"
temp_grid = load_dataarray(tmpfile.name)
xr.testing.assert_allclose(a=temp_grid, b=expected_grid)


def test_grdfill_required_args(grid):
Expand Down

0 comments on commit 3310f1e

Please sign in to comment.