@@ -1032,6 +1032,12 @@ def make(self, key):
1032
1032
& electrode_config_key
1033
1033
) * (dj .U ("electrode" , "channel_idx" ) & EphysRecording .Channel )
1034
1034
1035
+ channel_info = electrode_query .fetch (as_dict = True , order_by = "channel_idx" )
1036
+
1037
+ channel_info : dict [int , dict ] = {
1038
+ ch .pop ("channel_idx" ): ch for ch in channel_info
1039
+ }
1040
+
1035
1041
channel2electrode_map = dict (
1036
1042
zip (* electrode_query .fetch ("channel_idx" , "electrode" ))
1037
1043
) # {channel: electrode}
@@ -1058,27 +1064,37 @@ def make(self, key):
1058
1064
1059
1065
peak_electrode_ind = np .array (
1060
1066
[
1061
- channel2electrode_map [unit_peak_channel_map [unit_id ]]
1067
+ channel_info [unit_peak_channel_map [unit_id ]][ "electrode" ]
1062
1068
for unit_id in si_sorting .unit_ids
1063
1069
]
1064
1070
) # get the electrode where peak unit activity is recorded
1065
1071
1066
1072
# Get channel to depth mapping
1067
1073
channel_depth_ind = np .array (
1068
1074
[
1069
- channel2depth_map [unit_peak_channel_map [unit_id ]]
1075
+ channel_info [unit_peak_channel_map [unit_id ]][ "y_coord" ]
1070
1076
for unit_id in si_sorting .unit_ids
1071
1077
]
1072
1078
)
1073
- spikes ["electrode" ] = peak_electrode_ind [spikes ["unit_index" ]]
1074
- spikes ["depth" ] = channel_depth_ind [spikes ["unit_index" ]]
1079
+
1080
+ # Assign electrode and depth for each spike
1081
+ new_spikes = np .empty (spikes .shape , spikes .dtype .descr + [('electrode' , '<i8' ), ('depth' , '<i8' )])
1082
+
1083
+ for field in spikes .dtype .names :
1084
+ new_spikes [field ] = spikes [field ]
1085
+ del spikes
1086
+
1087
+ new_spikes ["electrode" ] = peak_electrode_ind [new_spikes ["unit_index" ]]
1088
+ new_spikes ["depth" ] = channel_depth_ind [new_spikes ["unit_index" ]]
1075
1089
1076
1090
units = []
1077
1091
1078
1092
for unit_id in si_sorting .unit_ids :
1079
1093
unit_id = int (unit_id )
1080
1094
units .append (
1081
- {
1095
+ {
1096
+ ** key ,
1097
+ ** channel_info [unit_peak_channel_map [unit_id ]],
1082
1098
"unit" : unit_id ,
1083
1099
"cluster_quality_label" : cluster_quality_label_map .get (
1084
1100
unit_id , "n.a."
@@ -1087,11 +1103,11 @@ def make(self, key):
1087
1103
unit_id , return_times = True
1088
1104
),
1089
1105
"spike_count" : spike_count_dict [unit_id ],
1090
- "spike_sites" : spikes ["electrode" ][
1091
- spikes ["unit_index" ] == unit_id
1106
+ "spike_sites" : new_spikes ["electrode" ][
1107
+ new_spikes ["unit_index" ] == unit_id
1092
1108
],
1093
- "spike_depths" : spikes ["depth" ][
1094
- spikes ["unit_index" ] == unit_id
1109
+ "spike_depths" : new_spikes ["depth" ][
1110
+ new_spikes ["unit_index" ] == unit_id
1095
1111
],
1096
1112
}
1097
1113
)
@@ -1178,7 +1194,7 @@ def make(self, key):
1178
1194
)
1179
1195
1180
1196
self .insert1 (key )
1181
- self .Unit .insert ([{ ** key , ** u } for u in units ] )
1197
+ self .Unit .insert (units , ignore_extra_fields = True )
1182
1198
1183
1199
1184
1200
@schema
0 commit comments