AllenInstitute / AllenSDK

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

Improvements to stimulus presentations table #2526

Closed aamster closed 2 years ago

aamster commented 2 years ago

Addresses #1190 Addresses #2515

This PR adds 2 improvements to the visual behavior stimulus presentations table:

Adds records for fingerprint stimulus if it exists

import pandas as pd

from allensdk.brain_observatory.behavior.data_files import BehaviorStimulusFile
from allensdk.brain_observatory.behavior.data_objects import StimulusTimestamps
from allensdk.brain_observatory.behavior.data_objects.stimuli\
    .fingerprint_stimulus import \
    FingerprintStimulus
from allensdk.core.auth_config import LIMS_DB_CREDENTIAL_MAP
from allensdk.internal.api import db_connection_creator

    db_conn = db_connection_creator(
        fallback_credentials=LIMS_DB_CREDENTIAL_MAP)
    stimulus = BehaviorStimulusFile.from_lims(behavior_session_id=1192665673,
                                              db=db_conn)
    timestamps = StimulusTimestamps.from_stimulus_file(stimulus_file=stimulus,
                                                       monitor_delay=0.)
    fingerprint_stim = FingerprintStimulus.from_stimulus_file(
        stimulus_presentations=pd.DataFrame({'stimulus_block': [0]}),
        stimulus_file=stimulus,
        stimulus_timestamps=timestamps
    )
    print(fingerprint_stim.table.head())
>>> 
   movie_frame_index   start_time  ...  stimulus_block      stimulus_name
0                  0  4204.084593  ...               2  natural_movie_one
1                  1  4204.117957  ...               2  natural_movie_one
2                  2  4204.151355  ...               2  natural_movie_one
3                  3  4204.184677  ...               2  natural_movie_one
4                  4  4204.218040  ...               2  natural_movie_one

Other notable changes: adds stimulus_name and stimulus_block columns to denote stimulus block. Helpful for differentiating different blocks in a session.

Adds a column is_image_novel

This value is True when the mouse has not seen this image before, False when it has, and nan when it doesn't apply (i.e when the image was omitted or when it is not an image, i.e grating)

Other notable changes