Skip to content

Commit 9becb0d

Browse files
authored
Merge pull request #623 from mraspaud/feature-bounding-box-2
Make use of bounding_box for area freezing when available
2 parents b279d35 + c4ce8ee commit 9becb0d

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535
- name: Setup Conda Environment
3636
uses: conda-incubator/setup-miniconda@v3
3737
with:
38-
miniforge-variant: Mambaforge
3938
miniforge-version: latest
40-
use-mamba: true
39+
mamba-version: "1.5.10"
4140
python-version: ${{ matrix.python-version }}
4241
environment-file: continuous_integration/environment.yaml
4342
activate-environment: test-environment
43+
channels: conda-forge
4444

4545
- name: Install unstable dependencies
4646
if: matrix.experimental == true

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ nosetests.xml
6262
pyresample/ewa/_fornav.cpp
6363
pyresample/ewa/_ll2cr.c
6464
pyresample/gradient/_gradient_search.c
65+
66+
# don't include doctest files
67+
docs/doctest/.doctrees/*

pyresample/geometry.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,8 @@ def freeze(self, lonslats=None, resolution=None, shape=None, proj_info=None,
12281228
lonlats : SwathDefinition or tuple
12291229
The geographical coordinates to contain in the resulting area.
12301230
A tuple should be ``(lons, lats)``.
1231+
If a SwathDefinition is provided, and it has a "bounding_box" attribute, it will be used instead of the full
1232+
longitude and latitude to avoid potentially slow computations.
12311233
resolution:
12321234
the resolution of the resulting area.
12331235
shape:
@@ -1317,7 +1319,10 @@ def _extract_lons_lats(lonslats):
13171319
try:
13181320
lons, lats = lonslats
13191321
except (TypeError, ValueError):
1320-
lons, lats = lonslats.get_lonlats()
1322+
try:
1323+
lons, lats = lonslats.attrs["bounding_box"]
1324+
except (AttributeError, KeyError):
1325+
lons, lats = lonslats.get_lonlats()
13211326
return lons, lats
13221327

13231328
def _compute_new_x_corners_for_antimeridian(self, xarr, antimeridian_mode):

pyresample/test/test_geometry/test_area.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from pyresample.future.geometry.area import ignore_pyproj_proj_warnings
3131
from pyresample.future.geometry.base import get_array_hashable
3232
from pyresample.geometry import AreaDefinition as LegacyAreaDefinition
33+
from pyresample.geometry import DynamicAreaDefinition
3334
from pyresample.test.utils import assert_future_geometry
3435

3536

@@ -1754,3 +1755,11 @@ def test_non2d_shape_error(shape):
17541755
"""Test that non-2D shapes fail."""
17551756
with pytest.raises(NotImplementedError):
17561757
AreaDefinition("EPSG:4326", shape, (-1000.0, -1000.0, 1000.0, 1000.0))
1758+
1759+
1760+
def test_dynamic_area_can_use_bounding_box_attribute():
1761+
"""Test that area freezing can use bounding box info."""
1762+
area_def = DynamicAreaDefinition("test_area", "", "epsg:3035", resolution=500)
1763+
swath_def_to_freeze_on = SwathDefinition(None, None, attrs=dict(bounding_box=[[0, 20, 20, 0], [55, 55, 45, 45]]))
1764+
res_area = area_def.freeze(swath_def_to_freeze_on)
1765+
assert res_area.area_extent == (3533500, 2484500, 5108500, 3588500)

0 commit comments

Comments
 (0)