Closed observingClouds closed 1 week ago
A PR would be welcome. A companion PR to cf-xarray would also be appreciated :)
@observingClouds It seems, that there are variables (str, dict, list) and coordinate variables (list) missing from those files. At least my cf-checker complains here, but good chance I'm missing something.
Oh yes @kmuehlbauer, I have simplified these example datasets to reduce the code section. They might no longer be CF-conform. Adding the missing variables and coordinates will not affect the decoding of the grid_mapping
attribute in mind. Sry for the confusion.
@observingClouds No worries. At least the UserWarning's are emitted when decoding the grid_mapping
. Anyway, this whole block might need a refactoring.
@kmuehlbauer, I just updated my MVCE to be cf compliant (except of a missing CF-convention attribute). The error remains the same.
@observingClouds Not sure if you're already working on a PR. I gave it a try in #9765.
This should now work for the two additional grid_mapping
layouts. Would be great if you could test this against your workflows.
I've also added some todos for testing things, if you have any suggestions on that, please let me know.
What happened?
Reading of CF-conform projection information and converting it automatically to coordinates with the
decode_coords='all'
argument ofxr.open_dataset()
failed for certain dataset.What did you expect to happen?
To do the detection of coordinates, xarray relies on the
grid_mapping
attribute that is set per variable. The CF-conventions allow for various differentgrid_mapping
formats:I expect that all formats are supported.
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
The issue seems to be that currently CF attributes can either be a string/list or a key-value pair depending whether the cf-attribute is listed in
CF_RELATED_DATA
or also listed inCF_RELATED_DATA_NEEDS_PARSING
.https://github.com/pydata/xarray/blob/main/xarray/conventions.py#L476-L480
grid_mapping
is currently only part ofCF_RELATED_DATA
, but adding it toCF_RELATED_DATA_NEEDS_PARSING
as well would cause the now working case to fail.Environment