Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annas branch #12

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions behav/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def load_data_pandas(subjects, data_folder, force_boolean=['reward']):
dt_maker = _make_dt_maker(year)
df['date'] = df.apply(dt_maker, axis=1)
df.set_index('date', inplace=True)
df['type_'] = df['old_type'].map(lambda(x): ['correction','normal'][x])
df['response'] = df['old_response'].map(lambda(x): ['none', 'L', 'R'][x])
df['correct'] = df['old_correct'].map(lambda(x): [False, True, float('nan')][x])
df['reward'] = df.apply(lambda(x): x['reinforcement'] == 1 and x['correct'] == True, axis=1)
df['class_'] = df['old_class'].map(lambda(x): ['none', 'L', 'R'][x])
df['type_'] = df['old_type'].map(lambda x: ['correction','normal'][x])
df['response'] = df['old_response'].map(lambda x: ['none', 'L', 'R'][x])
df['correct'] = df['old_correct'].map(lambda x: [False, True, float('nan')][x])
df['reward'] = df.apply(lambda x: x['reinforcement'] == 1 and x['correct'] == True, axis=1)
df['class_'] = df['old_class'].map(lambda x: ['none', 'L', 'R'][x])
df['data_file'] = data_f
df_set.append(df)

Expand Down Expand Up @@ -95,11 +95,11 @@ def load_data_pandas(subjects, data_folder, force_boolean=['reward']):
dt_maker = _make_dt_maker(year)
df['date'] = df.apply(dt_maker, axis=1)
df.set_index('date', inplace=True)
df['type_'] = df['old_type'].map(lambda(x): ['correction','normal'][x])
df['response'] = df['old_response'].map(lambda(x): ['none', 'C'][x])
df['correct'] = df['old_correct'].map(lambda(x): [False, True, float('nan')][x])
df['reward'] = df.apply(lambda(x): x['reinforcement'] == 1 and x['correct'] == True, axis=1)
df['class_'] = df['old_class'].map(lambda(x): ['none', 'GO', 'NOGO'][x])
df['type_'] = df['old_type'].map(lambda x: ['correction','normal'][x])
df['response'] = df['old_response'].map(lambda x: ['none', 'C'][x])
df['correct'] = df['old_correct'].map(lambda x: [False, True, float('nan')][x])
df['reward'] = df.apply(lambda x: x['reinforcement'] == 1 and x['correct'] == True, axis=1)
df['class_'] = df['old_class'].map(lambda x: ['none', 'GO', 'NOGO'][x])
df['data_file'] = data_f
df_set.append(df)

Expand All @@ -122,12 +122,12 @@ def _parse(datestr, timestr):
)
df.rename(columns=col_map, inplace=True)
df.set_index('date',inplace=True)
df['type_'] = df['Correction'].map(lambda(x): {0:'normal',1:'correction',243:'error',-1:None}[x])
df['correct'] = df['ResponseAccuracy'].map(lambda(x): [False, True, float('nan')][x])
df['reward'] = df.apply(lambda(x): x['Reinforced'] == 1 and x['correct'] == True, axis=1)
df['punish'] = df.apply(lambda(x): x['Reinforced'] == 1 and x['correct'] == False, axis=1)
df['class_'] = df['StimClass'].map(lambda(x): {0:'none',1:'L',2:'R',243:'error',-1:None}[x])
df['response'] = df['ResponseSelection'].map(lambda(x): ['none', 'L', 'R'][x])
df['type_'] = df['Correction'].map(lambda x: {0:'normal',1:'correction',243:'error',-1:None}[x])
df['correct'] = df['ResponseAccuracy'].map(lambda x: [False, True, float('nan')][x])
df['reward'] = df.apply(lambda x: x['Reinforced'] == 1 and x['correct'] == True, axis=1)
df['punish'] = df.apply(lambda x: x['Reinforced'] == 1 and x['correct'] == False, axis=1)
df['class_'] = df['StimClass'].map(lambda x: {0:'none',1:'L',2:'R',243:'error',-1:None}[x])
df['response'] = df['ResponseSelection'].map(lambda x: ['none', 'L', 'R'][x])
df['data_file'] = data_f

is_behave = df['BehavioralRecording'] > 0
Expand All @@ -141,12 +141,12 @@ def _parse(datestr, timestr):
if df_set:
behav_data[subj] = pd.concat(df_set).sort_index()
else:
print 'data not found for %s' % (subj)
print("data not found for %s" % (subj))
if force_boolean:
for subj in subjects:
if subj in behav_data:
for forced in force_boolean:
behav_data[subj][forced] = behav_data[subj][forced].map(lambda(x): x in [True, 'True', 'true', 1, '1'])
behav_data[subj][forced] = behav_data[subj][forced].map(lambda x: x in [True, 'True', 'true', 1, '1'])
return behav_data

def _make_dt_maker(year):
Expand Down
4 changes: 2 additions & 2 deletions behav/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import utils
import behav.utils as utils
import scipy as sp
from scipy import ndimage

Expand Down Expand Up @@ -214,7 +214,7 @@ def plot_accuracy_bias(subj, df, x_axis='time', smoothing='exponential', trial_l
else:
raise Exception('invalid value for x_axis')

datas = (df['correct'], df['response']=='L', df['response']=='R')
datas = (df['correct'], df['response'].isin(['L','left']), df['response'].isin(['R','right']))
plot_smoothed_mask = (plt_correct_smoothed, plt_L_response_smoothed, plt_R_response_smoothed)
plot_shaded_mask = (plt_correct_shade, plt_L_response_shade, plt_R_response_shade)
plot_line_mask = (plt_correct_line, plt_L_response_line, plt_R_response_line)
Expand Down
2 changes: 1 addition & 1 deletion behav/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def filter_normal_trials(df):
'''
filters dataframe, df, to only include normal (non-correction) trials that got a response.
'''
return df[(df.response<>'none')&(df.type_=='normal')]
return df[(df.response!='none')&(df.type_=='normal')]

def filter_recent_days(df, num_days):
'''
Expand Down
159 changes: 0 additions & 159 deletions notebooks/recent_behavior_analysis.ipynb

This file was deleted.

584 changes: 584 additions & 0 deletions recent_behavior_analysis.ipynb

Large diffs are not rendered by default.