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

FCI reader fails to load composites due to metadata issues #1215

Closed
ameraner opened this issue May 25, 2020 · 4 comments · Fixed by #1216
Closed

FCI reader fails to load composites due to metadata issues #1215

ameraner opened this issue May 25, 2020 · 4 comments · Fixed by #1216

Comments

@ameraner
Copy link
Member

Describe the bug
The FCI FDHSI reader fails to load a composite.

To Reproduce

sc = Scene(["/path_to_your_testdata/20130804_RC72/W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--L2P-NC4E_C_EUMT_20130804115845_GTT_DEV_20130804115330_20130804115345_N__C_0072_0035.nc"], reader="fci_l1c_fdhsi")
sc.load(["ir_87"]) #success
sc.load(["fog"]) #fail

Expected behavior
Load both single datasets as well as composites successfully.

Actual results

  File "/tcenas/home/andream/PycharmProjects/dev_src/dev_src/fci_test_data/check_fci_test_data.py", line 43, in analyse_FCI
    scn.load(channel_list)
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 975, in load
    keepables = self.generate_composites()
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 888, in generate_composites
    return self._read_composites(nodes)
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 863, in _read_composites
    self._generate_composite(item, keepables)
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/scene.py", line 838, in _generate_composite
    **self.attrs)
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/composites/__init__.py", line 859, in __call__
    new_attrs = combine_metadata(*projectables)
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/dataset.py", line 107, in combine_metadata
    elif all(val == values[0] for val in values[1:]):
  File "/tcenas/home/andream/code/satpy_latest/satpy/satpy/dataset.py", line 107, in <genexpr>
    elif all(val == values[0] for val in values[1:]):
  File "/tcenas/home/andream/anaconda3/envs/trolldev_latest/lib/python3.7/site-packages/xarray/core/common.py", line 120, in __bool__
    return bool(self.values)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Environment Info:

  • Linux
  • 0.20.1.dev233+g836af09c
@gerritholl
Copy link
Collaborator

The ancillary_variables attribute contains List[xarray.DataArray] (filled with the contents of data variable names listed in the original attribute). Based on initial investigations, I suspect that Satpy's combine_metadata cannot handle composites that combine different inputs that each have such an attribute. The FCI reader can handle the single-channel composite ir108_3d fine:

sc = Scene(["/media/nas/x21308/2020_04_MTG_unofficial_Testdata/20130804_RC72/W_XX-EUMETSAT-Darmstadt,IMG+SAT,MTI1+FCI-1C-RRAD-FDHSI-FD--CHK-BODY--L2P-NC4E_C_EUMT_20130804115845_GTT_DEV_20130804115330_20130804115345_N__C_0072_0035.nc"], reader="fci_l1c_fdhsi")
sc.load(["ir108_3d"])

As far as I know, the only other readers providing ancillary_variables are nwcsaf-nc and nucaps, which are both for level-2 data, and their only "composites" do not combine multiple variables that each have their own ancillary_variables attribute.

@gerritholl
Copy link
Collaborator

This regression was almost certainly caused by #1177.

@gerritholl
Copy link
Collaborator

It appears that combine_metadata does have a branch for arrays, but doesn't enter this because the ancillary_variables are not ndarrays but xarray.DataArrays:

satpy/satpy/dataset.py

Lines 97 to 108 in 836c657

# combine all of the dictionaries
shared_info = {}
for k in shared_keys:
values = [nfo[k] for nfo in info_dicts]
any_arrays = any([isinstance(val, np.ndarray) for val in values])
if any_arrays:
if all(np.all(val == values[0]) for val in values[1:]):
shared_info[k] = values[0]
elif 'time' in k and isinstance(values[0], datetime) and average_times:
shared_info[k] = average_datetimes(values)
elif all(val == values[0] for val in values[1:]):
shared_info[k] = values[0]

It would seem that this check needs to be replaced by some check testing positive for anything that supports the array interface, whether it's ndarray, xarray.DataArray, dask.array, pandas.DataFrame, etc.

@gerritholl
Copy link
Collaborator

I'll make an attempt at a fix.

gerritholl added a commit to gerritholl/satpy that referenced this issue May 25, 2020
Added a regression test triggering the ValueError raised when trying to
read a FCI composite (see pytroll#1215).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants