@@ -127,19 +127,20 @@ def get_best_channel(self, unit):
127
127
128
128
def extract_spike_depths (self ):
129
129
""" Reimplemented from https://github.com/cortex-lab/spikes/blob/master/analysis/ksDriftmap.m """
130
- ycoords = self .data ['channel_positions' ][:, 1 ]
131
- pc_features = self .data ['pc_features' ][:, 0 , :] # 1st PC only
132
- pc_features = np .where (pc_features < 0 , 0 , pc_features )
133
-
134
- # ---- compute center of mass of these features (spike depths) ----
135
-
136
- # which channels for each spike?
137
- spk_feature_ind = self .data ['pc_feature_ind' ][self .data ['spike_templates' ], :]
138
- # ycoords of those channels?
139
- spk_feature_ycoord = ycoords [spk_feature_ind ]
140
- # center of mass is sum(coords.*features)/sum(features)
141
- self ._data ['spike_depths' ] = (np .sum (spk_feature_ycoord * pc_features ** 2 , axis = 1 )
142
- / np .sum (pc_features ** 2 , axis = 1 ))
130
+ if 'pc_features' in self .data :
131
+ ycoords = self .data ['channel_positions' ][:, 1 ]
132
+ pc_features = self .data ['pc_features' ][:, 0 , :] # 1st PC only
133
+ pc_features = np .where (pc_features < 0 , 0 , pc_features )
134
+
135
+ # ---- compute center of mass of these features (spike depths) ----
136
+
137
+ # which channels for each spike?
138
+ spk_feature_ind = self .data ['pc_feature_ind' ][self .data ['spike_templates' ], :]
139
+ # ycoords of those channels?
140
+ spk_feature_ycoord = ycoords [spk_feature_ind ]
141
+ # center of mass is sum(coords.*features)/sum(features)
142
+ self ._data ['spike_depths' ] = (np .sum (spk_feature_ycoord * pc_features ** 2 , axis = 1 )
143
+ / np .sum (pc_features ** 2 , axis = 1 ))
143
144
144
145
# ---- extract spike sites ----
145
146
max_site_ind = np .argmax (np .abs (self .data ['templates' ]).max (axis = 1 ), axis = 1 )
0 commit comments