fixes #6 remove error rows from replay template before starting passive task

parent b857a75b
"""Initialize sp_experiment."""
__version__ = '0.2.1-dev'
__version__ = '0.2.2-dev'
......@@ -38,6 +38,7 @@ from sp_experiment.utils import (KEYLIST_SAMPLES,
get_payoff_dict,
get_passive_action,
get_passive_outcome,
remove_error_rows
)
from sp_experiment.define_payoff_settings import (get_payoff_settings,
get_random_payoff_dict,
......@@ -373,6 +374,8 @@ def run_flow(monitor='testMonitor', ser=Fake_serial(), max_ntrls=10,
fname = f'sub-{yoke_to:02d}_task-spactive_events.tsv'
fpath = op.join(op.dirname(data_file), fname)
df = pd.read_csv(fpath, sep='\t')
error_trig = ord(trig_dict['trig_error'])
df = remove_error_rows(df, error_trig=error_trig)
df = df[pd.notnull(df['trial'])]
current_nblocks = 0
......
......@@ -153,6 +153,37 @@ def get_payoff_dict(df, trial):
return payoff_dict
def remove_error_rows(df, error_trig):
"""Identify error rows and remove them.
Identify errors via an event value and discard all rows and including the
error row within the trial that the error happened.
Parameters
----------
df : pandas.DataFrame
The original data with a 'trial' and 'value' column
error_trig : int
The event value marking an error, 16 in v0.1.0, 20 in v0.2.0
Returns
-------
df : pandas.DataFrame
The original df with the trials containing errors remove
"""
error_idx = df.index[df['value'] == error_trig].to_numpy()
error_trls = df['trial'][error_idx].to_numpy()
remove_idx = list()
for idx, trl in zip(error_idx, error_trls):
__ = np.logical_and(df['trial'] == trl, df.index <= idx)
remove_idx += df.index[__].to_list()
df = df.drop(remove_idx)
return df
def get_passive_action(df, trial, sample):
"""Get data for a replay.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment