Ver código fonte

Aggiorna 'code/python/supportFunctions/get_all_data.py'

Stefano Diomedi 9 meses atrás
pai
commit
734f2ce979
1 arquivos alterados com 68 adições e 68 exclusões
  1. 68 68
      code/python/supportFunctions/get_all_data.py

+ 68 - 68
code/python/supportFunctions/get_all_data.py

@@ -1,69 +1,69 @@
-import h5py
-import numpy as np
-#import pandas as pd
-
-def get_all_data_from_level_h5(filename, str):
-    # The function extracts the spikes and the markers from a .h5 dataset
-
-    # INPUT:
-    #     filename = a string that identifies the h5 file from which to extract data
-    #     str = the group from which to extract the data. The function
-    #     automatically extracts every dataset of the group
-
-    # OUTPUT:
-    #     spikes = contains the extracted spike timing for each dataset
-    #     markers = contains the extracted marker timing for each dataset
-    #     all_strings = keeps track of the datasets extracted
-
-    # Francesco E. Vaccari 10/2022
-
-    with h5py.File(filename, 'r') as f:
-        if 'trial' in str:
-            lev = 4
-        elif 'condition' in str:
-            lev = 3
-        elif 'unit' in str:
-            lev = 2
-        elif 'DATA' in str:
-            lev = 1
-        else:
-            raise ValueError('str is not correct')
-
-        info = f[str]
-
-        spikes = []
-        markers = []
-        all_strings = []
-
-        if lev == 4:
-            spikes.append(np.array(info['spike_trains']))
-            markers.append(np.array(info['events_markers']))
-
-        elif lev == 3:
-            for trial in info:
-                str_trial = str + '/' + trial
-                spikes.append(np.array(f[str_trial]['spike_trains']))
-                markers.append(np.array(f[str_trial]['events_markers']))
-                all_strings.append(str_trial)
-
-        elif lev == 2:
-            for cond in info:
-                str2check = str + '/' + cond
-                for trial in f[str2check]:
-                    str_trial = str + '/' + cond + '/' + trial
-                    spikes.append(np.array(f[str_trial]['spike_trains']))
-                    markers.append(np.array(f[str_trial]['events_markers']))
-                    all_strings.append(str_trial)
-
-        elif lev == 1:
-            for neu in info:
-                str2check = str + '/' + neu
-                for cond in f[str2check]:
-                    str2check_cond = str2check + '/' + cond
-                    for trial in f[str2check_cond]:
-                        str_trial = str2check_cond + '/' +trial
-                        spikes.append(np.array(f[str_trial]['spike_trains']))
-                        markers.append(np.array(f[str_trial]['events_markers']))
-                        all_strings.append(str_trial)
-
+import h5py
+import numpy as np
+#import pandas as pd
+
+def get_all_data_from_level_h5(filename, str):
+    # The function extracts the spikes and the markers from a .h5 dataset
+
+    # INPUT:
+    #     filename = a string that identifies the h5 file from which to extract data
+    #     str = the group from which to extract the data. The function
+    #     automatically extracts every dataset of the group
+
+    # OUTPUT:
+    #     spikes = contains the extracted spike timing for each dataset
+    #     markers = contains the extracted marker timing for each dataset
+    #     all_strings = keeps track of the datasets extracted
+
+    # Francesco E. Vaccari 10/2022
+
+    with h5py.File(filename, 'r') as f:
+        if 'trial' in str:
+            lev = 4
+        elif 'condition' in str:
+            lev = 3
+        elif 'unit' in str:
+            lev = 2
+        elif 'DATA' in str:
+            lev = 1
+        else:
+            raise ValueError('str is not correct')
+
+        info = f[str]
+
+        spikes = []
+        markers = []
+        all_strings = []
+
+        if lev == 4:
+            spikes.append(np.array(info['spike_trains']))
+            markers.append(np.array(info['event_markers']))
+
+        elif lev == 3:
+            for trial in info:
+                str_trial = str + '/' + trial
+                spikes.append(np.array(f[str_trial]['spike_trains']))
+                markers.append(np.array(f[str_trial]['event_markers']))
+                all_strings.append(str_trial)
+
+        elif lev == 2:
+            for cond in info:
+                str2check = str + '/' + cond
+                for trial in f[str2check]:
+                    str_trial = str + '/' + cond + '/' + trial
+                    spikes.append(np.array(f[str_trial]['spike_trains']))
+                    markers.append(np.array(f[str_trial]['event_markers']))
+                    all_strings.append(str_trial)
+
+        elif lev == 1:
+            for neu in info:
+                str2check = str + '/' + neu
+                for cond in f[str2check]:
+                    str2check_cond = str2check + '/' + cond
+                    for trial in f[str2check_cond]:
+                        str_trial = str2check_cond + '/' +trial
+                        spikes.append(np.array(f[str_trial]['spike_trains']))
+                        markers.append(np.array(f[str_trial]['event_markers']))
+                        all_strings.append(str_trial)
+
     return spikes, markers, all_strings