Read data
extract_h5_data(path, keys=None, schema=False)
Extract data at the given keys from an HDF5 file. If no keys are given (None) returns the data field of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
path to the HDF5 file or a folder in which is contained a data.ddh5 file |
required |
keys
|
None or List
|
list of keys to extract from file['data'], by default None |
None
|
Returns:
Type | Description |
---|---|
Dict or Tuple[ndarray, ...]
|
The full data dictionary if keys = None. The tuple with the requested keys otherwise. |
Example
Extract the data object from the dataset:
>>> data = extract_h5_data(path)
Extracting only 'amp' and 'phase' from the dataset:
>>> amp, phase = extract_h5_data(path, ['amp', 'phase'])
Extracting only 'phase':
>>> phase, = extract_h5_data(path, ['phase'])
Source code in sqil_core/utils/_read.py
extract_mapped_data(path)
Loads measurement data from an HDF5 file and maps it into x_data, y_data and sweeps. The map and the database schema on which it relies are also returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str or Path
|
Path to the HDF5 file containing experimental data and schema definitions. |
required |
Returns:
Name | Type | Description |
---|---|---|
x_data |
ndarray
|
Array of x-axis values extracted according to the schema. |
y_data |
ndarray
|
Array of measured data values (y-axis). |
sweeps |
list[ndarray]
|
List of arrays for any additional swept parameters defined in the schema. |
datadict_map |
dict
|
Mapping of keys used for |
schema |
dict
|
The schema used to interpret the data structure and field roles. |
Notes
- This function expects the file to contain a top-level "schema" key that defines the role of each dataset (e.g., "data", "x-axis", "axis").
- Uses
extract_h5_data
andmap_data_dict
internally for loading and interpretation.
Examples:
Source code in sqil_core/utils/_read.py
map_data_dict(data_dict)
Maps experimental data to standardized arrays using a provided schema.
This function interprets the structure of a measurement data dictionary (obtained using extract_h5_data) by extracting relevant data fields according to roles specified in the database schema. It returns the x-axis values, y-axis data, any additional sweep parameters, and a mapping of keys used for each role.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dict
|
dict
|
Dictionary containing measurement data and an associated 'schema' key that defines the role of each field (e.g., "x-axis", "data", "axis"). |
required |
Returns:
Name | Type | Description |
---|---|---|
x_data |
ndarray
|
Array containing the x-axis values. |
y_data |
ndarray
|
Array containing the y-axis (measured) data. |
sweeps |
list[ndarray]
|
List of additional swept parameter arrays (if any). |
key_map |
dict
|
Dictionary with keys |
Notes
- If the schema is missing, the function prints a warning and returns empty arrays.
- Each item in the schema must be a dictionary with a
"role"
key.
Examples:
>>> x, y, sweeps, mapping = map_data_dict(experiment_data)
>>> print(f"x-axis data from key: {mapping['x_data']}")
Source code in sqil_core/utils/_read.py
read_json(path)
read_qpu(dir_path, filename)
Reads QPU file stored in dir_path/filename using laboneq serializers.