Skip to content

Commit 0852e24

Browse files
committed
srb update, presentation prep
1 parent 9ffd928 commit 0852e24

File tree

6 files changed

+952
-162
lines changed

6 files changed

+952
-162
lines changed

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ python scripts/relationalDatabaseEvent.py
55

66
python scripts/filteredDatabase.py
77
python scripts/velocityDatabase.py
8+
python scripts/SRBautoDatabase.py
89

910
# jupyter nbconvert --to html reports/*.ipynb --output-dir reports/html

notebooks/Presentation_plots_1005.ipynb

+178-110
Large diffs are not rendered by default.

notebooks/SRB_auto_1105.ipynb

+512
Large diffs are not rendered by default.

notebooks/SRB_col_auto_analysis_0905.ipynb

+159-49
Large diffs are not rendered by default.

scripts/SRBAutoDatabase.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import cfg
2+
import h5py
3+
import numpy as np
4+
import pandas as pd
5+
from tqdm import tqdm
6+
7+
pd.options.mode.chained_assignment = None # to be fixed
8+
9+
10+
rat_auto = pd.DataFrame()
11+
rat = pd.read_hdf(cfg.velocity_fname, 'Rat_Behavior').set_index('index')
12+
stim = pd.read_hdf(cfg.relational_fname, 'Events').set_index('index')
13+
stim.drop(labels=['MotiveExpTimeSecs'], axis=1, inplace=True)
14+
15+
rat_s = pd.merge(rat, stim, on=['Frame', 'Time', 'session_id'])
16+
rat_sf = rat_s[rat_s.Filtered == 1]
17+
18+
limits = pd.DataFrame(cfg.LIMITS)
19+
20+
21+
22+
# create limit columns
23+
rat_sf['Dmin'], rat_sf['Dmax'] = 0, 0
24+
rat_sf['change'] = False
25+
for index, row in tqdm(limits.iterrows()):
26+
rat_sf['change'] = (rat_sf['Dmin']==0) & (rat_sf['speed']==row['speed'])
27+
rat_sf['Dmin'] = np.where(rat_sf['change']==True, row['min'], rat_sf['Dmin'])
28+
rat_sf['Dmax'] = np.where(rat_sf['change']==True, row['max'], rat_sf['Dmax'])
29+
30+
rat_sf['SRB'] = (rat_sf['U'] > rat_sf['Dmin']) & (rat_sf['U'] < rat_sf['Dmax'])
31+
32+
# dropping unused columns
33+
rat_sf.drop(['Filtered', 'change'], axis=1, inplace=True)
34+
35+
36+
# MERGING SRB THAT HAVE REALLY SHORT BREAKS
37+
rat_up2 = pd.DataFrame()
38+
for name, dd in rat_sf.groupby('session_id'):
39+
# calculating dtime - time difference between srb
40+
dfSRBtemp = dd[dd['SRB']==True]
41+
dfSRBtemp['dtime'] = dfSRBtemp['Time'].diff(1)
42+
df2 = pd.merge(dd, dfSRBtemp[['dtime', 'Frame', 'session_id','Time']], on=['Frame', 'session_id','Time'], how='outer')
43+
df2.fillna(0, inplace=True)
44+
45+
#special time cases
46+
dftemp = dfSRBtemp[(dfSRBtemp['dtime']>0.005) & (dfSRBtemp['dtime']<0.1)]
47+
dftemp = dftemp.reset_index(drop=True)
48+
49+
maxF, minF = {}, {}
50+
minF={}
51+
df2['SRBall'] = df2['SRB']
52+
df2['SRBtt'] = False
53+
# merge super close events
54+
for i in np.arange(0,len(dftemp)):
55+
maxF[i] = dftemp.Time[i]
56+
minF[i] = maxF[i]-dftemp.dtime[i]
57+
58+
df2['SRBtt'] = (df2['Time']>minF[i]) & (df2['Time']<maxF[i]) | (df2['SRBtt']==True)
59+
df2['SRBall'] = (df2['SRBtt']==True) | (df2['SRBall']==True)
60+
61+
62+
df2['dtimeA'] = df2['dtime']
63+
df2.drop('dtime', inplace=True, axis=1)
64+
65+
# DELETING SHORT SRB
66+
# calculating dtime - time of srb
67+
dfSRBtemp2 = df2[df2['SRBall']==False]
68+
dfSRBtemp2['dtime'] = dfSRBtemp2['Time'].diff(1)
69+
df22 = pd.merge(df2, dfSRBtemp2[['dtime', 'Frame', 'session_id','Time']], on=['Frame', 'session_id','Time'], how='outer')
70+
df22.fillna(0, inplace=True)
71+
72+
#special time cases
73+
dftemp2 = dfSRBtemp2[(dfSRBtemp2['dtime']<0.4) & (dfSRBtemp2['dtime']>0.0049)]
74+
dftemp2 = dftemp2.reset_index(drop=True)
75+
maxF2, minF2 = {}, {}
76+
df22['SRBall2'] = df22['SRBall']
77+
df22['SRBtt2'] = False
78+
79+
# delete short events
80+
for i in np.arange(0,len(dftemp2)):
81+
maxF2[i] = dftemp2.Time[i]
82+
minF2[i] = dftemp2.Time[i] - dftemp2.dtime[i]
83+
df22['SRBtt2'] = ((df22['Time']>=minF2[i]) & (df22['Time']<=maxF2[i])) | (df22['SRBtt2']==True)
84+
df22['SRBall2'] = (df22['SRBtt2']==False) & (df22['SRBall2'] == True)
85+
86+
rat_auto = pd.concat([rat_auto, df22], axis=0, ignore_index=True)
87+
88+
89+
with h5py.File(cfg.SRBauto_fname, 'w') as f:
90+
f.create_dataset('Rat_Behavior', data=rat_auto.to_records())

scripts/cfg.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
3# File names
1+
# File names
22
relational_fname = 'datasets/preprocessed/relationalDatabase.h5'
3-
velocity_fname = 'datasets/preprocessed/velocityDatabase.h5'
4-
filtered_fname = 'datasets/preprocessed/filteredDatabase.h5'
3+
velocity_fname = 'datasets/preprocessed/velocityDatabase.h5'
4+
filtered_fname = 'datasets/preprocessed/filteredDatabase.h5'
5+
SRBauto_fname = 'datasets/preprocessed/SRBautoDatabase.h5'
56

67
# Rolling windows
78
WIDNOW_DATA = 40
@@ -13,3 +14,11 @@
1314
FILT_CLEANING_YPOS = 0.07
1415
FILT_CLEANING_YORI = -0.75
1516
FILT_DTIME = 0.005
17+
18+
# Automatic
19+
LIMITS = ({'speed':[ 7, 14, 28, -7, -14 , -28],
20+
'min' :[ 1, 5, 13, -9, -21.5, -30],
21+
'max' :[ 9, 18, 30, -1, -5 , -13]})
22+
23+
CLOSE_SRB_LIM = [0.005 , 0.2]
24+
SHORT_SRB_LIM = [0.0049, 0.4]

0 commit comments

Comments
 (0)