imas.util.to_xarray

imas.util.to_xarray(ids: IDSToplevel, *paths: str) Any

Convert an IDS to an xarray Dataset.

Parameters:
ids: IDSToplevel

An IDS toplevel element

*paths: str

Optional list of element paths to convert to xarray. The full IDS will be converted to an xarray Dataset if no paths are provided.

Paths must not contain indices, and may use a / or a . as separator. For example, "profiles_1d(itime)/electrons/density" is not allowed as path, use "profiles_1d/electrons/density" or profiles_1d.electrons.density" instead.

Coordinates to the quantities in the requested paths will also be included in the xarray Dataset.

Returns:

An xarray.Dataset object.

Notes

  • Lazy loaded IDSs are not supported for full IDS conversion (imas.util.to_xarray(ids) will raise an exception for lazy loaded IDSs). This function can work with lazy loaded IDSs when paths are explicitly provided: this might take a while because it will load all data for the provided paths and their coordinates.

  • This function does not accept wildcards for the paths. However, it is possible to combine this method with imas.util.find_paths(), see the Examples below.

  • This function may return an empty dataset in the following cases:

    • The provided IDS does not contain any data.

    • The IDS does not contain any data for the provided paths.

    • The provided paths do not point to data nodes, but to (arrays of) structures.

Examples

# Convert the whole IDS to an xarray Dataset
ds = imas.util.to_xarray(ids)

# Convert only some elements in the IDS (including their coordinates)
ds = imas.util.to_xarray(
    ids,
    "profiles_1d/electrons/density",
    "profiles_1d/electrons/temperature",
)

# Paths can be provided with "/" or "." as separator
ds = imas.util.to_xarray(
    ids,
    "profiles_1d.electrons.density",
    "profiles_1d.electrons.temperature",
)

# Combine with imas.util.find_paths to include all paths containing
# "profiles_1d" in the xarray conversion:
profiles_1d_paths = imas.util.find_paths(ids, "profiles_1d")
assert len(profiles_1d_paths) > 0
ds = imas.util.to_xarray(ids, *profiles_1d_paths)

Last update: 2026-01-28