Пример #1
0
from gittislab import dataloc
from gittislab import behavior
from gittislab import mat_file
from gittislab import plots
import time
import numpy as np
import pandas as pd
from scipy import stats
import cv2

# %% Test how long it takes to run a rear-extraction frunction on 1 video:
inc = ['GPe', 'Arch', 'PV', '10x30', 'Bilateral', 'AG3474_1']  #1st test
# inc=['10x30','A2A','AG3525_10','Bilateral']
exc = ['exclude']
basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior'
paths = dataloc.gen_paths_recurse(basepath, inc, exc, '.h5')

vid_path = dataloc.video(basepath, inc, exc)
print('Finished')
save_figs = False
tic = time.perf_counter()
peak, start, stop, df = behavior.detect_rear(paths,
                                             rear_thresh=0.7,
                                             min_thresh=0.2,
                                             save_figs=save_figs,
                                             dlc_outlier_thresh_sd=4,
                                             dlc_likelihood_thresh=0.1)
toc = time.perf_counter()
print('%2.1f seconds.' % float(toc - tic))

# %% Script that opens df, checks if fields are present, if not, adds it, saves .h5
# %% Check that immobility vs. ambulation vs. fine movement are detected correctly:
fig = plt.figure(figsize=(20, 5))

y = raw['vel']
m = np.nanmean(y)
raw = ethovision_tools.add_amb_to_raw(raw, meta)
fm = (raw['im'] == False) & (raw['ambulation'] == False)
wtf = (raw['im'] == True) & (raw['ambulation'] == True)

plt.plot(raw['time'], y, 'k')
plt.plot(raw['time'], raw['im'] * m, 'b')
plt.plot(raw['time'], raw['ambulation'] * m, '--r')
plt.plot(raw['time'], raw['fine_move'] * m, '--c')
plt.plot(raw['time'][wtf], np.ones((sum(wtf), 1)) * m, 'ro')
plt.plot(raw['time'].values[[0, -1]], meta['amb_vel_thresh'][0:2], '--g')

# %% Debug adding DLC data columns to Raw*.csv:
#
ex0 = ['exclude', '_and_GPe', 'Left', 'Right', 'Other XLS', 'Exclude']
inc = [['AG', 'GPe', 'CAG', 'Arch', '10x']]
exc = [ex0]
# inc=[['AG','Str','A2A','Ai32','10x'],['AG','Str','A2A','ChR2','10x']]
# exc=[ex0,ex0]
basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/'
dlc_path = dataloc.gen_paths_recurse(basepath, inc[0], exc[0],
                                     'dlc_analyze.h5')
raw_path = dataloc.raw_csv(basepath, inc[0], exc[0])

ethovision_tools.add_dlc_to_csv(basepath, inc, exc, save=True)
# dlc = behavior.load_and_clean_dlc_h5(dlc_path[0])
# raw,meta=ethovision_tools.csv_load(raw_path[0])
Пример #3
0
from scipy.interpolate import interp1d
from scipy.signal import find_peaks
import time


def calculateDistance(x1, y1, x2, y2):
    dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
    return dist

# %%

inc = ['GPe', 'Arch', 'PV', '10x30', 'Bilateral', 'AG3474_1']  #1st test
inc = ['10x30', 'A2A', 'AG3525_10', 'Bilateral']
exc = []
basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior'
paths = dataloc.gen_paths_recurse(basepath, inc, exc, '.h5')
for p in paths:
    print(p)

vid_path = dataloc.video(basepath, inc, exc)
print('Finished')

# %% Faster way:

peak, start, stop, df = behavior.detect_rear(paths[0],
                                             rear_thresh=0.7,
                                             min_thresh=0.2,
                                             save_figs=True,
                                             dlc_outlier_thresh_sd=4,
                                             dlc_likelihood_thresh=0.1)
            'Str',
            'A2A',
            'Ai32',
            '50x2_multi_mW',
        ]]

    pns = dataloc.raw_csv(basepath, inc[0], ex0)
    if not isinstance(pns, list):
        pns = [pns]

    pns = dataloc.raw_csv(basepath, inc[0], ex0)
    for ii in range(0, len(pns), 1):
        raw, meta = ethovision_tools.csv_load(pns[ii],
                                              columns='All',
                                              method='preproc')
        trial_fn = dataloc.gen_paths_recurse(pns[ii].parent,
                                             filetype='pwm_output*.csv')
        trials = pd.read_csv(trial_fn)
        doubled = False
        #% Percent Time Immobile
        if len(meta['stim_dur']) > 50:
            doubled = True
        if doubled:
            meta.drop(axis=0, index=range(0, 100, 2), inplace=True)
            meta.reset_index(inplace=True)

        m_clip = behavior.stim_clip_grab(raw,
                                         meta,
                                         y_col=y_col,
                                         stim_dur=meta['stim_dur'][0],
                                         baseline=meta['stim_dur'][0],
                                         summarization_fun=sum_fun)
Пример #5
0
        sampKey[key] = pwSamp
    return timeKey, sampKey


# %% Binary packet reading:
ex0=['exclude','Bad','GPe','bad','Broken', 'grooming',
 'Exclude','Other XLS']
exc=[ex0]
inc=[['AG','Str','A2A','Ai32','50x2_hm4di_cno',]]
pns=dataloc.raw_csv(basepath,inc[0],ex0)
if not isinstance(pns,list):
    pns=[pns]
use = pns[4]
df,meta=ethovision_tools.csv_load(use,columns='All',method='raw' )

truth_pn=dataloc.gen_paths_recurse(use.parent,[],[],filetype='pwm_output*.csv')
# truth_pn=pns[0].parent.joinpath('pwm_output_trial_354.csv')
pwm_df=pd.read_csv(truth_pn)`

#%% Without interpolation:
correct_day=False
ver=3
evt = df['Binary packet info'].values.astype(int)
if correct_day == True:
    evt[1025:1029]=0 # Why are the stop and start events "Fused" here? bug?
    #evt[10257]=0
p=np.insert(evt,0,0)
dp=np.diff(p)
s=np.argwhere(dp==1)
ss = np.argwhere(dp==-1)
pwHigh = ss -s