Browse Source

Fix saving of nix by making all channel_id(s) (array)annotations dtype int

Michael Denker 10 months ago
parent
commit
861f31756a
1 changed files with 6 additions and 9 deletions
  1. 6 9
      code/reachgraspio/reachgraspio.py

+ 6 - 9
code/reachgraspio/reachgraspio.py

@@ -783,7 +783,7 @@ class ReachGraspIO(BlackrockIO):
         unit_dict = {}
         for seg in block.segments:
             for st in seg.spiketrains:
-                chid = str(st.annotations['channel_id'])
+                chid = st.annotations['channel_id']
                 unit_id = st.annotations['unit_id']
                 if chid not in unit_dict:
                     unit_dict[chid] = {}
@@ -843,7 +843,7 @@ class ReachGraspIO(BlackrockIO):
 
             try:
                 sec = self.odmldoc['UtahArray']['Array'][
-                    'Electrode_%03d' % int(un.annotations['channel_id'])][
+                    'Electrode_%03d' % un.annotations['channel_id']][
                     'OfflineSpikeSorting']
             except KeyError:
                 return
@@ -986,13 +986,16 @@ class ReachGraspIO(BlackrockIO):
         if self.odmldoc:
 
             # updating array annotations of neuronal analogsignals
+            # and use same dtype for channel_id annotations as for
+            # channel_ids array_annotations
             for seg in block.segments:
                 for obj in seg.analogsignals:
                     if 'neural_signal' in obj.annotations and obj.annotations[
                        'neural_signal'] and 'channel_ids' in obj.array_annotations:
                         chids = np.asarray(obj.array_annotations['channel_ids'], dtype=int)
                         ca_ids, *coordinates = self.__convert_chids_and_coordinates(chids)
-                        obj.array_annotations.update(dict(connector_aligned_ids=ca_ids,
+                        obj.array_annotations.update(dict(channel_ids=chids,
+                                                          connector_aligned_ids=ca_ids,
                                                           coordinates_x=coordinates[0],
                                                           coordinates_y=coordinates[1]))
 
@@ -1001,14 +1004,8 @@ class ReachGraspIO(BlackrockIO):
             for seg in block.segments:
                 sts.extend(seg.spiketrains)
 
-            # use same dtypes for annotations and array_annotations
-            for st in sts:
-                st.annotations['channel_id'] = str(st.annotations['channel_id'])
-
             for obj in sts + block.groups:
                 if 'channel_id' in obj.annotations:
-                    # use same dtype for annotations as array_annotations
-                    obj.annotations['channel_id'] = str(obj.annotations['channel_id'])
                     chid = obj.annotations['channel_id']
                     ca_id, *coordinates = self.__convert_chids_and_coordinates([chid])
                     obj.annotate(connector_aligned_id=ca_id[0],