allensdk.brain_observatory.behavior.data_objects.stimuli.presentations module

class allensdk.brain_observatory.behavior.data_objects.stimuli.presentations.Presentations(presentations: DataFrame, columns_to_rename: Dict[str, str] | None = None, column_list: List[str] | None = None, sort_columns: bool = True, trials: Trials | None = None)[source]

Bases: DataObject, StimulusFileReadableInterface, NwbReadableInterface, NwbWritableInterface

Stimulus presentations

classmethod from_nwb(nwbfile: NWBFile, add_is_change: bool = True, add_trials_dependent_values: bool = True, column_list: List[str] | None = None) Presentations[source]
Parameters:
nwbfile
add_is_change: Whether to add a column denoting whether the current

row represents a stimulus in which there was a change event

column_list: The columns and order of columns

in the final dataframe.

Returns:
Presentations instance
classmethod from_path(path: str | Path, behavior_session_id: int, exclude_columns: List[str] | None = None, columns_to_rename: Dict[str, str] | None = None, sort_columns: bool = True, trials: Trials | None = None) Presentations[source]

Reads the table directly from a precomputed csv

Parameters:
path: Path to load table from
behavior_session_id

LIMS behavior session id

exclude_columns: Columns to exclude
columns_to_rename: Optional d ict mapping

old column name -> new column name

sort_columns: Whether to sort the columns by name
Returns:
Presentations instance
classmethod from_stimulus_file(stimulus_file: BehaviorStimulusFile, stimulus_timestamps: StimulusTimestamps, behavior_session_id: int, trials: Trials, limit_to_images: List | None = None, column_list: List[str] | None = None, fill_omitted_values: bool = True, project_code: ProjectCode | None = None) Presentations[source]

Get stimulus presentation data.

Parameters:
stimulus_fileBehaviorStimulusFile

Input stimulus_file to create presentations dataframe from.

stimulus_timestampsStimulusTimestamps

Timestamps of the stimuli

behavior_session_idint

LIMS id of behavior session

trials: Trials

Object to create trials_id column in Presentations table allowing for mering of the two tables.

limit_to_imagesOptional, list of str

Only return images given by these image names

column_listOptional, list of str

The columns and order of columns in the final dataframe

fill_omitted_valuesOptional, bool

Whether to fill stop_time and duration for omitted frames

project_code: Optional, ProjectCode

For released datasets, provide a project code to produce explicitly named stimulus_block column values in the column stimulus_block_name

Returns:
output_presentations: Presentations

Object with a table whose rows are stimulus presentations (i.e. a given image, for a given duration, typically 250 ms) and whose columns are presentation characteristics.

to_nwb(nwbfile: NWBFile, stimulus_name_column='stimulus_name') NWBFile[source]

Adds a stimulus table (defining stimulus characteristics for each time point in a session) to an nwbfile as TimeIntervals.

Parameters:
nwbfile
stimulus_name_column: The column in the dataframe denoting the

stimulus name

allensdk.brain_observatory.behavior.data_objects.stimuli.presentations.get_spontaneous_block_indices(stimulus_blocks: ndarray) ndarray[source]

Gets the indices where there is a gap in stimulus block. This is where spontaneous blocks are. Example: stimulus blocks are [0, 2, 3]. There is a spontaneous block at 1.

Parameters:
stimulus_blocks: Stimulus blocks in the stimulus presentations table
Returns:
np.array: spontaneous stimulus blocks

Notes

This doesn’t support a spontaneous block appearing at the beginning or end of a session