Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent EWA test failures #482

Merged
merged 6 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyresample/ewa/_legacy_dask_ewa.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def precompute(self, cache_dir=None, swath_usage=0, **kwargs):
chunks = (2,) + lons.chunks
res = da.map_blocks(self._call_ll2cr, lons, lats,
target_geo_def, swath_usage,
meta=np.array((), dtype=lons.dtype),
dtype=lons.dtype, chunks=chunks, new_axis=[0])
cols = res[0]
rows = res[1]
Expand Down Expand Up @@ -232,7 +233,7 @@ def compute(self, data, cache_id=None, fill_value=0, weight_count=10000,
rows_per_scan = self._get_rows_per_scan(kwargs, data)
data_in = self._get_data_arr(data)

res = dask.delayed(self._call_fornav)(
res = dask.delayed(self._call_fornav, pure=True)(
cols, rows, self.target_geo_def, data_in,
grid_coverage=grid_coverage,
rows_per_scan=rows_per_scan, weight_count=weight_count,
Expand All @@ -243,7 +244,8 @@ def compute(self, data, cache_id=None, fill_value=0, weight_count=10000,
new_shape = (len(data_in),) + self.target_geo_def.shape
else:
new_shape = self.target_geo_def.shape
data_arr = da.from_delayed(res, new_shape, data.dtype)
data_arr = da.from_delayed(res, new_shape, dtype=data.dtype,
meta=np.array((), dtype=data.dtype))
# from delayed creates one large chunk, break it up a bit if we can
data_arr = data_arr.rechunk([chunks or CHUNK_SIZE] * data_arr.ndim)
if data.ndim == 3 and data.dims[0] == 'bands':
Expand Down
7 changes: 2 additions & 5 deletions pyresample/ewa/dask_ewa.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@
logger = logging.getLogger(__name__)


def _call_ll2cr(lons, lats, target_geo_def, computing_meta=False):
def _call_ll2cr(lons, lats, target_geo_def):
"""Wrap ll2cr() for handling dask delayed calls better."""
if computing_meta:
# produce a representative meta array in the best case
# avoids errors when we return our "empty" tuples below
return np.zeros((2, *lons.shape), dtype=lons.dtype)
new_src = SwathDefinition(lons, lats)
swath_points_in_grid, cols, rows = ll2cr(new_src, target_geo_def)
if swath_points_in_grid == 0:
Expand All @@ -73,6 +69,7 @@ def _call_ll2cr(lons, lats, target_geo_def, computing_meta=False):
def _call_mapped_ll2cr(lons, lats, target_geo_def):
res = da.map_blocks(_call_ll2cr, lons, lats,
target_geo_def,
meta=np.array((), dtype=lons.dtype),
dtype=lons.dtype)
return res

Expand Down
4 changes: 3 additions & 1 deletion pyresample/test/test_dask_ewa.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
from unittest import mock

import dask
import numpy as np
import pytest
from pyproj import CRS
Expand Down Expand Up @@ -204,7 +205,8 @@ def test_xarray_basic_ewa(self, resampler_class, resampler_mod,
num_chunks = _get_num_chunks(source_swath, resampler_class, rows_per_scan)

with mock.patch.object(resampler_mod, 'll2cr', wraps=resampler_mod.ll2cr) as ll2cr, \
mock.patch.object(source_swath, 'get_lonlats', wraps=source_swath.get_lonlats) as get_lonlats:
mock.patch.object(source_swath, 'get_lonlats', wraps=source_swath.get_lonlats) as get_lonlats, \
dask.config.set(scheduler='sync'):
resampler = resampler_class(source_swath, target_area)
new_data = resampler.resample(swath_data, rows_per_scan=rows_per_scan,
weight_delta_max=40,
Expand Down