Source code for allensdk.brain_observatory.behavior.data_objects.stimuli.stimuli

from typing import List, Optional

from allensdk.brain_observatory.behavior.data_files import BehaviorStimulusFile
from allensdk.brain_observatory.behavior.data_files.stimulus_file import (
    StimulusFileReadableInterface,
)
from allensdk.brain_observatory.behavior.data_objects import StimulusTimestamps
from allensdk.brain_observatory.behavior.data_objects.metadata.behavior_metadata.project_code import (  # noqa: E501
    ProjectCode,
)
from allensdk.brain_observatory.behavior.data_objects.stimuli.presentations import (  # noqa: E501
    Presentations,
)
from allensdk.brain_observatory.behavior.data_objects.stimuli.templates import (  # noqa: E501
    Templates,
)
from allensdk.brain_observatory.behavior.data_objects.trials.trials import (
    Trials,
)
from allensdk.core import (
    DataObject,
    NwbReadableInterface,
    NwbWritableInterface,
)
from pynwb import NWBFile


[docs] class Stimuli( DataObject, StimulusFileReadableInterface, NwbReadableInterface, NwbWritableInterface, ): def __init__(self, presentations: Presentations, templates: Templates): super().__init__(name="stimuli", value=None, is_value_self=True) self._presentations = presentations self._templates = templates @property def presentations(self) -> Presentations: return self._presentations @property def templates(self) -> Templates: return self._templates
[docs] @classmethod def from_nwb( cls, nwbfile: NWBFile, presentation_columns: Optional[List[str]] = None, add_is_change_to_presentations_table=True, ) -> "Stimuli": p = Presentations.from_nwb( nwbfile=nwbfile, column_list=presentation_columns, add_is_change=add_is_change_to_presentations_table, ) t = Templates.from_nwb(nwbfile=nwbfile) return Stimuli(presentations=p, templates=t)
[docs] @classmethod def from_stimulus_file( cls, stimulus_file: BehaviorStimulusFile, stimulus_timestamps: StimulusTimestamps, behavior_session_id: int, trials: Trials, limit_to_images: Optional[List] = None, presentation_columns: Optional[List[str]] = None, presentation_fill_omitted_values: bool = True, project_code: Optional[ProjectCode] = None, load_stimulus_movie: bool = False ) -> "Stimuli": """ Parameters ---------- stimulus_file: BehaviorStimulusFile Input stimulus file for the session. stimulus_timestamps: StimulusTimestamps Stimulus timestamps for the session. trials: Trials Trials object to add trials_id column into the presentations data frame to allow for merging between the two tables. behavior_session_id behavior session id in LIMS limit_to_images: limit to certain images. Used for testing. presentation_columns: The columns and order of columns in the final presentations dataframe presentation_fill_omitted_values: Whether to fill stop_time and duration for omitted frames project_code : ProjectCode For released datasets, provide a project code to produce explicitly named stimulus_block column values in the column stimulus_block_name load_stimulus_movie : bool Whether to load the stimulus movie (e.g natrual_movie_one) as part of loading stimuli. Default False. Returns ------- """ p = Presentations.from_stimulus_file( stimulus_file=stimulus_file, stimulus_timestamps=stimulus_timestamps, behavior_session_id=behavior_session_id, limit_to_images=limit_to_images, column_list=presentation_columns, fill_omitted_values=presentation_fill_omitted_values, project_code=project_code, trials=trials, ) t = Templates.from_stimulus_file( stimulus_file=stimulus_file, limit_to_images=limit_to_images, load_stimulus_movie=load_stimulus_movie ) return Stimuli(presentations=p, templates=t)
[docs] def to_nwb( self, nwbfile: NWBFile, presentations_stimulus_column_name="stimulus_name", ) -> NWBFile: """ Parameters ---------- nwbfile presentations_stimulus_column_name: Name of the column in the presentations table that denotes the stimulus name Returns ------- NWBFile """ nwbfile = self._templates.to_nwb( nwbfile=nwbfile, stimulus_presentations=self._presentations ) nwbfile = self._presentations.to_nwb( nwbfile=nwbfile, stimulus_name_column=presentations_stimulus_column_name, ) return nwbfile