Stimulus Mapping

ModuleGUI

class mesmerize.viewer.modules.stimulus_mapping.ModuleGUI(parent, viewer)[source]
property maps: dict

Returns a dictionary of the stimulus maps

Page

Each Page instance contains the mapping data for one stimulus type

class mesmerize.viewer.modules.stimmap_modules.page.Page(parent, stim_type: str)[source]
set_data(dataframe: pandas.core.frame.DataFrame)[source]

Set the stimulus map

Parameters

dataframe – DataFrame with the appropriate rows (see add_row())

get_dataframe() pandas.core.frame.DataFrame[source]

Get the stimulus map as a DataFrame

set_units(units: str)[source]

Set the time units

Parameters

units – One of ‘frames’ or ‘seconds’

get_units() str[source]

Get the time units

add_row(pd_series: Optional[pandas.core.series.Series] = None)[source]

Add a row to the stimulus map

Parameters

pd_series – pandas series containing the following: stimulus name, start, end, and color

Returns

delete_row(row: Union[mesmerize.viewer.modules.stimmap_modules.row.Row, int])[source]

Delete a row from the stimulus map

Parameters

row – The Row object to remove or the numerical index of the row

clear()[source]

Clear the stimulus map

DataFrame Format

Page.set_data() expects a DataFrame in the following format

Columns

Column

Description

name

Stimulus name

start

Start time of stimulus period

end

End time of stimulus period

color

Color to display in the viewer curve plot

Data types:

Column

Data type

name

str

start

numpy.float64

end

numpy.float64

color

Tuple in RGBA format

(int, int, int, int)
Each int must be within the 0 - 255 range

Example

name

start

end

color

control

0.0

328.0

(0, 75, 0, 255)

stim_A

328.0

1156.0

(0, 0, 125, 255)

stim_C

1156.0

2987.0

(125, 0, 0, 255)

Example

This example creates a pandas DataFrame from a csv file to set the stimulus mappings. It uses the csv file from the pvc-7 dataset availble on CRCNS: http://dx.doi.org/10.6080/K0C8276G

You can also download the csv here: stimulus_pvc7.csv

This example is meant to be run through the Viewer Script Editor

 1import pandas as pd
 2from mesmerize.plotting.utils import get_colormap
 3
 4# Load dataframe from CSV
 5df = pd.read_csv('path_to_csv_file')
 6
 7# Sort according to time
 8df.sort_values(by='start').reset_index(drop=True, inplace=True)
 9
10# Trim off the stimulus periods that are not in the current image sequence
11trim = get_image().shape[2]
12df = df[df['start'] <= trim]
13
14# get one dataframe for each of the stimulus types
15ori_df = df.drop(columns=['sf', 'tf', 'contrast'])  # contains ori stims
16sf_df = df.drop(columns=['ori', 'tf', 'contrast'])  # contains sf stims
17tf_df = df.drop(columns=['sf', 'ori', 'contrast'])  # contains tf stims
18
19# Rename the stimulus column of interest to "name"
20ori_df.rename(columns={'ori': 'name'}, inplace=True)
21sf_df.rename(columns={'sf': 'name'}, inplace=True)
22tf_df.rename(columns={'tf': 'name'}, inplace=True)
23
24
25# Get the stimulus mapping module
26smm = get_module('stimulus_mapping')
27
28# set the stimulus map in Mesmerize for each of the 3 stimulus types
29for stim_type, _df in zip(['ori', 'sf', 'tf'], [ori_df, sf_df, tf_df]):
30    # data in the name column must be `str` type for stimulus mapping module
31    _df['name'] = _df['name'].apply(str)
32
33    # Get the names of the stimulus periods
34    stimuli = _df['name'].unique()
35    stimuli.sort()
36
37    # Create colormap with the stimulus names
38    stimuli_cmap = get_colormap(stimuli, 'tab10', output='pyqt', alpha=0.6)
39
40    # Create a column with colors that correspond to the stimulus names
41    # This is for illustrating the stimulus periods in the viewer plot
42    _df['color'] = _df['name'].map(stimuli_cmap)
43
44    # Set the data in the Stimulus Mapping module
45    smm.maps[stim_type].set_data(_df)