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

Handling erroneous or xarray incompatible FieldSet netcdf metadata #1919

Open
VeckoTheGecko opened this issue Mar 6, 2025 · 1 comment
Open
Labels

Comments

@VeckoTheGecko
Copy link
Contributor

VeckoTheGecko commented Mar 6, 2025

We need to decide to what extent we want to support broken or xarray incompatible metadata in Parcels (e.g., for units).

I am of the mindset that we rely on the user to fix their metadata using xarray before passing it to Parcels (though we can help out with informative error messages).

For the meantime I am going to remove code along the lines of

def convert_xarray_time_units(ds, time):
"""Fixes DataArrays that have time.Unit instead of expected time.units"""
da = ds[time] if isinstance(ds, xr.Dataset) else ds
if "units" not in da.attrs and "Unit" in da.attrs:
da.attrs["units"] = da.attrs["Unit"]
da2 = xr.Dataset({time: da})
try:
da2 = xr.decode_cf(da2)
except ValueError:
raise RuntimeError(
"Xarray could not convert the calendar. If you're using from_netcdf, "
"try using the timestamps keyword in the construction of your Field. "
"See also the tutorial at https://docs.oceanparcels.org/en/latest/examples/tutorial_timestamps.html"
)
ds[time] = da2[time]

so that we can consolidate this later

@erikvansebille
Copy link
Member

Yep, agree! Let users make sure their array datasets are compatible. Maybe add tooling as a separate layer later on, but not within Parcels-Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Status: Backlog
Development

No branches or pull requests

2 participants