Closed Tjalling-dejong closed 5 months ago
I think the problem is that you omitted the .ugrid
accessor on the to_netcdf
call.
If you change it to this:
data.ugrid.to_netcdf("test.nc")
It'll work as expected.
Without the ugrid accessor it'll just call the regular xarray method which is topology unaware.
(With a bit of luck, the ordinary method might also work once xarray has implemented explicit indexes.)
Thanks Huite, that worked. Is there a way that the crs can be preserved when writing to netcdf?
Not at the moment :(
These issues are related:
The first one is most relevant. I haven't found the time to implement this. PRs are -- obviously! -- welcome.
Thanks again, I'm closing this issue since the original issue is not an issue anymore.
For the mesh component of HydroMT I was writing some tests involving writing and reading UgridDatasets. HydroMT converts UgridDatasets to xarray.Datasets before writing in order to preserve crs. I wanted to check if XUgrid preserves crs when writing to file. This resulted in an unexpected error. I expected the crs to be None but got an UgridDataset with 0 grids.
Reproducible example:
This will give a TypeError because grids is 0.