@@ -225,6 +225,7 @@ def plot(
225225 save_path : str = "action_potentials.png" ,
226226 show : bool = True ,
227227 save : bool = False ,
228+ polar : bool = False ,
228229 alpha : float | None = None ,
229230 color : str = "gist_rainbow" ,
230231 ** kwargs : Any ,
@@ -249,96 +250,171 @@ def plot(
249250 ch_action_potentials = self .action_potentials .action_potentials [ch_mask ]
250251 ch_sweeps = self .action_potentials .sweep_numbers [ch_mask ]
251252 ch_threshold_index = self .action_potentials .threshold ["index" ][ch_mask ]
253+ ch_action_potentials_diff = self .action_potentials .action_potentials_diff [
254+ ch_mask
255+ ]
252256 channel_tmp = self .win .addPlot (row = idx , col = 0 ) # type: ignore
253- channel_tmp .setYRange (
254- np .nanmin (ch_action_potentials .magnitude ),
255- np .nanmax (ch_action_potentials .magnitude ),
256- )
257- channel_tmp .setXRange (
258- np .nanmin (
259- self .action_potentials .time .magnitude
260- - self .action_potentials .time .magnitude [ch_threshold_index .min ()]
261- ),
262- np .nanmax (
263- self .action_potentials .time .magnitude
264- - self .action_potentials .time .magnitude [ch_threshold_index .max ()]
265- ),
266- )
257+ if polar :
258+
259+ channel_tmp .setYRange (
260+ np .nanmin (ch_action_potentials_diff .magnitude ),
261+ np .nanmax (ch_action_potentials_diff .magnitude ),
262+ )
263+ channel_tmp .setXRange (
264+ np .nanmin (ch_action_potentials .magnitude ),
265+ np .nanmax (ch_action_potentials .magnitude ),
266+ )
267+ else :
268+ channel_tmp .setYRange (
269+ np .nanmin (ch_action_potentials .magnitude ),
270+ np .nanmax (ch_action_potentials .magnitude ),
271+ )
272+ channel_tmp .setXRange (
273+ np .nanmin (
274+ self .action_potentials .time .magnitude
275+ - self .action_potentials .time .magnitude [
276+ ch_threshold_index .min ()
277+ ]
278+ ),
279+ np .nanmax (
280+ self .action_potentials .time .magnitude
281+ - self .action_potentials .time .magnitude [
282+ ch_threshold_index .max ()
283+ ]
284+ ),
285+ )
267286 if idx == 0 :
268287 channel_0 = channel_tmp
269288 channel_tmp .setXLink (channel_0 )
270289 for i , sweep in enumerate (sweep_numbers ):
271290 sweep_index = np .where (ch_sweeps == sweep )
272291 sweep_array = ch_action_potentials [sweep_index ].magnitude
273- if align_threshold :
292+ # curve_array = CurveArray(np.array([]), np.array([]))
293+ if align_threshold and (polar is False ):
274294 time_scale = np .array (
275295 [
276296 self .action_potentials .time .magnitude
277297 - self .action_potentials .time .magnitude [threshold_idx ]
278298 for threshold_idx in ch_threshold_index [sweep_index ]
279299 ]
280300 )
281- else :
301+ elif polar is False :
282302 time_scale = self .action_potentials .time .magnitude
303+ else :
304+ time_scale = ch_action_potentials_diff [sweep_index ].magnitude
305+
306+ if polar :
307+ curve_array = CurveArray (sweep_array , time_scale )
308+ else :
309+ curve_array = CurveArray (time_scale , sweep_array )
310+
283311 sweep_color = color_picker_qcolor (
284312 len (sweep_numbers ),
285313 i ,
286314 color = self .params .color ,
287315 alpha = self .params .alpha ,
288316 )
289- curve_array = CurveArray ( time_scale , sweep_array )
317+
290318 plot_curve = pg .PlotCurveItem (
291319 curve_array .x ,
292320 curve_array .y ,
293321 pen = pg .mkPen (sweep_color , width = self .params .line_width ),
294322 connect = "finite" ,
295323 )
296324 channel_tmp .addItem (plot_curve )
297- for i , sweep in enumerate (sweep_numbers ):
298- sweep_index = np .where (ch_sweeps == sweep )
299- sweep_array = ch_action_potentials [sweep_index ].magnitude
300- if align_threshold :
301- time_scale = np .array (
302- [
303- self .action_potentials .time .magnitude
304- - self .action_potentials .time .magnitude [threshold_idx ]
305- for threshold_idx in ch_threshold_index [sweep_index ]
306- ]
307- )
308- else :
309- time_scale = self .action_potentials .time .magnitude
310- sweep_color = color_picker_qcolor (
311- len (sweep_numbers ), i , color = self .params .color , alpha = 0.8
312- )
313- if threshold :
314- ch_threshold = self .action_potentials .threshold ["threshold" ][
315- ch_mask
316- ][sweep_index ]
325+ if polar is False :
326+ for i , sweep in enumerate (sweep_numbers ):
327+ sweep_index = np .where (ch_sweeps == sweep )
328+ sweep_array = ch_action_potentials [sweep_index ].magnitude
317329 if align_threshold :
318- time_scale_threshold = 0.0
330+ time_scale = np .array (
331+ [
332+ self .action_potentials .time .magnitude
333+ - self .action_potentials .time .magnitude [threshold_idx ]
334+ for threshold_idx in ch_threshold_index [sweep_index ]
335+ ]
336+ )
319337 else :
320- time_scale_threshold = self .action_potentials .time .magnitude [
321- ch_threshold_index [sweep_index ]
322- ]
323- plot_scatter = pg .ScatterPlotItem (
324- x = time_scale_threshold ,
325- y = ch_threshold ,
326- pen = pg .mkPen (sweep_color , width = 1 ),
327- brush = pg .mkBrush (sweep_color ),
328- marker = "o" ,
329- markersize = 2 ,
338+ time_scale = self .action_potentials .time .magnitude
339+ sweep_color = color_picker_qcolor (
340+ len (sweep_numbers ), i , color = self .params .color , alpha = 0.8
330341 )
331- channel_tmp .addItem (plot_scatter )
342+ if threshold :
343+ ch_threshold = self .action_potentials .threshold ["threshold" ][
344+ ch_mask
345+ ][sweep_index ]
346+ if align_threshold :
347+ time_scale_threshold = 0.0
348+ else :
349+ time_scale_threshold = (
350+ self .action_potentials .time .magnitude [
351+ ch_threshold_index [sweep_index ]
352+ ]
353+ )
354+ plot_scatter = pg .ScatterPlotItem (
355+ x = time_scale_threshold ,
356+ y = ch_threshold ,
357+ pen = pg .mkPen (sweep_color , width = 1 ),
358+ brush = pg .mkBrush (sweep_color ),
359+ marker = "o" ,
360+ markersize = 2 ,
361+ )
362+ channel_tmp .addItem (plot_scatter )
332363
333- channel_tmp .setLabel ("left" , f"Channel { ch } " )
334- channel_tmp .setLabel (
335- "bottom" ,
336- f"Time ({ self .action_potentials .time .dimensionality .string } )" ,
337- )
338- channel_tmp .setLabel (
339- "right" ,
340- f"Amplitude ({ self .action_potentials .action_potentials .dimensionality .string } )" ,
341- )
364+ channel_tmp .setLabel ("left" , f"Channel { ch } " )
365+ channel_tmp .setLabel (
366+ "bottom" ,
367+ f"Time ({ self .action_potentials .time .dimensionality .string } )" ,
368+ )
369+ channel_tmp .setLabel (
370+ "right" ,
371+ f"Amplitude ({ self .action_potentials .action_potentials .dimensionality .string } )" ,
372+ )
373+ else :
374+ for i , sweep in enumerate (sweep_numbers ):
375+ sweep_index = np .where (ch_sweeps == sweep )
376+ sweep_array = ch_action_potentials [sweep_index ].magnitude
377+ sweep_array_diff = ch_action_potentials_diff [sweep_index ].magnitude
378+ sweep_color = color_picker_qcolor (
379+ len (sweep_numbers ), i , color = self .params .color , alpha = 0.8
380+ )
381+ if threshold :
382+
383+ ch_threshold_index = self .action_potentials .threshold ["index" ][
384+ ch_mask
385+ ][sweep_index ]
386+ ch_threshold = self .action_potentials .threshold ["threshold" ][
387+ ch_mask
388+ ][sweep_index ]
389+ ch_threshold_diff = [
390+ sweep_array_diff [idx , threshold_idx ]
391+ for idx , threshold_idx in enumerate (ch_threshold_index )
392+ ]
393+ print (
394+ ch_threshold ,
395+ ch_threshold_diff ,
396+ sweep_color ,
397+ sweep_index ,
398+ )
399+ plot_scatter = pg .ScatterPlotItem (
400+ x = ch_threshold ,
401+ y = ch_threshold_diff ,
402+ pen = pg .mkPen (sweep_color , width = 1 ),
403+ brush = pg .mkBrush (sweep_color ),
404+ marker = "o" ,
405+ markersize = 2 ,
406+ )
407+ channel_tmp .addItem (plot_scatter )
408+
409+ channel_tmp .setLabel ("left" , f"Channel { ch } (Polar)" )
410+ channel_tmp .setLabel (
411+ "bottom" ,
412+ f"Amplitude ({ self .action_potentials .action_potentials .dimensionality .string } )" ,
413+ )
414+ channel_tmp .setLabel (
415+ "right" ,
416+ f"ΔAmplitude ({ self .action_potentials .action_potentials .dimensionality .string } )" ,
417+ )
342418
343419 def show (self ) -> None :
344420 """Show the plot window."""
0 commit comments