zea.data.file¶
zea H5 file functionality.
Functions
|
Asserts key is in a h5py.File. |
|
Loads a zea data files (h5py file). |
Load dict from contents of group |
|
|
Reads the hdf5 file at the given path and validates its structure. |
Classes
|
h5py.File in zea format. |
- class zea.data.file.File(name, *args, **kwargs)[source]¶
Bases:
File
h5py.File in zea format.
- static check_data(data, key)[source]¶
Check the data for a given key. For example, will check if the shape matches the data type (such as raw_data, …)
- copy_key(key, dst)[source]¶
Copy a specific key to another file.
Will always copy the attributes and the scan data if it exists. Will warn if the key is not in this file or if the key already exists in the destination file.
- Parameters:
key (str) – The key to copy.
dst (File) – The destination file to copy the key to.
- property description¶
Reads the description from the data file and returns it.
- property event_keys¶
Return all events in the file.
- get_parameters(event=None)[source]¶
Returns a dictionary of parameters to initialize a scan object that comes with the file (stored inside datafile).
If there are no scan parameters in the hdf5 file, returns an empty dictionary.
- Parameters:
event (int, optional) –
Event number. When specified, an event structure is expected as follows:
event_0 / scan event_1 / scan ...
Defaults to None. In that case no event structure is expected.
- Returns:
The scan parameters.
- Return type:
dict
- get_probe_parameters(event=None)[source]¶
Returns a dictionary of probe parameters to initialize a probe object that comes with the file (stored inside datafile).
- Returns:
The probe parameters.
- Return type:
dict
- get_scan_parameters(event=None)[source]¶
Returns a dictionary of default parameters to initialize a scan object that works with the file.
- Returns:
- The default parameters (the keys are identical to the
__init__ parameters of the Scan class).
- Return type:
dict
- classmethod get_shape(path, key)[source]¶
Get the shape of a key in a file.
- Parameters:
path (str) – The path to the file.
key (str) – The key to get the shape of.
- Returns:
The shape of the key.
- Return type:
tuple
- property has_events¶
Check if the file has events.
- load_data(data_type, indices='all')[source]¶
Load data from the file.
- Parameters:
data_type (str) – The type of data to load. Options are ‘raw_data’, ‘aligned_data’, ‘beamformed_data’, ‘envelope_data’, ‘image’ and ‘image_sc’.
indices (str, int, list, optional) – The indices to load. Defaults to “all” in which case all frames are loaded. If an int is provided, it will be used as a single index. If a list is provided, it will be used as a list of indices.
- load_transmits(key, selected_transmits)[source]¶
Load raw_data or aligned_data for a given list of transmits. :param data_type: The type of data to load. Options are ‘raw_data’ and ‘aligned_data’. :type data_type: str :type selected_transmits: :param selected_transmits: The transmits to load. :type selected_transmits: list, np.ndarray
- property n_frames¶
Return number of frames in a file.
- property name¶
Return the name of the file.
- property path¶
Return the path of the file.
- probe(event=None)[source]¶
Returns a Probe object initialized with the parameters from the file.
- Parameters:
event (int, optional) –
Event number. When specified, an event structure is expected as follows:
event_0 / scan event_1 / scan ...
Defaults to None. In that case, no event structure is expected.
- Returns:
The probe object.
- Return type:
- property probe_name¶
Reads the probe name from the data file and returns it.
- recursively_load_dict_contents_from_group(path, squeeze=False)[source]¶
Load dict from contents of group
Values inside the group are converted to numpy arrays or primitive types (int, float, str). Single element arrays are converted to the corresponding primitive type (if squeeze=True)
- Parameters:
path (str) – path to group
squeeze (bool, optional) – squeeze arrays with single element. Defaults to False.
- Returns:
dictionary with contents of group
- Return type:
dict
- scan(event=None, **kwargs)[source]¶
Returns a Scan object initialized with the parameters from the file.
- Parameters:
event (int, optional) –
Event number. When specified, an event structure is expected as follows:
event_0 / scan event_1 / scan ...
Defaults to None. In that case no event structure is expected.
**kwargs – Additional keyword arguments to pass to the Scan object. These will override the parameters from the file if they are present in the file.
- Returns:
The scan object.
- Return type:
- property stem¶
Return the stem of the file.
- zea.data.file.load_file(path, data_type='raw_data', indices='all', scan_kwargs=None)[source]¶
Loads a zea data files (h5py file).
Returns the data together with a scan object containing the parameters of the acquisition and a probe object containing the parameters of the probe.
Additionally, it can load a specific subset of frames / transmits.
# TODO: add support for event
- 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 (str, int, list, optional) – The indices to load. Defaults to “all” in which case all frames are loaded. If an int is provided, it will be used as a single index. If a list is provided, it will be used as a list of indices.
scan_kwargs (Config, dict, optional) – Additional keyword arguments to pass to the Scan object. These will override the parameters from the file if they are present in the file. Defaults to None.
- Returns:
The raw data of shape (n_frames, n_tx, n_ax, n_el, n_ch). (Scan): A scan object containing the parameters of the acquisition. (Probe): A probe object containing the parameters of the probe.
- Return type:
(np.ndarray)
- zea.data.file.recursively_load_dict_contents_from_group(h5file, path, squeeze=False)[source]¶
Load dict from contents of group
Values inside the group are converted to numpy arrays or primitive types (int, float, str). Single element arrays are converted to the corresponding primitive type (if squeeze=True)
- Parameters:
h5file (h5py._hl.files.File) – h5py file object
path (str) – path to group
squeeze (bool, optional) – squeeze arrays with single element. Defaults to False.
- Returns:
dictionary with contents of group
- Return type:
dict