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 args of bucket_sum and bucket_avg resampler #1539

Merged
merged 10 commits into from Mar 12, 2021
2 changes: 1 addition & 1 deletion doc/source/readers.rst
Expand Up @@ -63,7 +63,7 @@ polarization::

Or multiple calibrations::

>>> scn.load([0.6, 10.8], calibrations=['brightness_temperature', 'radiance'])
>>> scn.load([0.6, 10.8], calibration=['brightness_temperature', 'radiance'])

In the above case Satpy will load whatever dataset is available and matches
the specified parameters. So the above ``load`` call would load the ``0.6``
Expand Down
31 changes: 20 additions & 11 deletions satpy/resample.py
Expand Up @@ -1120,24 +1120,29 @@ class BucketAvg(BucketResamplerBase):
Parameters
----------
fill_value : float (default: np.nan)
Fill value for missing data
mask_all_nans : boolean (default: False)
Mask all locations with all-NaN values
Fill value to mark missing/invalid values in the input data,
as well as in the binned and averaged output data.
skipna : boolean (default: True)
If True, skips missing values (as marked by NaN or `fill_value`) for the average calculation
(similarly to Numpy's `nanmean`). Buckets containing only missing values are set to fill_value.
If False, sets the bucket to fill_value if one or more missing values are present in the bucket
(similarly to Numpy's `mean`).
In both cases, empty buckets are set to `fill_value`.

"""

def compute(self, data, fill_value=np.nan, mask_all_nan=False, **kwargs):
def compute(self, data, fill_value=np.nan, skipna=True, **kwargs):
"""Call the resampling."""
results = []
if data.ndim == 3:
for i in range(data.shape[0]):
res = self.resampler.get_average(data[i, :, :],
fill_value=fill_value,
mask_all_nan=mask_all_nan)
skipna=skipna)
results.append(res)
else:
res = self.resampler.get_average(data, fill_value=fill_value,
mask_all_nan=mask_all_nan)
skipna=skipna)
results.append(res)

return da.stack(results)
Expand All @@ -1153,22 +1158,26 @@ class BucketSum(BucketResamplerBase):
----------
fill_value : float (default: np.nan)
Fill value for missing data
mask_all_nans : boolean (default: False)
Mask all locations with all-NaN values
skipna : boolean (default: True)
If True, skips NaN values for the sum calculation
(similarly to Numpy's `nansum`). Buckets containing only NaN are set to zero.
ameraner marked this conversation as resolved.
Show resolved Hide resolved
If False, sets the bucket to NaN if one or more NaN values are present in the bucket
(similarly to Numpy's `sum`).
In both cases, empty buckets are set to 0.

"""

def compute(self, data, mask_all_nan=False, **kwargs):
def compute(self, data, skipna=True, **kwargs):
"""Call the resampling."""
LOG.debug("Resampling %s", str(data.name))
results = []
if data.ndim == 3:
for i in range(data.shape[0]):
res = self.resampler.get_sum(data[i, :, :],
mask_all_nan=mask_all_nan)
skipna=skipna)
results.append(res)
else:
res = self.resampler.get_sum(data, mask_all_nan=mask_all_nan)
res = self.resampler.get_sum(data, skipna=skipna)
results.append(res)

return da.stack(results)
Expand Down
8 changes: 4 additions & 4 deletions satpy/tests/test_resample.py
Expand Up @@ -725,7 +725,7 @@ def test_compute(self):
self.bucket.resampler.get_average.assert_called_once_with(
data,
fill_value=2,
mask_all_nan=False)
skipna=True)
self.assertEqual(res.shape, (1, 5))
# 2D data
self.bucket.resampler = mock.MagicMock()
Expand All @@ -735,7 +735,7 @@ def test_compute(self):
self.bucket.resampler.get_average.assert_called_once_with(
data,
fill_value=2,
mask_all_nan=False)
skipna=True)
self.assertEqual(res.shape, (1, 5, 5))
# 3D data
self.bucket.resampler = mock.MagicMock()
Expand Down Expand Up @@ -810,7 +810,7 @@ def test_compute(self):
res = self.bucket.compute(data)
self.bucket.resampler.get_sum.assert_called_once_with(
data,
mask_all_nan=False)
skipna=True)
self.assertEqual(res.shape, (1, 5))
# 2D data
self.bucket.resampler = mock.MagicMock()
Expand All @@ -819,7 +819,7 @@ def test_compute(self):
res = self.bucket.compute(data)
self.bucket.resampler.get_sum.assert_called_once_with(
data,
mask_all_nan=False)
skipna=True)
self.assertEqual(res.shape, (1, 5, 5))
# 3D data
self.bucket.resampler = mock.MagicMock()
Expand Down