Array¶
- class escape.Array(data=None, index=None, step_lengths=None, parameter=None, name=None, source=None, grid_specs=None)[source]¶
Bases:
objectnd array data wrapper with optional scan metadata and grid support.
Arraystores raw measurement data together with an event index and optional scan grouping information. Whenstep_lengthsandparameterare provided, a lazily constructedscanproperty exposes grouped step selection and scan-level operations.- Args:
data: nd data array or callable returning data. index: Event identifiers aligned with the first dimension of
data. step_lengths: List of step sizes for each scan step. parameter: Scan parameter metadata for each step. name: Optional array name. source: Optional source metadata object. grid_specs: Optional metadata used to buildscan.grid.
- property T¶
- __init__(data=None, index=None, step_lengths=None, parameter=None, name=None, source=None, grid_specs=None)[source]¶
- categorize(other_array)[source]¶
Re-sort and re-group other_array to match this Array’s index ordering and scan-step boundaries.
The returned Array contains other_array’s data values at the pulse IDs that are common to both arrays, ordered and grouped exactly as self. This is the primary tool for applying a new grouping (obtained e.g. via
digitize()orget_index_array()) to another channel.- Parameters:
other_array (escape.Array) – The array to re-sort.
- Returns:
other_array restricted to the common pulse IDs and re-grouped according to self’s scan structure.
- Return type:
Notes
Equivalent to
escape.match_arrays(self, other_array)[1].Examples
>>> time_bins = sig.get_index_array(N_index_aggregation=1000) >>> i0_rebinned = time_bins.categorize(i0)
- compute(**kwargs)[source]¶
Evaluate the dask graph and return a new Array backed by a NumPy array.
No-op when the data is already a NumPy array (returns self with a message). All index and scan metadata are preserved.
- Parameters:
**kwargs – Forwarded to
dask.array.Array.compute().- Returns:
Same Array with NumPy data instead of a dask graph.
- Return type:
See also
escape.computeCompute several Arrays in one dask scheduler pass.
- correct_for_references(isref_bool, N_index_aggregation=None, operation=<built-in function truediv>)[source]¶
- property data¶
- property dtype¶
- get_index_array(N_index_aggregation=None)[source]¶
Return an Array whose data equals its own index (pulse IDs), optionally grouped into contiguous bins.
Without aggregation this is a simple 1-D Array where
data == index, useful as an “identity” sorter. With N_index_aggregation the pulse IDs are binned into groups of width N_index_aggregation index units (typically pulse IDs), creating a coarser time-ordered grouping.- Parameters:
N_index_aggregation (int, optional) – Width of each pulse-ID bin. If None no binning is applied.
- Returns:
1-D Array with
data == index(before any binning).- Return type:
Notes
The resulting Array can be used with
categorize()to apply the new grouping to any other channel:Examples
>>> # Group into bins of 1000 consecutive pulse IDs >>> time_bins = sig.get_index_array(N_index_aggregation=1000) >>> sig_rebinned = time_bins.categorize(sig) >>> i0_rebinned = time_bins.categorize(i0)
- property grid¶
- hist(cut_percentage=0, bins='auto', normalize_to=None, scanpar_name=None, plot_results=True, plot_axis=None)[source]¶
- property index¶
- map_index_blocks(foo, *args, drop_axis=None, new_axis=None, new_element_size=None, event_dim='same', **kwargs)[source]¶
Apply foo block-wise over the event axis using dask’s
map_blocks.The function
fooreceives a raw NumPy array (one dask chunk along the event axis) and returns a NumPy array. The result is assembled back into a lazy dask-backedArraywith the same index and scan metadata.This is the preferred way to apply arbitrary NumPy or SciPy functions (gain correction, thresholding, peak fitting, …) to large detector data without loading everything into memory.
- Parameters:
foo (callable) –
f(block, *args, **kwargs) -> ndarray. block has shape(n_events_in_chunk, *element_shape).*args – Extra positional arguments forwarded to
foo.drop_axis (int or list of int, optional) – Axes to remove from the output (forwarded to
dask.map_blocks).new_axis (int or list of int, optional) – New axes to add to the output.
new_element_size (list of int, optional) – Shape of each per-event element in the output (excluding the event axis). Required when
foochanges the per-event shape.**kwargs – Extra keyword arguments forwarded to
foo.
- Returns:
Lazy Array with the transformed data.
- Return type:
Examples
Threshold pixels below 4 keV to NaN:
def threshold(block, thr): out = block.copy() out[out < thr] = np.nan return out imgs_clean = imgs.map_index_blocks(threshold, 4.0)
Extract two scalars per event (change per-event shape):
posamp = tt_proj.map_index_blocks( lambda block: np.array([find_edge(row) for row in block]), new_element_size=(2,), dtype=float, )
Notes
Formerly called
map_event_blocksin older versions ofescape.
- property ndim¶
- property ndim_nonzero¶
- property scan¶
- property shape¶
- store(parent_h5py=None, name=None, unit=None, lock='auto', **kwargs)[source]¶
a way to store data, especially expensively computed data, into a new file.
- store_file(parent_h5py=None, name=None, unit=None, **kwargs)[source]¶
a way to store data, especially expensively computed data, into a new file.
- property tools¶