Skip to content

Commit dffeac7

Browse files
maarten-icolivhoenen
authored andcommitted
Additional documentation and example for to_xarray
1 parent ce313de commit dffeac7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

imas/util.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,22 @@ def to_xarray(ids: IDSToplevel, *paths: str) -> Any:
543543
Returns:
544544
An ``xarray.Dataset`` object.
545545
546+
Notes:
547+
- Lazy loaded IDSs are not supported for full IDS conversion
548+
(``imas.util.to_xarray(ids)`` will raise an exception for lazy loaded IDSs).
549+
This function can work with lazy loaded IDSs when paths are explicitly
550+
provided: this might take a while because it will load all data for the
551+
provided paths and their coordinates.
552+
- This function does not accept wildcards for the paths. However, it is possible
553+
to combine this method with :py:func:`imas.util.find_paths`, see the Examples
554+
below.
555+
- This function may return an empty dataset in the following cases:
556+
557+
- The provided IDS does not contain any data.
558+
- The IDS does not contain any data for the provided paths.
559+
- The provided paths do not point to data nodes, but to (arrays of)
560+
structures.
561+
546562
Examples:
547563
.. code-block:: python
548564
@@ -563,6 +579,12 @@ def to_xarray(ids: IDSToplevel, *paths: str) -> Any:
563579
"profiles_1d.electrons.temperature",
564580
)
565581
582+
# Combine with imas.util.find_paths to include all paths containing
583+
# "profiles_1d" in the xarray conversion:
584+
profiles_1d_paths = imas.util.find_paths(ids, "profiles_1d")
585+
assert len(profiles_1d_paths) > 0
586+
ds = imas.util.to_xarray(ids, *profiles_1d_paths)
587+
566588
See Also:
567589
https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html
568590
"""

0 commit comments

Comments
 (0)