-
Notifications
You must be signed in to change notification settings - Fork 4
Load as dataset and use name in data_vars #56
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,21 @@ def load_netcdf_dataarray( | |
band_dim_name: str = "bands", | ||
) -> xarray.DataArray: | ||
"""Load a data cube from a NetCDF file as a xarray DataArray""" | ||
|
||
# TODO: avoid the try-except, and just work from `open_dataset`? | ||
try: | ||
# TODO: avoid the try-except, and just work from `open_dataset`? | ||
data = xarray.open_dataarray(path) | ||
except ValueError: | ||
data = xarray.open_dataset(path, decode_coords="all") | ||
# VITO/CDSE write a Dataset even if there are no bands, with a default name 'var' | ||
if len(data.data_vars) == 1 and [v for v in data.data_vars] == ["var"]: | ||
data = data["var"] | ||
# EODC writes a Dataset even if there are no bands, with a default name 'name' | ||
elif len(data.data_vars) == 1 and [v for v in data.data_vars] == ["name"]: | ||
data = data["name"] | ||
else: | ||
data = data.to_dataarray(dim=band_dim_name) | ||
data = data.to_array(dim=band_dim_name) | ||
except ValueError: | ||
data = xarray.open_dataarray(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you switch to trying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not implement the initial There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these try-except constructs were originally introduced by @clausmichele I think, e.g. like in c8b6f51 so maybe he can comment if the try-except can be dropped if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, on our side we still use DataArray most of the times (which is the internal format used by openeo-processes-dask), that's why I was checking that. |
||
|
||
return data | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.