Browse Source

gin commit from nit-ope-de04

Modified files: 4
sprenger 3 years ago
parent
commit
c7014e5a23
4 changed files with 45 additions and 11 deletions
  1. 29 5
      code/data_overview_1.py
  2. 8 1
      code/data_overview_2.py
  3. 1 1
      code/example.py
  4. 7 4
      code/reachgraspio/reachgraspio.py

+ 29 - 5
code/data_overview_1.py

@@ -51,6 +51,7 @@ from reachgraspio import reachgraspio
 import odml.tools
 
 from neo import utils as neo_utils
+from neo_utils import load_segment
 import odml_utils
 
 
@@ -127,8 +128,8 @@ def get_arraygrid(signals, chosen_el):
 # Load data and metadata for a monkey
 # =============================================================================
 # CHANGE this parameter to load data of the different monkeys
-# monkey = 'Nikos2'
-monkey = 'Lilou'
+monkey = 'Nikos2'
+# monkey = 'Lilou'
 
 chosen_el = {'Lilou': 71, 'Nikos2': 63}
 chosen_units = {'Lilou': range(1, 5), 'Nikos2': range(1, 5)}
@@ -223,9 +224,33 @@ segment.spiketrains = segment.filter(targdict={'channel_id': chosen_el[monkey]},
 segment.spiketrains = [st for st in segment.spiketrains if st.annotations['unit_id'] in range(1, 5)]
 # replacing the segment with a new segment containing all data
 # to speed up cutting of segments
-from neo_utils import load_segment
 segment = load_segment(segment, load_wavefroms=True, channel_indexes=[chosen_el[monkey]])
 
+# use most raw neuronal data if multiple versions are present
+max_sampling_rate = max([a.sampling_rate for a in segment.analogsignals])
+idx = 0
+while idx < len(segment.analogsignals):
+    signal = segment.analogsignals[idx]
+    if signal.annotations['neural_signal'] and signal.sampling_rate < max_sampling_rate:
+        segment.analogsignals.pop(idx)
+    else:
+        idx += 1
+
+# neural_signals = []
+# behav_signals = []
+# for sig in segment.analogsignals:
+#     if sig.annotations['neural_signal']:
+#         neural_signals.append(sig)
+#     else:
+#         behav_signals.append(sig)
+#
+# chosen_raw = neural_signals[0]
+# for sig in neural_signals:
+#     if sig.sampling_rate > chosen_raw.sampling_rate:
+#         chosen_raw = sig
+#
+# segment.analogsignals = behav_signals + [chosen_raw]
+
 # cut segments according to inserted 'complete_trials' epochs and reset trial times
 cut_segments = neo_utils.cut_segment_by_epoch(segment, epochs[0], reset_time=True)
 
@@ -569,8 +594,7 @@ ax4.text(timebar_xmin + 0.25 * pq.s, timebar_ypos + timebar_labeloffset,
 # PLOT BEHAVIORAL SIGNALS of chosen trial
 # =============================================================================
 # get behavioral signals
-ainp_signals = [nsig for nsig in trial_segment.analogsignals if
-                not nsig.annotations['neural_signal']][0]
+ainp_signals = [nsig for nsig in trial_segment.analogsignals if not nsig.annotations['neural_signal']][0]
 
 force_channel_idx = np.where(ainp_signals.array_annotations['channel_ids'] == 141)[0][0]
 ainp_trialz_signals = [a for a in trialz_seg.analogsignals if not a.annotations['neural_signal']]

+ 8 - 1
code/data_overview_2.py

@@ -137,10 +137,17 @@ seg.spiketrains = seg.filter(targdict={'unit_id': chosen_unit},
 # remove all non-neural signals
 seg.analogsignals = seg.filter(targdict={'neural_signal': True},
                                objects='AnalogSignalProxy')
+
+# use most raw data if multiple versions are present
+raw_signal = seg.analogsignals[0]
+for sig in seg.analogsignals:
+    if sig.sampling_rate > raw_signal.sampling_rate:
+        raw_signal = sig
+seg.analogsignals = [raw_signal]
+
 # replacing the segment with a new segment containing all data
 # to speed up cutting of segments
 seg = load_segment(seg, load_wavefroms=True)
-assert len(seg.analogsignals) == 1
 
 # only keep the chosen electrode signal in the AnalogSignal object
 mask = np.isin(seg.analogsignals[0].array_annotations['channel_ids'], chosen_els[monkey])

+ 1 - 1
code/example.py

@@ -72,7 +72,7 @@ session = reachgraspio.ReachGraspIO(session_name, odml_directory=odml_dir)
 # but not loading data into memory.  The lazy neo structure will contain objects
 # to capture all recorded data types (time series at 1000Hz (ns2) and 30kHz (ns6)
 # scaled to units of voltage, sorted spike trains, spike waveforms and events)
-# from electrode 62 of the recording session and return it as a Neo Block. The
+# of the recording session and return it as a Neo Block. The
 # time shift of the ns2 signal (LFP) induced by the online filter is
 # automatically corrected for by a heuristic factor stored in the metadata
 # (correct_filter_shifts=True).

+ 7 - 4
code/reachgraspio/reachgraspio.py

@@ -476,10 +476,10 @@ class ReachGraspIO(BlackrockIO):
             for band in bands:
                 sec = self.odmldoc['PreProcessing'][band]
 
-                if type(sec.properties['RejTrials'].values) != [-1]:
+                if type(sec.properties['RejTrials'].values) != []:
                     rej_trials = [int(_) for _ in sec.properties['RejTrials'].values]
                     rej_index = np.in1d(event.array_annotations['trial_id'], rej_trials)
-                elif sec.properties['RejTrials'].values == [-1]:
+                elif sec.properties['RejTrials'].values == []:
                     rej_index = np.zeros((len(event.array_annotations['trial_id'])), dtype=bool)
                 else:
                     raise ValueError(
@@ -536,7 +536,7 @@ class ReachGraspIO(BlackrockIO):
                 for analog_events in trial_sec['AnalogEvents'][signalname].properties:
 
                     # skip invalid values
-                    if analog_events.values == [-1]:  # this was used as default time
+                    if analog_events.values == []:  # this was used as default time
                         continue
 
                     time = analog_events.values * pq.CompoundUnit(analog_events.unit)
@@ -844,7 +844,10 @@ class ReachGraspIO(BlackrockIO):
                 return
 
             suaids = sec.properties['SUAIDs'].values
-            muaid = sec.properties['MUAID'].values[0]
+            if sec.properties['MUAID'].values:
+                muaid = sec.properties['MUAID'].values[0]
+            else:
+                muaid = None
             noiseids = sec.properties['NoiseIDs'].values
 
             if un.annotations['unit_id'] in suaids: