@@ -41,6 +41,8 @@ def insert_idx(array, values):
4141 idx [np .where (abs (values - array [idx - 1 ]) < abs (values - array [idx ]))] -= 1
4242 # If 0 index was reduced, revert
4343 idx [idx == - 1 ] = 0
44+ if np .all (idx == 0 ):
45+ raise ValueError ('Something is wrong, all values to insert are outside of the array.' )
4446 return idx
4547
4648
@@ -121,7 +123,7 @@ def get_feature_event_times(dlc, dlc_t, features):
121123
122124def get_licks (dlc , dlc_t ):
123125 """
124- Compute lick times from the toungue dlc points
126+ Compute lick times from the tongue dlc points
125127 :param dlc: dlc pqt table
126128 :param dlc_t: dlc times
127129 :return:
@@ -216,6 +218,9 @@ def get_smooth_pupil_diameter(diameter_raw, camera, std_thresh=5, nan_thresh=1):
216218 else :
217219 raise NotImplementedError ("camera has to be 'left' or 'right" )
218220
221+ # Raise error if too many NaN time points, in this case it doesn't make sense to interpolate
222+ if np .mean (np .isnan (diameter_raw )) > 0.9 :
223+ raise ValueError (f"Raw pupil diameter for { camera } is too often NaN, cannot smooth." )
219224 # run savitzy-golay filter on non-nan time points to denoise
220225 diameter_smoothed = smooth_interpolate_savgol (diameter_raw , window = window , order = 3 , interp_kind = 'linear' )
221226
@@ -488,6 +493,8 @@ def plot_speed_hist(dlc_df, cam_times, trials_df, feature='paw_r', cam='left', l
488493 """
489494 # Threshold the dlc traces
490495 dlc_df = likelihood_threshold (dlc_df )
496+ # For pre-GPIO sessions, remove the first few timestamps to match the number of frames
497+ cam_times = cam_times [- len (dlc_df ):]
491498 # Get speeds
492499 speeds = get_speed (dlc_df , cam_times , camera = cam , feature = feature )
493500 # Windows aligned to align_to
@@ -506,7 +513,7 @@ def plot_speed_hist(dlc_df, cam_times, trials_df, feature='paw_r', cam='left', l
506513 plt .plot (times , pd .DataFrame .from_dict (dict (zip (incorrect .index , incorrect .values ))).mean (axis = 1 ),
507514 c = 'gray' , label = 'incorrect trial' )
508515 plt .axvline (x = 0 , label = 'stimOn' , linestyle = '--' , c = 'r' )
509- plt .title (f'{ feature .split ("_" )[0 ].capitalize ()} speed' )
516+ plt .title (f'{ feature .split ("_" )[0 ].capitalize ()} speed ( { cam } cam) ' )
510517 plt .xticks ([- 0.5 , 0 , 0.5 , 1 , 1.5 ])
511518 plt .xlabel ('time [sec]' )
512519 plt .ylabel ('speed [px/sec]' )
@@ -542,7 +549,7 @@ def plot_pupil_diameter_hist(pupil_diameter, cam_times, trials_df, cam='left'):
542549 plt .plot (times , pupil_mean , label = align_to .split ("_" )[0 ], color = color )
543550 plt .fill_between (times , pupil_mean + pupil_std , pupil_mean - pupil_std , color = color , alpha = 0.5 )
544551 plt .axvline (x = 0 , linestyle = '--' , c = 'k' )
545- plt .title ('Pupil diameter' )
552+ plt .title (f 'Pupil diameter ( { cam } cam) ' )
546553 plt .xlabel ('time [sec]' )
547554 plt .xticks ([- 0.5 , 0 , 0.5 , 1 , 1.5 ])
548555 plt .ylabel ('pupil diameter [px]' )
0 commit comments