def binary_vector_score_event_accuracy(target, pred, est_tn=True): hit_rate = sum((pred == 1) & (target == 1)) / sum(target == 1) miss_rate = sum((pred == 0) & (target == 1)) / sum(target == 1) fa_rate = sum((pred == 1) & (target == 0)) / sum(target == 0) print('Raw: %1.3f Hit, %1.3f Miss, %1.3f FA ' % (hit_rate, miss_rate, fa_rate)) #Per target event, detect prediction hits: hit = [] on, off = signals.thresh(target, 0.5) for o, f in zip(on, off): ind = pred[o:f] if any(ind): hit.append(1) else: hit.append(0) mean_dur = np.mean(off - on) # Detect false alarms fa = [] on, off = signals.thresh(pred, 0.5) for o, f in zip(on, off): ind = target[o:f] if not (any(ind)): fa.append(1) else: fa.append(0) if est_tn == True: true_negative = round(np.sum(target == 0) / mean_dur) else: true_negative = len( hit ) # This can be made to be true by adding confirmed true negative events (see below) cr = true_negative - sum(fa) miss = np.sum(np.array(hit) == 0) return sum(hit), sum(fa), cr, miss
step=2, poly_order=2) mhh = signals.max_normalize_per_dist(x, mouse_height, step=2, poly_order=2) plt.figure() plt.plot(raw['time'], mh / 100) plt.plot(raw['time'], mhh) # %% Plot some questionable frames [update: they look good!]: parts = [ 'dlc_front_centroid', 'dlc_rear_centroid', ] part_colors = ['.c', '.y'] framesets = [] on, off = signals.thresh(mh, 30, sign='Pos') for o, f in zip(on, off): if o > f: print('o > f') m = round((o + f) / 2) framesets.append([o, m, f]) # framesets=[[8349,8359,8369],[6327, 6337, 6347],[6159,6169,6179],[3356, 3366, 3376]] plot_points = plots.gen_sidecam_plot_points(dlc, parts, framesets) plots.etho_check_sidecamera(dataloc.video(pns.parent), framesets, plot_points=plot_points, part_colors=part_colors) # %% Different rear approach scaling mouse_height to body len x = raw['x'].values
import pickle # %% #Dial 740 Cal: # fn = Path('/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/GPe/Naive/A2A/Ai32/Bilateral/50x2/exclude/2021-08-23-laser_cal/gpe_buttonB6_0-255_11mW_max_cal_cleaned.csv') fn = button_base.joinpath('gpe_buttonB6_0-255_11mW_max_cal_cleaned.csv') df_cal = pd.read_csv(fn) plt.figure() y = df_cal.loc[:, ' Power(W)'] * 1000 # Put in mW plt.plot([x for x in range(0, len(y))], y) #locate drop offs: d = np.diff(y) on, off = signals.thresh(d, -2, 'Neg') for o in off: plt.plot([o, o], [0, 33], '--r') onsets = [2] + off[0:-1] offsets = on durs = [f - o for o, f in zip(onsets, offsets)] use_dur = 3726 #3662 print(durs) newclips = [] for o, f in zip(onsets, offsets): dd = f - o if dd > 3500: if dd > use_dur:
from pathlib import Path import pandas as pd import numpy as np from matplotlib import pyplot as plt from gittislab import signals, plots, behavior, dataloc, ethovision_tools # %% # fn = Path('/home/brian/Dropbox/Gittis Lab Hardware/Laser Glow/laser_cal_sweeps/pwm_to_analog/power_control_sweep_0-255_arduino_multi_sweep_clean.csv') fn = Path('/home/brian/Dropbox/Gittis Lab Hardware/Laser Glow/laser_cal_sweeps/pwm_to_TTL/power_control_sweep_0-255_arduino_TTL_multi_test_clean.csv') df=pd.read_csv(fn) plt.figure() y=df.loc[:,'Power (W)'] *1000 # Put in mW plt.plot(df.loc[:,'Samples '],y) #locate drop offs: d=np.diff(y) on,off=signals.thresh(d,-15,'Neg') for o in off: plt.plot([o,o],[0,33],'--r') onsets= [2] + off[0:-1] offsets = on newclips=[] for o,f in zip(onsets,offsets): dd= f-o if dd > 62: o=f-62 if dd < 62: o= o-(62-dd) t=y[o:f]