import dascore as dc
from dascore.xarray import patch_to_xarray
patch = dc.get_example_patch()
# Materialized labels, as a plain xarray index holds them.
array = patch_to_xarray(patch)
# Lazy labels; the patch's own coordinates come back exactly.
lazy = patch_to_xarray(patch, lazy_coords=True)
assert lazy.xindexes["time"].coordinate == patch.get_coord("time")patch_to_xarray
patch_to_xarray(
patch: Patch ,
lazy_coords: bool | collections.abc.Collection[bool, collections.abc.Collection[str]] = False,
)
Convert a patch to an xarray DataArray.
Parameters
| Parameter | Description |
|---|---|
| patch | The patch to convert. |
| lazy_coords |
Which dimension coordinates to serve throughdascore.xarray.index.CoordIndex, which computes labels on demand fromthe coordinate instead of storing them: True for every evenly sampled or segmented one, False (the default) for none, or their names, served whatever their kind (one holding its labels keeps them in the index). Other coordinates are materialized. |
A lazy coordinate is the patch’s own coordinate, so it converts back exactly, exact sampling grid included; a one-sample materialized coordinate cannot retain its step. Combining a lazy result with an array whose index is materialized raises an AlignmentError when the labels differ, and before xarray 2026.9 even when they agree; so does reindexing it to new labels. Materialized labels, the default, cost 8 bytes a sample along each dimension, which beside a patch’s data is little.
Units are strings, as the CF conventions state them: a coordinate’s under units, the data’s under both data_units and units.