From 5fc21f8e5ce5a72b6d1502094e249eb6e3131cb1 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Fri, 29 Jun 2018 13:19:09 +0200 Subject: [PATCH 1/2] Fix freezing of areas before resampling even as strings --- satpy/scene.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/satpy/scene.py b/satpy/scene.py index 93f3930502..4f3039c704 100644 --- a/satpy/scene.py +++ b/satpy/scene.py @@ -866,12 +866,12 @@ def _resampled_scene(self, new_scn, destination_area, **resample_kwargs): new_datasets = {} datasets = list(new_scn.datasets.values()) max_area = None - if hasattr(destination_area, 'freeze'): - try: - max_area = new_scn.max_area() - except ValueError: - raise ValueError("No dataset areas available to freeze " - "DynamicAreaDefinition.") + + try: + max_area = new_scn.max_area() + except ValueError: + raise ValueError("No dataset areas available to freeze " + "DynamicAreaDefinition.") destination_area = get_frozen_area(destination_area, max_area) resamplers = {} From 0a790e64c22c98a749a5071c0858145344c170ca Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Fri, 29 Jun 2018 16:39:30 +0200 Subject: [PATCH 2/2] Do not perform freezing unless needed --- satpy/resample.py | 14 -------------- satpy/scene.py | 21 ++++++++++++--------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/satpy/resample.py b/satpy/resample.py index e9268a1390..7df6a71cbc 100644 --- a/satpy/resample.py +++ b/satpy/resample.py @@ -136,7 +136,6 @@ import xarray as xr import dask import dask.array as da -import six from pyresample.bilinear import get_bil_info, get_sample_from_bil_info from pyresample.ewa import fornav, ll2cr @@ -181,19 +180,6 @@ def get_area_def(area_name): return parse_area_file(get_area_file(), area_name)[0] -def get_frozen_area(to_freeze, ref): - """Freeze the *to_freeze* area according to *ref* if applicable, otherwise - return *to_freeze* as an area definition instance. - """ - if isinstance(to_freeze, (str, six.text_type)): - to_freeze = get_area_def(to_freeze) - - try: - return to_freeze.freeze(ref) - except AttributeError: - return to_freeze - - class BaseResampler(object): """Base abstract resampler class.""" diff --git a/satpy/scene.py b/satpy/scene.py index 4f3039c704..ea04207581 100644 --- a/satpy/scene.py +++ b/satpy/scene.py @@ -33,11 +33,12 @@ replace_anc) from satpy.node import DependencyTree from satpy.readers import DatasetDict, load_readers -from satpy.resample import (resample_dataset, get_frozen_area, - prepare_resampler) +from satpy.resample import (resample_dataset, + prepare_resampler, get_area_def) from satpy.writers import load_writer from pyresample.geometry import AreaDefinition from xarray import DataArray +import six try: import configparser @@ -866,13 +867,15 @@ def _resampled_scene(self, new_scn, destination_area, **resample_kwargs): new_datasets = {} datasets = list(new_scn.datasets.values()) max_area = None - - try: - max_area = new_scn.max_area() - except ValueError: - raise ValueError("No dataset areas available to freeze " - "DynamicAreaDefinition.") - destination_area = get_frozen_area(destination_area, max_area) + if isinstance(destination_area, (str, six.text_type)): + 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) + except ValueError: + raise ValueError("No dataset areas available to freeze " + "DynamicAreaDefinition.") resamplers = {} for dataset, parent_dataset in dataset_walker(datasets):