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

Implement RaggedArray.from_xarray() #44

Closed
milancurcic opened this issue Oct 21, 2022 · 0 comments · Fixed by #51
Closed

Implement RaggedArray.from_xarray() #44

milancurcic opened this issue Oct 21, 2022 · 0 comments · Fixed by #51
Assignees
Labels
enhancement New feature or request

Comments

@milancurcic
Copy link
Member

As discussed with @selipot on 10/20, it's in scope for clouddrift to allow getting a RaggedArray instance from an xarray.Dataset.

RaggedArray.from_netcdf() already does this internally, i.e.:

with xr.open_dataset(filename) as ds:
nb_traj = ds.dims["traj"]
nb_obs = ds.dims["obs"]
attrs_global = ds.attrs
for var in ds.coords.keys():
coords[var] = ds[var].data
attrs_variables[var] = ds[var].attrs
for var in ds.data_vars.keys():
if len(ds[var]) == nb_traj:
metadata[var] = ds[var].data
elif len(ds[var]) == nb_obs:
data[var] = ds[var].data
else:
print(
f"Error: variable '{var}' has unknown dimension size of {len(ds[var])}, which is not traj={nb_traj} or obs={nb_obs}."
)
attrs_variables[var] = ds[var].attrs

Some assumptions are currently needed for the dimension names (currently assumed "traj" and "obs"). The method should allow the user to specify dimension names to use, in absence of an established convention.

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

Successfully merging a pull request may close this issue.

1 participant