AllenInstitute / mindscope_utilities

Utilities for loading, manipulating and visualizing data from the Allen Institute Mindscope program
Other
2 stars 1 forks source link

add_trials_id_to_stimulus_presentations does not work as supposed #59

Closed jkim0731 closed 1 year ago

jkim0731 commented 2 years ago

/visual_behavior_ophys/data_formatting.py def add_trials_id_to_stimulus_presentations(stimulus_presentations, trials):

adds bunch of NaN's and occasionally some trials_id. It is because inside the method it is looking for 'change_time' of trials that are within 1 s apart from stimulus 'start_time'. If the purpose is to curate go trials only, the name of the method does not clearly state it.

Given its usage in add_trials_data_to_stimulus_presentations_table, again used in get_annotated_stimulus_presentations, it does not seem to perform as it is supposed to. For example, add_trials_data_to_stimulus_presentations_table does not log any 'aborted' trials.

A better approach is written inside annotate_stimuli.

for idx, row in stimulus_presentations.iterrows():
    # trials_id is last trials_id with start_time <= stimulus_time
    try:
        trials_id = trials.loc[:row['start_time']].iloc[-1]['trials_id']
    except IndexError:
        trials_id = -1
    stimulus_presentations.at[idx, 'trials_id'] = trials_id