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

ragged.regular_to_ragged to accept xarray.dataarray or xarray.dataset input #369

Open
selipot opened this issue Feb 4, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@selipot
Copy link
Member

selipot commented Feb 4, 2024

Right now ragged.regular_to_ragged accepts only numpy array. I think we should expand that function or write a new function that would automatically convert a regular data xarray.dataarray/dataset to a ragged xarray.dataaray/dataset.

@selipot selipot added the enhancement New feature or request label Feb 4, 2024
@selipot
Copy link
Member Author

selipot commented Feb 4, 2024

Such a function would do something like the following automatically with a number of checks. Assuming the regular xarray input dataset is ds_in with dimensions traj and dimension coordinate obs. And after having applied a mask to all the variables with dimensions (trajectory,obs).

n_traj = ds_in.sizes["traj"]
n_obs = ds_in["lat"].count().values

# Initialize the Dataset
ds_out = xr.Dataset(
    coords={
        'id': ('traj', ds2["id"].data),
        'obs': ('obs', range(n_obs))
    }
)
for var in ds_in.data_vars:
    dum, rowsize = regular_to_ragged(ds2[var].to_numpy(), fill_value=np.nan)
    ds_out[var] = xr.DataArray(dum, dims=("obs"), name=var)
ds_out["rowsize"] = xr.DataArray(rowsize, dims=("traj"), name="rowsize")

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

No branches or pull requests

1 participant