Skip to content

Commit

Permalink
Merge pull request #1565 from pnuu/rename_min_max_area
Browse files Browse the repository at this point in the history
Rename min_area() and max_area() methods
  • Loading branch information
mraspaud authored Feb 25, 2021
2 parents feea149 + 94c2b14 commit bae4793
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
6 changes: 3 additions & 3 deletions satpy/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@
>>> new_scn = scn.resample(resampler='native')
By default this resamples to the
:meth:`highest resolution area <satpy.scene.Scene.max_area>` (smallest footprint per
pixel) shared between the loaded datasets. You can easily specify the lower
:meth:`highest resolution area <satpy.scene.Scene.finest_area>` (smallest footprint per
pixel) shared between the loaded datasets. You can easily specify the lowest
resolution area:
.. code-block:: python
>>> new_scn = scn.resample(scn.min_area(), resampler='native')
>>> new_scn = scn.resample(scn.coarsest_area(), resampler='native')
Providing an area that is neither the minimum or maximum resolution area
may work, but behavior is currently undefined.
Expand Down
51 changes: 40 additions & 11 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import logging
import os
import warnings

from satpy.composites import IncompatibleAreas
from satpy.composites.config_loader import CompositorLoader
Expand Down Expand Up @@ -221,7 +222,7 @@ def key_func(ds):
# find the highest/lowest area among the provided
return compare_func(areas, key=key_func)

def max_area(self, datasets=None):
def finest_area(self, datasets=None):
"""Get highest resolution area for the provided datasets.
Args:
Expand All @@ -233,7 +234,21 @@ def max_area(self, datasets=None):
"""
return self._compare_areas(datasets=datasets, compare_func=max)

def min_area(self, datasets=None):
def max_area(self, datasets=None):
"""Get highest resolution area for the provided datasets. Deprecated.
Args:
datasets (iterable): Datasets whose areas will be compared. Can
be either `xarray.DataArray` objects or
identifiers to get the DataArrays from the
current Scene. Defaults to all datasets.
"""
warnings.warn("'max_area' is deprecated, use 'finest_area' instead.",
warnings.DeprecationWarning)
return self.finest_area(datasets=datasets)

def coarsest_area(self, datasets=None):
"""Get lowest resolution area for the provided datasets.
Args:
Expand All @@ -245,6 +260,20 @@ def min_area(self, datasets=None):
"""
return self._compare_areas(datasets=datasets, compare_func=min)

def min_area(self, datasets=None):
"""Get lowest resolution area for the provided datasets. Deprecated.
Args:
datasets (iterable): Datasets whose areas will be compared. Can
be either `xarray.DataArray` objects or
identifiers to get the DataArrays from the
current Scene. Defaults to all datasets.
"""
warnings.warn("'min_area' is deprecated, use 'coarsest_area' instead.",
warnings.DeprecationWarning)
return self.coarsest_area(datasets=datasets)

def available_dataset_ids(self, reader_name=None, composites=False):
"""Get DataIDs of loadable datasets.
Expand Down Expand Up @@ -552,11 +581,11 @@ def crop(self, area=None, ll_bbox=None, xy_bbox=None, dataset_ids=None):

# get the lowest resolution area, use it as the base of the slice
# this makes sure that the other areas *should* be a consistent factor
min_area = new_scn.min_area()
coarsest_area = new_scn.coarsest_area()
if isinstance(area, str):
area = get_area_def(area)
new_min_area, min_y_slice, min_x_slice = self._slice_area_from_bbox(
min_area, area, ll_bbox, xy_bbox)
new_coarsest_area, min_y_slice, min_x_slice = self._slice_area_from_bbox(
coarsest_area, area, ll_bbox, xy_bbox)
new_target_areas = {}
for src_area, dataset_ids in new_scn.iter_by_area():
if src_area is None:
Expand All @@ -565,9 +594,9 @@ def crop(self, area=None, ll_bbox=None, xy_bbox=None, dataset_ids=None):
continue

y_factor, y_remainder = np.divmod(float(src_area.shape[0]),
min_area.shape[0])
coarsest_area.shape[0])
x_factor, x_remainder = np.divmod(float(src_area.shape[1]),
min_area.shape[1])
coarsest_area.shape[1])
y_factor = int(y_factor)
x_factor = int(x_factor)
if y_remainder == 0 and x_remainder == 0:
Expand Down Expand Up @@ -684,8 +713,8 @@ def _resampled_scene(self, new_scn, destination_area, reduce_data=True,
destination_area = get_area_def(destination_area)
if hasattr(destination_area, 'freeze'):
try:
max_area = new_scn.max_area()
destination_area = destination_area.freeze(max_area)
finest_area = new_scn.finest_area()
destination_area = destination_area.freeze(finest_area)
except ValueError:
raise ValueError("No dataset areas available to freeze "
"DynamicAreaDefinition.")
Expand Down Expand Up @@ -755,7 +784,7 @@ def resample(self, destination=None, datasets=None, generate=True,
Args:
destination (AreaDefinition, GridDefinition): area definition to
resample to. If not specified then the area returned by
`Scene.max_area()` will be used.
`Scene.finest_area()` will be used.
datasets (list): Limit datasets to resample to these specified
data arrays. By default all currently loaded
datasets are resampled.
Expand All @@ -780,7 +809,7 @@ def resample(self, destination=None, datasets=None, generate=True,
if (not datasets) or dsid in datasets]

if destination is None:
destination = self.max_area(to_resample_ids)
destination = self.finest_area(to_resample_ids)
new_scn = self.copy(datasets=to_resample_ids)
# we may have some datasets we asked for but don't exist yet
new_scn._wishlist = self._wishlist.copy()
Expand Down
2 changes: 1 addition & 1 deletion satpy/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_1258(fake_open_dataset):

scene = Scene(abi_file_list, reader='abi_l1b')
scene.load(['true_color_nocorr', 'C04'], calibration='radiance')
resampled_scene = scene.resample(scene.min_area(), resampler='native')
resampled_scene = scene.resample(scene.coarsest_area(), resampler='native')
assert len(resampled_scene.keys()) == 2


Expand Down
10 changes: 5 additions & 5 deletions satpy/tests/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ def test_delitem(self):
self.assertEqual(len(scene._datasets.keys()), 0)
self.assertRaises(KeyError, scene.__delitem__, 0.2)

def test_min_max_area(self):
"""Test 'min_area' and 'max_area' methods."""
def test_coarsest_finest_area(self):
"""Test 'coarsest_area' and 'finest_area' methods."""
from satpy import Scene
from xarray import DataArray
from pyresample.geometry import AreaDefinition
Expand Down Expand Up @@ -612,9 +612,9 @@ def test_min_max_area(self):
ds1.attrs['area'] = area_def1
ds2.attrs['area'] = area_def2
ds3.attrs['area'] = area_def2
self.assertIs(scene.min_area(), area_def1)
self.assertIs(scene.max_area(), area_def2)
self.assertIs(scene.min_area(['2', '3']), area_def2)
self.assertIs(scene.coarsest_area(), area_def1)
self.assertIs(scene.finest_area(), area_def2)
self.assertIs(scene.coarsest_area(['2', '3']), area_def2)

def test_all_datasets_no_readers(self):
"""Test all datasets with no reader."""
Expand Down

0 comments on commit bae4793

Please sign in to comment.