Attention

This documentation is for the Mesmerize legacy desktop application. Please see the home page or GitHub repo for information on the latest packages.

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: DataFrame)[source]

Set the stimulus map

Parameters:

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

get_dataframe() 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[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[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

import pandas as pd
from mesmerize.plotting.utils import get_colormap

# Load dataframe from CSV
df = pd.read_csv('path_to_csv_file')

# Sort according to time
df.sort_values(by='start').reset_index(drop=True, inplace=True)

# Trim off the stimulus periods that are not in the current image sequence
trim = get_image().shape[2]
df = df[df['start'] <= trim]

# get one dataframe for each of the stimulus types
ori_df = df.drop(columns=['sf', 'tf', 'contrast'])  # contains ori stims
sf_df = df.drop(columns=['ori', 'tf', 'contrast'])  # contains sf stims
tf_df = df.drop(columns=['sf', 'ori', 'contrast'])  # contains tf stims

# Rename the stimulus column of interest to "name"
ori_df.rename(columns={'ori': 'name'}, inplace=True)
sf_df.rename(columns={'sf': 'name'}, inplace=True)
tf_df.rename(columns={'tf': 'name'}, inplace=True)


# Get the stimulus mapping module
smm = get_module('stimulus_mapping')

# set the stimulus map in Mesmerize for each of the 3 stimulus types
for stim_type, _df in zip(['ori', 'sf', 'tf'], [ori_df, sf_df, tf_df]):
    # data in the name column must be `str` type for stimulus mapping module
    _df['name'] = _df['name'].apply(str)

    # Get the names of the stimulus periods
    stimuli = _df['name'].unique()
    stimuli.sort()

    # Create colormap with the stimulus names
    stimuli_cmap = get_colormap(stimuli, 'tab10', output='pyqt', alpha=0.6)

    # Create a column with colors that correspond to the stimulus names
    # This is for illustrating the stimulus periods in the viewer plot
    _df['color'] = _df['name'].map(stimuli_cmap)

    # Set the data in the Stimulus Mapping module
    smm.maps[stim_type].set_data(_df)