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

🚀[FEA]: Save NetCDF4 timedelta units compatible with xarray #181

Open
swbg opened this issue Jan 15, 2025 · 0 comments
Open

🚀[FEA]: Save NetCDF4 timedelta units compatible with xarray #181

swbg opened this issue Jan 15, 2025 · 0 comments
Labels
? - Needs Triage Need team to review and classify enhancement New feature or request

Comments

@swbg
Copy link
Contributor

swbg commented Jan 15, 2025

Is this a new feature, an improvement, or a change to existing functionality?

Improvement

How would you describe the priority of this feature request

Medium

Please provide a clear description of problem you would like to solve.

The NetCDF4 IO backend saves timedelta units as "h", "s", etc., while xarray only automatically decodes units "hours", "seconds", etc. Both versions seem to be acceptable according to CF conventions but it would be convenient to use xarray-style units

See here, where units are set according to numpy convention: https://github.com/NVIDIA/earth2studio/blob/main/earth2studio/io/netcdf4.py#L135
See, e.g., here, where xarray docs state they are using long-form units: (at the bottom, decode_timedelta) https://docs.xarray.dev/en/stable/generated/xarray.decode_cf.html
See here, in the xarray code: https://github.com/pydata/xarray/blob/main/xarray/coding/times.py#L80

Current workaround:

ds = xr.open_dataset("./output.nc", engine="netcdf4")  # some forecasting output
# lead_time has dtype int64
ds.lead_time.attrs["units"] = "hours"  # instead of "h"
ds = xr.decode_cf(ds)
# lead_time has dytpe timedelta64
@swbg swbg added ? - Needs Triage Need team to review and classify enhancement New feature or request labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
? - Needs Triage Need team to review and classify enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant