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

String coordinates in netcdf datasets #260

Closed
corentincarton opened this issue Nov 14, 2023 · 4 comments · Fixed by #285
Closed

String coordinates in netcdf datasets #260

corentincarton opened this issue Nov 14, 2023 · 4 comments · Fixed by #285
Assignees

Comments

@corentincarton
Copy link
Contributor

def as_level(self, level):

I'm trying to read a netcdf dataset with string coordinates. The netcdf field is a list of points, each point has an ID (for instance G0001) and a time series, so two dimensions: station and time.
I get the following error when trying to read with earthkit:

File /etc/ecmwf/nfs/dh1_home_a/macw/git/test/hat/venv/hat/lib/python3.10/site-packages/earthkit/data/readers/netcdf.py:37, in as_level(self, level)
     36 def as_level(self, level):
---> 37     n = float(level)
     38     if int(n) == n:
     39         return int(n)

ValueError: could not convert string to float: 'G0001'

Do we really need to force a casting to float for the not-recognised dimensions?

@sandorkertesz
Copy link
Collaborator

@corentincarton, thank you for reporting this issue. The netcdf parser should not crash like that so it has to be fixed. Please can you make the data file available?

As for the data, I have to admit I am not sure if we need to treat it as a field/fieldset.

@corentincarton
Copy link
Contributor Author

Hi @sandorkertesz, sorry I should have added a small code to reproduce the error. Here it is:

import xarray as xr
ds = xr.DataArray([[1,2,3], [4,5,6]], coords={'ids': ["Index1", "Index2" ], 'x':[1,2,3]})
ds.to_netcdf("test.nc")
earthkit.data.from_source("file", "test.nc")

Not sure about the field or fieldset... something we need to discuss indeed.

@sandorkertesz
Copy link
Collaborator

Hi @corentincarton, the string coordinate issue can be fixed. However, at the moment when we create a field/fieldlist out of netcdf we assume it has a pair of horizontal coordinates (lat/lon or x/y). Without this only a NetCDFReader is created not a FieldList.
I will fix the string coordinate problem within this issue and open another one to discuss the netcdf field/fieldlist problem.

@corentincarton
Copy link
Contributor Author

Thanks @sandorkertesz !

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

Successfully merging a pull request may close this issue.

2 participants