patch_to_xarray

function of dascore.xarray.patch source

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 through
dascore.xarray.index.CoordIndex, which computes labels on demand from
the 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.
Note

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. xarray aligns a lazy index only with lazy indexes: combining a lazy result with an array whose index is materialized, or reindexing it to new labels, raises an AlignmentError. Materialized labels, the default, cost 8 bytes a sample along each dimension, which beside a patch’s data is little.

Examples

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")