Include metadata variables for (arrays of) structures in to_xarray#112
Conversation
More readable code, and less repetition: ```python # before self.ncmeta.get_dimensions(..., self.homogeneous_time) # after self.get_dimensions(...) ```
This allows reading back data in the following scenario:
```python
ids = imas.IDSFactory().core_profiles()
... # fill IDS
xrds = imas.util.to_xarray(ids)
xrds.to_netcdf("data.nc", group="core_profiles/0")
with imas.DBEntry("data.nc", "r") as entry:
ids2 = entry.get("core_profiles")
```
N.B. `to_xarray()` doesn't include metadata for inhomogeneously sized arrays of structures, so the two IDSs in above example could be different.
|
N.B. I want to further close the gap between writing an IDS to a netCDF file (with DBEntry.put) and the xarray route. Marking this PR as draft until then. |
- Centralize attribute metadata logic - Include :shape arrays in imas.util.to_xarray - Test that netCDF files written with xarray can be read as DBEntry
|
@prasad-sawantdesai @olivhoenen I've updated the logic so that:
Can you please review the PR? Thanks! |
|
Works nicely, thanks @maarten-ic ! somewhere in the documentation (maybe after the section on converting directly IDS to xarray)? |
Thanks for the suggestion! Please check if the documentation is clear like this: https://imas-python--112.org.readthedocs.build/en/112/netcdf.html#store-xarray-datasets-in-imas-compatible-netcdf-file |
This allows reading back data in the following scenario: