Skip to content

Commit

Permalink
Merge pull request #623 from mraspaud/feature-bounding-box-2
Browse files Browse the repository at this point in the history
Make use of bounding_box for area freezing when available
  • Loading branch information
mraspaud authored Oct 1, 2024
2 parents b279d35 + c4ce8ee commit 9becb0d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
mamba-version: "1.5.10"
python-version: ${{ matrix.python-version }}
environment-file: continuous_integration/environment.yaml
activate-environment: test-environment
channels: conda-forge

- name: Install unstable dependencies
if: matrix.experimental == true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ nosetests.xml
pyresample/ewa/_fornav.cpp
pyresample/ewa/_ll2cr.c
pyresample/gradient/_gradient_search.c

# don't include doctest files
docs/doctest/.doctrees/*
7 changes: 6 additions & 1 deletion pyresample/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,8 @@ def freeze(self, lonslats=None, resolution=None, shape=None, proj_info=None,
lonlats : SwathDefinition or tuple
The geographical coordinates to contain in the resulting area.
A tuple should be ``(lons, lats)``.
If a SwathDefinition is provided, and it has a "bounding_box" attribute, it will be used instead of the full
longitude and latitude to avoid potentially slow computations.
resolution:
the resolution of the resulting area.
shape:
Expand Down Expand Up @@ -1317,7 +1319,10 @@ def _extract_lons_lats(lonslats):
try:
lons, lats = lonslats
except (TypeError, ValueError):
lons, lats = lonslats.get_lonlats()
try:
lons, lats = lonslats.attrs["bounding_box"]
except (AttributeError, KeyError):
lons, lats = lonslats.get_lonlats()
return lons, lats

def _compute_new_x_corners_for_antimeridian(self, xarr, antimeridian_mode):
Expand Down
9 changes: 9 additions & 0 deletions pyresample/test/test_geometry/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from pyresample.future.geometry.area import ignore_pyproj_proj_warnings
from pyresample.future.geometry.base import get_array_hashable
from pyresample.geometry import AreaDefinition as LegacyAreaDefinition
from pyresample.geometry import DynamicAreaDefinition
from pyresample.test.utils import assert_future_geometry


Expand Down Expand Up @@ -1754,3 +1755,11 @@ def test_non2d_shape_error(shape):
"""Test that non-2D shapes fail."""
with pytest.raises(NotImplementedError):
AreaDefinition("EPSG:4326", shape, (-1000.0, -1000.0, 1000.0, 1000.0))


def test_dynamic_area_can_use_bounding_box_attribute():
"""Test that area freezing can use bounding box info."""
area_def = DynamicAreaDefinition("test_area", "", "epsg:3035", resolution=500)
swath_def_to_freeze_on = SwathDefinition(None, None, attrs=dict(bounding_box=[[0, 20, 20, 0], [55, 55, 45, 45]]))
res_area = area_def.freeze(swath_def_to_freeze_on)
assert res_area.area_extent == (3533500, 2484500, 5108500, 3588500)

0 comments on commit 9becb0d

Please sign in to comment.