import dascore as dc
patch = dc.get_example_patch()
# Replace the data, keeping the coordinates and attrs.
doubled = patch.replace(data=patch.data * 2)
# Replace every coordinate; ones not named are dropped.
bare = patch.replace(coords={x: patch.get_coord(x) for x in patch.dims})update
update(
self: Patch ,
data: ndarray | None = None,
coords: collections.abc.Mapping[collections.abc.Mapping[str, Any], CoordManager, None] = None,
dims: collections.abc.Sequence[collections.abc.Sequence[str], None] = None,
attrs: collections.abc.Mapping | dascore.core.attrs.PatchAttrs | None[Mapping, PatchAttrs, None] = None,
dtype: Any = None,
source: dascore.core.source.ArraySource | None[ArraySource, None] = None,
)-> ‘PatchType’
Return a copy of the Patch with replaced data, coords, dims, or attrs.
This rebuilds the patch wholesale: replace, update and new are the same method. A coords mapping becomes the whole coordinate set, so coordinates it does not name are dropped; use update_coords to change some coordinates and keep the rest.
The kind is preserved: a patch gives back a patch, and a PatchMeta gives back metadata. Use to_patch to give metadata data.
Parameters
| Parameter | Description |
|---|---|
| data |
An array-like containing data, an xarray DataArray object, or a Patch. Metadata holds none, so giving it data here is an error. |
| coords |
The coordinates, or dimensional labels for the data. These can be passed in three forms: {coord_name: data} {coord_name: ((dimensions,), data)} {coord_name: (dimensions, data)} |
| dims |
A sequence of dimension strings. The first entry corresponds to the first axis of data, the second to the second dimension, and so on. |
| attrs | Optional attributes (non-coordinate metadata) passed as a dict. |
| dtype |
The dtype of the data. Metadata, which holds none, takes the one it is given; a patch checks its data against it. |
| source | Internal I/O source metadata. If omitted, retain the current source. |