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

bucket_sum resampler fails due to unexpected fill_value kwarg #2805

Closed
ameraner opened this issue May 22, 2024 · 0 comments · Fixed by pytroll/pyresample#602
Closed

bucket_sum resampler fails due to unexpected fill_value kwarg #2805

ameraner opened this issue May 22, 2024 · 0 comments · Fixed by pytroll/pyresample#602

Comments

@ameraner
Copy link
Member

Describe the bug
The bucket_sum resampler fails due to a fill_value argument

satpy/satpy/resample.py

Lines 1067 to 1068 in 233f698

fill_value = kwargs.pop("fill_value", get_fill_value(dataset))
new_data = resample(source_area, dataset, destination_area, fill_value=fill_value, **kwargs)

that is then passed as kwarg to pyresample here:

satpy/satpy/resample.py

Lines 916 to 921 in 233f698

for i in range(data.shape[0]):
res = self.resampler.get_sum(data[i, :, :], skipna=skipna,
**kwargs)
results.append(res)
else:
res = self.resampler.get_sum(data, skipna=skipna, **kwargs)

and is then not accepted inside pyresample: https://github.com/pytroll/pyresample/blob/4e18999cb76c3404d0f5ec3df04b3350e56f0612/pyresample/bucket/__init__.py#L205

To Reproduce

path_to_testdata = '/tcenas/scratch/andream/lil2a/'
scn = Scene(filenames=glob(os.path.join(path_to_testdata, '*AF*---*T_0073_0001.nc')), reader='li_l2_nc',
            reader_kwargs={'with_area_definition': False})
scn.load(['flash_accumulation'], upper_right_corner='NE')
# resample 1-d array onto grid
scn_r = scn.resample('mtg_fci_fdss_2km', resampler='bucket_sum')

Expected behavior
Working resampler

Actual results

DEBUG: 2024-05-22 13:32:11 : satpy.resample] Initializing bucket resampler.
/tcenas/home/andream/anaconda3/envs/devenv/lib/python3.11/site-packages/pyproj/crs/crs.py:1293: UserWarning: You will likely lose important projection information when converting to a PROJ string from another format. See: https://proj.org/faq.html#what-is-the-best-format-for-describing-coordinate-reference-systems
  proj = self._crs.to_proj4(version=version)
[INFO: 2024-05-22 13:32:11 : pyresample.bucket] Determine bucket resampling indices
[DEBUG: 2024-05-22 13:32:11 : satpy.resample] Resampling DataID(name='flash_accumulation', modifiers=())
Traceback (most recent call last):
  File "/tcenas/proj/optcalimg/andream/pycharm_install/pycharm-2022.3.2/plugins/python/helpers/pydev/pydevd.py", line 1496, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/proj/optcalimg/andream/pycharm_install/pycharm-2022.3.2/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/tcenas/home/andream/PycharmProjects/dev_src/dev_src/li_data/plot_li_data.py", line 31, in <module>
    scn_r = scn.resample('mtg_fci_fdss_2km', resampler='bucket_sum')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 977, in resample
    self._resampled_scene(new_scn, destination, resampler=resampler,
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 893, in _resampled_scene
    res = resample_dataset(dataset, destination_area, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/resample.py", line 1068, in resample_dataset
    new_data = resample(source_area, dataset, destination_area, fill_value=fill_value, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/resample.py", line 1031, in resample
    res = resampler_instance.resample(data, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/resample.py", line 815, in resample
    result = self.compute(data_arr, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/resample.py", line 921, in compute
    res = self.resampler.get_sum(data, skipna=skipna, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BucketResampler.get_sum() got an unexpected keyword argument 'fill_value'

Additional Information
There are two solutions:

  1. we handle this in satpy and make sure not to pass the fill_value argument
  2. we handle this in pyresample and add support for fill_value, as already done for the other bucket resamplers.

I would likely go for the second option as it is a useful feature for pyresample and keeps a consistent interface in satpy.

@ameraner ameraner changed the title bucket_sum resampler fails due to fill_value passing bucket_sum resampler fails due to unexpected fill_value kwarg May 22, 2024
@ameraner ameraner self-assigned this Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant