|
@@ -0,0 +1,40 @@
|
|
|
+import h5py
|
|
|
+import numpy as np
|
|
|
+
|
|
|
+def get_all_data_from_level_h5_rec(filename, group_name, markers, all_strings_mk, spikes, all_strings_sp):
|
|
|
+ """
|
|
|
+ This function recursively reads data from an HDF5 file.
|
|
|
+
|
|
|
+ Parameters:
|
|
|
+ filename (str): A string that identifies the HDF5 file from which to extract data.
|
|
|
+ group_name (str): The group from which to start extracting data.
|
|
|
+ data (list, optional): A list to add and store the extracted data. Defaults to None.
|
|
|
+ all_strings (list, optional): A list to add and store the paths of the extracted datasets. Defaults to None.
|
|
|
+
|
|
|
+ Returns:
|
|
|
+ data (list): A list containing the extracted data for each dataset.
|
|
|
+ all_strings (list): A list containing the paths of the extracted datasets.
|
|
|
+
|
|
|
+ authors: Stefano Diomedi and Francesco E. Vaccari
|
|
|
+ date: 03/2024
|
|
|
+ """
|
|
|
+
|
|
|
+ def visitor_func(name, node):
|
|
|
+ if isinstance(node, h5py.Group):
|
|
|
+ node.visititems(visitor_func)
|
|
|
+ if isinstance(node, h5py.Dataset):
|
|
|
+ # ...read the data from the dataset and append it to the 'data' list.
|
|
|
+ if name == 'event_markers' and node.name not in all_strings_mk:
|
|
|
+ markers.append(node[()])
|
|
|
+ # ...append the path of the dataset to the 'all_strings' list.
|
|
|
+ all_strings_mk.append(node.name)
|
|
|
+ if name == 'spike_trains' and node.name not in all_strings_sp:
|
|
|
+ spikes.append(node[()])
|
|
|
+ all_strings_sp.append(node.name)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ with h5py.File(filename, 'r') as f:
|
|
|
+ f[group_name].visititems(visitor_func)
|
|
|
+
|
|
|
+ return markers, all_strings_mk, spikes, all_strings_sp
|