Skip to content

Commit

Permalink
Merge branch 'main' into rolling-window-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
santisoler authored Sep 5, 2024
2 parents 288ec90 + 605ecd7 commit f3c042d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 37 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ jobs:
echo "Collected dependencies:"
cat requirements-full.txt
- name: Rename conda-forge packages
run: |
echo "Rename conda-forge packages in requirements-full.txt"
# Replace "build" for "python-build"
sed -s --in-place 's/^build$/python-build/' requirements-full.txt
echo "Renamed dependencies:"
cat requirements-full.txt
- name: Install requirements
run: conda install --file requirements-full.txt python=$PYTHON -c conda-forge

Expand Down
50 changes: 46 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defaults:

jobs:
#############################################################################
# Run tests and upload to codecov
# Run tests
test:
name: ${{ matrix.os }} python=${{ matrix.python }} dependencies=${{ matrix.dependencies }}
runs-on: ${{ matrix.os }}-latest
Expand Down Expand Up @@ -114,6 +114,21 @@ jobs:
echo "Collected dependencies:"
cat requirements-full.txt
- name: Rename conda-forge packages
run: |
# Choose options to sed based on the OS (macos uses POSIX sed)
if [[ ${{ matrix.os }} == macos ]]; then
opts="-i''"
else
opts='-s --in-place'
fi
echo "OPTS:" $opts
echo "Rename conda-forge packages in requirements-full.txt"
# Replace "build" for "python-build"
sed $opts 's/^build$/python-build/' requirements-full.txt
echo "Renamed dependencies:"
cat requirements-full.txt
- name: Install requirements
run: conda install --quiet --file requirements-full.txt python=$PYTHON

Expand Down Expand Up @@ -150,11 +165,38 @@ jobs:
- name: Convert coverage report to XML for codecov
run: coverage xml

- name: Upload coverage to Codecov
- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.os }}_${{ matrix.dependencies }}
path: ./coverage.xml


#############################################################################
# Upload coverage report to codecov
codecov-upload:
runs-on: ubuntu-latest
needs: test

steps:

- name: Download coverage report artifacts
# Download coverage reports from every runner.
# Maximum coverage is achieved by combining reports from every runner.
# Each coverage file will live in its own folder with the same name as
# the artifact.
uses: actions/download-artifact@v4
with:
pattern: coverage_*

- name: List all downloaded artifacts
run: ls -l -R .

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
env_vars: OS,PYTHON,DEPENDENCIES
# Upload all coverage report files
files: ./coverage_*/coverage.xml
# Fail the job so we know coverage isn't being updated. Otherwise it
# can silently drop and we won't know.
fail_ci_if_error: true
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- pip
# Build
- twine
- build
- python-build
# Run
- numpy
- scipy
Expand Down
10 changes: 2 additions & 8 deletions verde/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def get_region(coordinates):
--------
>>> coords = grid_coordinates((0, 1, -10, -6), shape=(10, 10))
>>> print(get_region(coords))
>>> region = get_region(coords)
>>> print(tuple(float(c) for c in region))
(0.0, 1.0, -10.0, -6.0)
"""
Expand Down Expand Up @@ -233,9 +234,6 @@ def line_coordinates(
Examples
--------
>>> # Lower printing precision to shorten this example
>>> import numpy as np; np.set_printoptions(precision=2, suppress=True)
>>> values = line_coordinates(0, 5, spacing=2.5)
>>> print(values.shape)
(3,)
Expand Down Expand Up @@ -362,8 +360,6 @@ def grid_coordinates(
>>> east, north = grid_coordinates(region=(0, 5, 0, 10), shape=(5, 3))
>>> print(east.shape, north.shape)
(5, 3) (5, 3)
>>> # Lower printing precision to shorten this example
>>> import numpy as np; np.set_printoptions(precision=1, suppress=True)
>>> print(east)
[[0. 2.5 5. ]
[0. 2.5 5. ]
Expand Down Expand Up @@ -485,8 +481,6 @@ def grid_coordinates(
>>> east, north = grid_coordinates(region=(0, 5, 0, 10), spacing=2.5,
... pixel_register=True)
>>> # Raise the printing precision for this example
>>> np.set_printoptions(precision=2, suppress=True)
>>> # Notice that the shape is 1 less than when pixel_register=False
>>> print(east.shape, north.shape)
(4, 2) (4, 2)
Expand Down
3 changes: 2 additions & 1 deletion verde/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def project_region(region, projection):
>>> def projection(x, y):
... return (2*x, -1*y)
>>> project_region((3, 5, -9, -4), projection)
>>> region_proj = project_region((3, 5, -9, -4), projection)
>>> print(tuple(float(c) for c in region_proj))
(6.0, 10.0, 4.0, 9.0)
"""
Expand Down
31 changes: 13 additions & 18 deletions verde/tests/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,23 @@ def test_rolling_window_no_shape_or_spacing():
rolling_window(coords, size=2)


def test_rolling_window_oversized_window():
@pytest.mark.parametrize(
"region",
[
(-5, -1, 6, 20), # window larger than west-east
(-20, -1, 6, 10), # window larger than south-north
(-5, -1, 6, 10), # window larger than both dims
],
)
def test_rolling_window_oversized_window(region):
"""
Check if error is raised if size larger than region is passed
"""
oversize = 5
regions = [
(-5, -1, 6, 20), # window larger than west-east
(-20, -1, 6, 10), # window larger than south-north
(-5, -1, 6, 10), # window larger than both dims
]
for region in regions:
coords = grid_coordinates(region, spacing=1)
# The expected error message with regex
# (the long expression intends to capture floats and ints)
float_regex = r"[+-]?([0-9]*[.])?[0-9]+"
err_msg = (
r"Window size '{}' is larger ".format(float_regex)
+ r"than dimensions of the region "
+ r"'\({0}, {0}, {0}, {0}\)'.".format(float_regex)
)
with pytest.raises(ValueError, match=err_msg):
rolling_window(coords, size=oversize, spacing=2)
coords = grid_coordinates(region, spacing=1)
err_msg = f"Window size '{oversize}' is larger than dimensions of the region "
with pytest.raises(ValueError, match=err_msg):
rolling_window(coords, size=oversize, spacing=2)


def test_spacing_to_size():
Expand Down
16 changes: 11 additions & 5 deletions verde/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,24 @@ def maxabs(*args, nan=True):
Examples
--------
>>> maxabs((1, -10, 25, 2, 3))
25
>>> maxabs((1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499))
>>> result = maxabs((1, -10, 25, 2, 3))
>>> float(result)
25.0
>>> result = maxabs(
... (1, -10.5, 25, 2), (0.1, 100, -500), (-200, -300, -0.1, -499)
... )
>>> float(result)
500.0
If the array contains NaNs, we'll use the ``nan`` version of of the numpy
functions by default. You can turn this off through the *nan* argument.
>>> import numpy as np
>>> maxabs((1, -10, 25, 2, 3, np.nan))
>>> result = maxabs((1, -10, 25, 2, 3, np.nan))
>>> float(result)
25.0
>>> maxabs((1, -10, 25, 2, 3, np.nan), nan=False)
>>> result = maxabs((1, -10, 25, 2, 3, np.nan), nan=False)
>>> float(result)
nan
"""
Expand Down

0 comments on commit f3c042d

Please sign in to comment.