zea.data.file_operationsΒΆ
This module provides some utilities to edit zea data files, either individually or in bulk.
Each operation is available both as a Python function and as a zea data command line
subcommand. See the CLI documentation for the available operations and their
command-line usage.
Functions
|
Compounds frames in a raw data file by averaging them. |
|
Compounds transmits in a raw data file by averaging them. |
|
Copies zea files to a new location using |
|
extracts frames and transmits in a raw data file. |
|
Parse command line arguments and run the requested data operation. |
|
Resaves a zea data file to a new location. |
|
Index a spec along named SCHEMA dimensions, wherever they occur. |
|
Sums multiple raw data files and saves the result to a new file. |
|
Prints a summary of a zea data file to the console. |
- zea.data.file_operations.compound_frames(input_path, output_path, overwrite=False)[source]ΒΆ
Compounds frames in a raw data file by averaging them.
- Parameters:
input_path (
str|Path) β Path to the input raw data file, or a folder of files. Also accepts anhf://path (file or folder).output_path (
str|Path) β Path to the output file (or folder) where the compounded data will be saved.overwrite (bool, optional) β Whether to overwrite the output file if it exists. Defaults to False.
- zea.data.file_operations.compound_transmits(input_path, output_path, overwrite=False)[source]ΒΆ
Compounds transmits in a raw data file by averaging them.
Note
This function assumes that all transmits are identical. If this is not the case the function will result in incorrect scan parameters.
- Parameters:
input_path (
str|Path) β Path to the input raw data file, or a folder of files. Also accepts anhf://path (file or folder).output_path (
str|Path) β Path to the output file (or folder) where the compounded data will be saved.overwrite (bool, optional) β Whether to overwrite the output file if it exists. Defaults to False.
- zea.data.file_operations.copy(src, dst, key, mode=None)[source]ΒΆ
Copies zea files to a new location using
zea.Dataset.copy().- Parameters:
src (
str|Path) β Source path. Can be a single file, a list of files, a folder, or anhf://path.dst (
str|Path) β Destination folder path.key (
str) β Key to access in the HDF5 files. Use"all"or"*"to copy everything.mode (
str|None) β HDF5 file mode for the destination files. Defaults to None, which letszea.Dataset.copy()auto-select the mode ("a"for a single key,"w"whenkeyis"all"/"*").
- zea.data.file_operations.extract_frames_transmits(input_path, output_path, frame_indices=slice(None, None, None), transmit_indices=slice(None, None, None), overwrite=False, **kwargs)[source]ΒΆ
extracts frames and transmits in a raw data file.
Every field carrying an
n_framesorn_txdimension is sliced, as determined by the spec schema (seeslice_spec_dims()), so scan parameters, annotations and metrics stay in sync with the extracted data.- Parameters:
input_path (
str|Path) β Path to the input raw data file, or a folder of files. Also accepts anhf://path (file or folder).output_path (
str|Path) β Path to the output file (or folder) where the extracted data will be saved.frame_indices (list, array-like, or slice) β Indices of the frames to keep.
transmit_indices (list, array-like, or slice) β Indices of the transmits to keep.
overwrite (bool, optional) β Whether to overwrite the output file if it exists. Defaults to False.
**kwargs β Passed to
zea.data.spec.FileSpec.save()(e.g.compression,chunk_axes).
- zea.data.file_operations.main()[source]ΒΆ
Parse command line arguments and run the requested data operation.
Entry point for
python -m zea.data. This is equivalent tozea data.
- zea.data.file_operations.resave(input_path, output_path, overwrite=False, **kwargs)[source]ΒΆ
Resaves a zea data file to a new location.
- Parameters:
input_path (
str|Path) β Path to the input zea data file, or a folder of files. Also accepts anhf://path (file or folder).output_path (
str|Path) β Path to the output file (or folder) where the data will be saved.overwrite (bool, optional) β Whether to overwrite the output file if it exists. Defaults to False.
chunk_axes (tuple, optional) β Dimension names to chunk with size 1. Defaults to
("n_frames",)β one full frame per chunk β so partial and streamed reads fetch only the requested frames; other axes stay at full extent. UseNone/()for contiguous storage. Seezea.data.spec.Spec._resolve_chunks().
- zea.data.file_operations.slice_spec_dims(spec, **dim_indices)[source]ΒΆ
Index a spec along named SCHEMA dimensions, wherever they occur.
Every field whose
SCHEMAshape mentions one of the given dimension names is indexed along that dimension, throughout the whole spec tree. So slicingn_framesalso selects the matching entries oftimestamps,annotationsandmetrics, and slicingn_txalso selects the matchingt0_delays,tx_apodizationsandtime_to_next_transmitβ without this function needing to know those fields exist.Fields that do not carry the dimension are passed through untouched, and arrays are shared with
specrather than copied where possible.Note
customelements are opaque to the schema and are never sliced.- Parameters:
spec (
TypeVar(SpecT, bound=Spec)) β The spec to slice. Not modified.**dim_indices β Index per named dimension, e.g.
n_frames=[0, 2],n_tx=slice(0, 4). Values may be ints, lists, arrays, boolean masks or slices, and unlike a single fancy-index expression, several dimensions may be given as lists at the same time.
- Returns:
A validated copy of
specwith the requested dimensions indexed.- Return type:
TypeVar(SpecT, bound=Spec)
Example
sliced = slice_spec_dims(file_spec, n_frames=[0, 2], n_tx=slice(0, 4))
- zea.data.file_operations.sum_data(input_paths, output_path, overwrite=False)[source]ΒΆ
Sums multiple raw data files and saves the result to a new file.
For images, this will actually average the images. If the images are uint8, it will average directly. If the images are float32, we assume they are in the log-domain and we will do the averaging in the linear domain.
- Parameters:
input_paths (
Sequence[str|Path]) β List of paths to the input raw data files. Each path may be a single file, a folder, or anhf://path; folders (local orhf://) are expanded into all zea files they contain (usingzea.Dataset).output_path (
str|Path) β Path to the output file where the summed data will be saved.overwrite (bool, optional) β Whether to overwrite the output file if it exists. Defaults to False.