zea.data.file¶
zea data file (HDF5).
Functions
|
Asserts key is in a h5py.File. |
|
Recursively load the contents of an HDF5 group into a plain dict. |
|
Loads a zea data files (h5py file). |
|
Loads a zea data files (h5py file). |
|
Validate the structure and data of a zea HDF5 file. |
Classes
|
h5py.File in zea format. |
|
A single acquisition track within a |
- class zea.data.file.Track(index, group, timestamps=None, label=None, probe=None)[source]¶
Bases:
objectA single acquisition track within a
File.Provides the same
.data,.scanand.load_parameters()interface asFilebut scoped to onetracks/track_Ngroup. Obtain instances throughFile.tracksrather than constructing this class directly.Example:
with File("multi_track.hdf5") as f: for track in f.tracks: raw = track.data.raw_data[:] parameters = track.load_parameters()
- property data: _GroupProxy¶
Lazy proxy for this track’s
datagroup.
- property label: str | None¶
Human-readable name for this track (e.g.
'focused'or'planewave').Returns
Nonefor single-track files or legacy files written without a label. UseFile.track_labelsto print all labels in acquisition order andFile.get_track()to retrieve a track by name.
- load_parameters(**overrides)[source]¶
Load this track’s parameters (merged probe + scan) as
Parameters.Each track shares the same probe but has its own scan, so the returned object has the same shape as
File.load_parameters()for a single-track file.- Parameters:
**overrides – Override any parameter.
- Returns:
Initialised parameters object for this track.
- Return type:
- property n_ax: int¶
Number of axial samples.
- property n_el: int¶
Number of elements.
- property n_frames: int¶
Number of frames.
- property n_tx: int¶
Number of transmit events.
- property scan: ScanSpec¶
Return the validated
ScanSpecfor this track.This is the bare scan group as a spec object. For a full, derivable parameter object (merged probe + scan) use
load_parameters().
- zea.data.file.load_dict_from_hdf5_group(group)[source]¶
Recursively load the contents of an HDF5 group into a plain dict.
Datasets are returned as numpy arrays or scalars; nested groups are converted recursively. String datasets are decoded to
np.str_.- Parameters:
group (
Group) – An openh5py.Group(orh5py.File).- Returns:
Nested dictionary mirroring the group structure.
- Return type:
dict
- zea.data.file.load_file(path, data_type='raw_data', indices=None, scan_kwargs=None)[source]¶
Loads a zea data files (h5py file).
Returns the data together with a parameters object containing the parameters of the acquisition. Probe information is available via
parameters.to_probe_dict()orFile.probe.Additionally, it can load a specific subset of frames / transmits.
The indices parameter can be used to load a subset of the data. This can be
'all'orNoneto load all dataan
intto load a single framea
List[int]to load specific frames- a
Tuple[Union[list, slice, int], ...]to index multiple axes (i.e. frames and transmits). Note that indexing with lists of indices for multiple axes is not supported. In that case, try to define one of the axes with a slice for optimal performance. Alternatively, slice the data after loading.
- a
For more information on the indexing options, see indexing on ndarrays and fancy indexing in h5py.
- Parameters:
path (str, pathlike) – The path to the hdf5 file.
data_type (str, optional) – The type of data to load. Defaults to ‘raw_data’. Other options are ‘aligned_data’, ‘beamformed_data’, ‘envelope_data’, ‘image’ and ‘image_sc’.
indices (
Union[Tuple[Union[list,slice,int],...],List[int],int,None]) – The indices to load. Defaults to None in which case all frames are loaded.scan_kwargs (
dict) – Additional keyword arguments to pass toFile.load_parameters(). These will override the parameters from the file if they are present. Defaults to None.
- Returns:
The raw data of shape (n_frames, n_tx, n_ax, n_el, n_ch). (Parameters): A parameters object containing the parameters of the acquisition.
- Return type:
Tuple[ndarray,Parameters]
- zea.data.file.load_file_all_data_types(path, indices=None, scan_kwargs=None)[source]¶
Loads a zea data files (h5py file).
Returns all data types together with a parameters object containing the parameters of the acquisition. Probe information is available via
parameters.to_probe_dict()orFile.probe.Additionally, it can load a specific subset of frames / transmits.
The indices parameter can be used to load a subset of the data. This can be
'all'orNoneto load all dataan
intto load a single framea
List[int]to load specific frames- a
Tuple[Union[list, slice, int], ...]to index multiple axes (i.e. frames and transmits). Note that indexing with lists of indices for multiple axes is not supported. In that case, try to define one of the axes with a slice for optimal performance. Alternatively, slice the data after loading.
- a
For more information on the indexing options, see indexing on ndarrays and fancy indexing in h5py.
- Parameters:
path (str, pathlike) – The path to the hdf5 file.
indices (
Union[Tuple[Union[list,slice,int],...],List[int],int,None]) – The indices to load. Defaults to None in which case all frames are loaded.scan_kwargs (
dict) – Additional keyword arguments to pass toFile.load_parameters(). These will override the parameters from the file if they are present. Defaults to None.
- Returns:
A dictionary with all data types as keys and the corresponding data as values. (Parameters): A parameters object containing the parameters of the acquisition.
- Return type:
(dict)
- zea.data.file.validate_file(path=None, file=None)[source]¶
Validate the structure and data of a zea HDF5 file.
For files created with zea v0.1.0 and later this runs the full
FileSpecschema validation (dtypes, shapes, and dimension consistency). Legacy files (before zea v0.1.0) are detected by the presence of scalar datasetscan/n_frames; for those only a lightweight structuraldatagroup check is performed.Provide either path or file, but not both.
- Parameters:
- Returns:
{"status": "success"}on success.- Return type:
dict
- Raises:
AssertionError – If the file is missing the
datagroup.TypeError, ValueError – If spec validation fails on files created with zea v0.1.0 and later.