Skip to content

Comments

Fix response latency calculation#90

Merged
saskiad merged 1 commit intoAllenSWDB:mainfrom
JEElsner:vbn-aligning-behavior-data
Aug 6, 2024
Merged

Fix response latency calculation#90
saskiad merged 1 commit intoAllenSWDB:mainfrom
JEElsner:vbn-aligning-behavior-data

Conversation

@JEElsner
Copy link
Contributor

@JEElsner JEElsner commented Jul 17, 2024

We get the time at which the stimulus presentation changes from stimulus_presentations. But if no rows are returned from the table when we join on change frame, the list of rows are empty, so indexing is impossible, and we were getting an indexing error.

Now if no rows are returned we just return NaN.

Fixes #88 .

We get the time at which the stimulus presentation changes from
`stimulus_presentations`. But if no rows are returned from the table
when we join on change frame, the list of rows are empty, so indexing is
impossible, and we were getting an indexing error.

Now if no rows are returned we just return NaN.
@saskiad saskiad requested a review from corbennett July 29, 2024 22:23
Copy link
Collaborator

@corbennett corbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks fine. What sessions are failing in this way? I'm a bit surprised there are cases where there aren't matches in the stim table for the change frame in the trials table. In any case, we can close this. I'll open a new issue if needed.

@JEElsner
Copy link
Contributor Author

JEElsner commented Aug 2, 2024

This is starting to get concerning. I changed the function to count how many values there are and all of the rows are zero. I'm gonna hold off on merging this for now.

def count_start_times(row):
    table = stimulus_presentations
    change_frame = row['change_frame']
    
    if np.isnan(change_frame):
        return np.nan
    
    start_times_len = len(table[table.start_time == change_frame]['start_time'].values)
    return start_times_len

n_start_times = trials.apply(count_start_times, axis=1)
print(f'number of zero entries: {np.count_nonzero(n_start_times == 0)}')
print(f'total entries: {len(n_start_times)}')
number of zero entries: 567
total entries: 567

Am I doing something wrong???

@corbennett
Copy link
Collaborator

This is starting to get concerning. I changed the function to count how many values there are and all of the rows are zero. I'm gonna hold off on merging this for now.

def count_start_times(row):
    table = stimulus_presentations
    change_frame = row['change_frame']
    
    if np.isnan(change_frame):
        return np.nan
    
    start_times_len = len(table[table.start_time == change_frame]['start_time'].values)
    return start_times_len

n_start_times = trials.apply(count_start_times, axis=1)
print(f'number of zero entries: {np.count_nonzero(n_start_times == 0)}')
print(f'total entries: {len(n_start_times)}')
number of zero entries: 567
total entries: 567

Am I doing something wrong???

There's a small bug in this function that explains this result:

start_times_len = len(table[table.start_time == change_frame]['start_time'].values)

should be

start_times_len = len(table[table.start_frame == change_frame]['start_time'].values)

@saskiad saskiad merged commit da8af5d into AllenSWDB:main Aug 6, 2024
@JEElsner
Copy link
Contributor Author

JEElsner commented Aug 6, 2024

We'll look into this more in a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix error in calculating response latency

3 participants