Skip to content

Commit

Permalink
Merge pull request #348 from pytroll/fix-preresample-freeze
Browse files Browse the repository at this point in the history
Fix freezing of areas before resampling even as strings
  • Loading branch information
djhoese authored Jul 1, 2018
2 parents 20e3ebb + 0a790e6 commit c72af2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
14 changes: 0 additions & 14 deletions satpy/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand Down
9 changes: 6 additions & 3 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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.")
destination_area = get_frozen_area(destination_area, max_area)

resamplers = {}
for dataset, parent_dataset in dataset_walker(datasets):
Expand Down

0 comments on commit c72af2a

Please sign in to comment.