h5py_helper_fn.py
is_float16_dtype(dt, *, include_subarray_base=False)
¶
Return True if dtype is a plain float16 (any endianness).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
dtype
|
Dtype to test. |
required |
include_subarray_base
|
bool
|
If True, treat subarray dtypes with base float16 as float16. If False (default), exclude subarray dtypes. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if dtype is float16 under the chosen policy; otherwise False. |
Notes
Excludes:
- Object/region references
- Variable-length (vlen) types
- Compound dtypes
- Subarray dtypes unless include_subarray_base=True
Source code in src/spyglass/utils/h5py_helper_fn.py
find_float16_datasets(file, *, include_dimension_scales=False, include_subarray_base=False)
¶
List absolute HDF5 paths of datasets stored as float16.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
File
|
Open HDF5 file handle. |
required |
include_dimension_scales
|
bool
|
If False (default), skip datasets that are HDF5 dimension scales (CLASS='DIMENSION_SCALE'). |
False
|
include_subarray_base
|
bool
|
If True, include subarray dtypes whose base is float16. |
False
|
Returns:
| Type | Description |
|---|---|
list of str
|
Absolute dataset paths with dtype float16 under the chosen policy. |
Source code in src/spyglass/utils/h5py_helper_fn.py
convert_dataset_type(file, dataset_path, target_dtype)
¶
Convert a dataset to a different dtype.
Operation is in-place for the nwb file. The dataset itself is deleted and recreated with the same name, data, and attributes, but with the new dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
File
|
Open HDF5 file handle with write access. |
required |
dataset_path
|
str
|
Absolute path of the dataset to convert. |
required |
target_dtype
|
str
|
Target dtype (e.g., 'float32', 'int16', etc.) |
required |
Source code in src/spyglass/utils/h5py_helper_fn.py
find_dynamic_tables_missing_id(file)
¶
Return DynamicTable paths that do not contain an 'id' dataset.
The check is intentionally minimal: a DynamicTable group is considered GOOD if and only if the key 'id' exists directly under that group. Otherwise, it's BAD and included in the returned list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
File
|
Open HDF5 file handle. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
Sorted list of absolute HDF5 paths to DynamicTable groups that are missing the 'id' key. |
Notes
A group is detected as a DynamicTable if its attribute
neurodata_type equals "DynamicTable" (bytes or str).
Source code in src/spyglass/utils/h5py_helper_fn.py
add_id_column_to_table(file, dataset_path)
¶
Add an 'id' column to a DynamicTable dataset if it doesn't exist.
The 'id' column will be populated with sequential integers starting from 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
File
|
An open HDF5 file object. |
required |
dataset_path
|
str
|
The path to the DynamicTable dataset within the HDF5 file. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified dataset_path does not exist or is not a DynamicTable. |