import numpy as np
import dascore as dc
from dascore.core.source import ArraySource
from dascore.utils.downloader import fetch
patch = dc.read(fetch("example_dasdae_event_1.h5"))[0]
source = patch._source
# Slicing reads nothing and gives another source.
sub = source[10:20]
assert sub.shape[0] == 10 and sub.data_id != source.data_id
assert sub.load().shape == sub.shape
# A constant source generates its array instead of reading one.
constant = ArraySource.full((2, 3), np.nan)
assert np.isnan(constant.load()).all()ArraySource
ArraySource(
path: str = ““,
format: str =”“,
version: str =”“,
key: str =”“,
windows: tuple[tuple[int, int], …] = (),
shape: tuple[int, …] = (),
dtype: Any = None,
origin_id: str =”“,
extent: tuple[int, …] = (),
filled: bool = False,
value: Any = None,
)-> None
Where an array is stored, or the constant which fills it, and enough to load it without its patch.
Holds no data and opens nothing until load. A reader sets key; the I/O framework fills in the rest.
Parameters
| Parameter | Description |
|---|---|
| path | The resource holding the array. |
| format | The name of the FiberIO which reads the resource. |
| version | The version of that format. |
| key |
Which array in the resource: the logical patch of a multi-patch resource, or an absolute path (“/…”) to any stored array, such as a dense coordinate. |
| windows |
A half-open (start, stop) sample range for each axis.
|
| shape | The shape of the array the windows select. |
| dtype | The dtype of the loaded array. |
| origin_id |
The id of the whole array, which a window’s id builds on. The framework gives a patch’s data array the patch’s origin_id; acaller which knows better, such as a hash of the contents, gives that. Empty means “by location”: path, format, version and key. |
| extent |
The shape of the whole array, which says when the windows select all of it. |
| filled |
Whether the array is value throughout rather than stored. Its ownflag because a table cannot say so by the value: NaN stores as NULL. |
| value |
The constant of a filled array. Such a source has no path andreads nothing; see full.
|
Examples
Methods
| Name | Description |
|---|---|
| describe | Return a source for the whole of an array of this shape and dtype. |
| detach | Return the provenance alone, for an array this no longer loads. |
| load | Read and return the array. |
| narrow |
Return the source indexer selects, detached if not contiguous.
|
| to_dict |
Return a JSON-compatible dict which from_dict reads back.
|