AllenInstitute / AllenSDK

code for reading and processing Allen Institute for Brain Science data
https://allensdk.readthedocs.io/en/latest/
Other
340 stars 150 forks source link

calculate_reward_rate fails for VBN data #2530

Open matchings opened 2 years ago

matchings commented 2 years ago

Describe the bug the function calculate_reward_rate from allensdk.brain_observatory.behavior.trials_processing returns incorrect values (all zeros) with Visual Behavior Neuropixels data because it lacks the requisite columns to calculate the reward rate value. Specifically, the VBN trials table does not have response_latency.

Response latency can be calculated as trials['response_latency'] = trials.response_time-trials.change_time_no_display_delay

To Reproduce `from allensdk.brain_observatory.behavior.behavior_project_cache.\ behavior_neuropixels_project_cache \ import VisualBehaviorNeuropixelsProjectCache

cache = VisualBehaviorNeuropixelsProjectCache.from_local_cache( cache_dir=cache_dir, use_static_cache=use_static)

session_id = 1053941483 session = cache.get_ecephys_session( ecephys_session_id=session_id)

trials = session.trials.copy()

from allensdk.brain_observatory.behavior.trials_processing import calculate_reward_rate

trials['reward_rate'] = calculate_reward_rate(trials['response_latency'].values, trials['start_time'], window=.5)`

Expected behavior I expect the output of calculate_reward_rate to return the trials table with a column added called reward_rate with values that are not entirely zero or NaN.

Actual Behavior image

Environment (please complete the following information):

Additional context Add any other context about the problem here.

morriscb commented 1 year ago

Hey Marina,

I've started looking into this issue and was able reproduce and find where I think we would have to add the calculation to compute the response_latency column. However, I chatted with @aamster a bit and learned that the supported way of accessing the reward rate for the session is through the method BehaviorSession.get_reward_rate() not the trials table. Here's the code for the method. It eventually calls the method same calculate_reward_rate that you are using here. Does calling this method on the session you load in the code above give you what you want?