Skip to content

Include metadata variables for (arrays of) structures in to_xarray#112

Open
maarten-ic wants to merge 2 commits intoiterorganization:developfrom
maarten-ic:feature/to-xarray-export-structure-metadata
Open

Include metadata variables for (arrays of) structures in to_xarray#112
maarten-ic wants to merge 2 commits intoiterorganization:developfrom
maarten-ic:feature/to-xarray-export-structure-metadata

Conversation

@maarten-ic
Copy link
Collaborator

This allows reading back data in the following scenario:

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.

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.
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 this pull request may close these issues.

1 participant