allensdk.core.brain_observatory_nwb_data_set module

class allensdk.core.brain_observatory_nwb_data_set.BrainObservatoryNwbDataSet(nwb_file)[source]

Bases: object

FILE_METADATA_MAPPING = {'age': 'general/subject/age', 'device_string': 'general/devices/2-photon microscope', 'excitation_lambda': 'general/optophysiology/imaging_plane_1/excitation_lambda', 'experiment_container_id': 'general/experiment_container_id', 'fov': 'general/fov', 'generated_by': 'general/generated_by', 'genotype': 'general/subject/genotype', 'imaging_depth': 'general/optophysiology/imaging_plane_1/imaging depth', 'indicator': 'general/optophysiology/imaging_plane_1/indicator', 'ophys_experiment_id': 'general/session_id', 'session_start_time': 'session_start_time', 'session_type': 'general/session_type', 'sex': 'general/subject/sex', 'specimen_name': 'general/specimen_name', 'targeted_structure': 'general/optophysiology/imaging_plane_1/location'}
MOTION_CORRECTION_DATASETS = ['MotionCorrection/2p_image_series/xy_translations', 'MotionCorrection/2p_image_series/xy_translation']
PIPELINE_DATASET = 'brain_observatory_pipeline'
STIMULUS_TABLE_TYPES = {'abstract_feature_series': ['drifting_gratings', 'static_gratings'], 'indexed_time_series': ['natural_scenes', 'locally_sparse_noise', 'locally_sparse_noise_4deg', 'locally_sparse_noise_8deg'], 'repeated_indexed_time_series': ['natural_movie_one', 'natural_movie_two', 'natural_movie_three']}
SUPPORTED_PIPELINE_VERSION = '2.0'
get_cell_specimen_ids()[source]

Returns an array of cell IDs for all cells in the file

Returns:
cell specimen IDs: list
get_cell_specimen_indices(cell_specimen_ids)[source]

Given a list of cell specimen ids, return their index based on their order in this file.

Parameters:
cell_specimen_ids: list of cell specimen ids
get_corrected_fluorescence_traces(cell_specimen_ids=None)[source]

Returns an array of demixed and neuropil-corrected fluorescence traces for all ROIs and the timestamps for each datapoint

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then all are returned

Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

traces: 2D numpy array

Corrected fluorescence traces for each cell

get_demixed_traces(cell_specimen_ids=None)[source]

Returns an array of demixed fluorescence traces for all ROIs and the timestamps for each datapoint

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then all are returned

Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

traces: 2D numpy array

Demixed fluorescence traces for each cell

get_dff_traces(cell_specimen_ids=None)[source]

Returns an array of dF/F traces for all ROIs and the timestamps for each datapoint

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return data for. If this is None (default) then all are returned

Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

dF/F: 2D numpy array

dF/F values for each cell

get_fluorescence_timestamps()[source]

Returns an array of timestamps in seconds for the fluorescence traces

get_fluorescence_traces(cell_specimen_ids=None)[source]

Returns an array of fluorescence traces for all ROI and the timestamps for each datapoint

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then all are returned

Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

traces: 2D numpy array

Fluorescence traces for each cell

get_locally_sparse_noise_stimulus_template(stimulus, mask_off_screen=True)[source]

Return an array of the stimulus template for the specified stimulus.

Parameters:
stimulus: string
Which locally sparse noise stimulus to retrieve. Must be one of:

stimulus_info.LOCALLY_SPARSE_NOISE stimulus_info.LOCALLY_SPARSE_NOISE_4DEG stimulus_info.LOCALLY_SPARSE_NOISE_8DEG

mask_off_screen: boolean

Set off-screen regions of the stimulus to LocallySparseNoise.LSN_OFF_SCREEN.

Returns:
tuple: (template, off-screen mask)
get_max_projection()[source]

Returns the maximum projection image for the 2P movie.

Returns:
max projection: np.ndarray
get_metadata()[source]

Returns a dictionary of meta data associated with each experiment, including Cre line, specimen number, visual area imaged, imaging depth

Returns:
metadata: dictionary
get_motion_correction()[source]

Returns a Panda DataFrame containing the x- and y- translation of each image used for image alignment

get_neuropil_r(cell_specimen_ids=None)[source]

Returns a scalar value of r for neuropil correction of flourescence traces

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then results for all are returned

Returns:
r: 1D numpy array, len(r)=len(cell_specimen_ids)

Scalar for neuropil subtraction for each cell

get_neuropil_traces(cell_specimen_ids=None)[source]

Returns an array of neuropil fluorescence traces for all ROIs and the timestamps for each datapoint

Parameters:
cell_specimen_ids: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then all are returned

Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

traces: 2D numpy array

Neuropil fluorescence traces for each cell

get_pupil_location(as_spherical=True)[source]

Returns the x, y pupil location.

Parameters:
as_spherical : bool

Whether to return the location as spherical (default) or not. If true, the result is altitude and azimuth in degrees, otherwise it is x, y in centimeters. (0,0) is the center of the monitor.

Returns:
(timestamps, location)

Timestamps is an (Nx1) array of timestamps in seconds. Location is an (Nx2) array of spatial location.

get_pupil_size()[source]

Returns the pupil area in pixels.

Returns:
(timestamps, areas)

Timestamps is an (Nx1) array of timestamps in seconds. Areas is an (Nx1) array of pupil areas in pixels.

get_roi_ids()[source]

Returns an array of IDs for all ROIs in the file

Returns:
ROI IDs: list
get_roi_mask(cell_specimen_ids=None)[source]

Returns an array of all the ROI masks

Parameters:
cell specimen IDs: list or array (optional)

List of cell IDs to return traces for. If this is None (default) then all are returned

Returns:
List of ROI_Mask objects
get_roi_mask_array(cell_specimen_ids=None)[source]

Return a numpy array containing all of the ROI masks for requested cells. If cell_specimen_ids is omitted, return all masks.

Parameters:
cell_specimen_ids: list

List of cell specimen ids. Default None.

Returns:
np.ndarray: NxWxH array, where N is number of cells
get_running_speed()[source]

Returns the mouse running speed in cm/s

get_session_type()[source]

Returns the type of experimental session, presently one of the following: three_session_A, three_session_B, three_session_C

Returns:
session type: string
get_spontaneous_activity_stimulus_table(**kwargs)[source]

Return the spontaneous activity stimulus table, if it exists.

Returns:
stimulus table: pd.DataFrame
get_stimulus(frame_ind)[source]
get_stimulus_epoch_table()[source]

Returns a pandas dataframe that summarizes the stimulus epoch duration for each acquisition time index in the experiment

Parameters:
None
Returns:
timestamps: 2D numpy array

Timestamp for each fluorescence sample

traces: 2D numpy array

Fluorescence traces for each cell

get_stimulus_table(stimulus_name)[source]

Return a stimulus table given a stimulus name

Notes

For more information, see: http://help.brain-map.org/display/observatory/Documentation?preview=/10616846/10813485/VisualCoding_VisualStimuli.pdf

get_stimulus_template(**kwargs)[source]

Return an array of the stimulus template for the specified stimulus.

Parameters:
stimulus_name: string

Must be one of the strings returned by list_stimuli().

Returns:
stimulus table: pd.DataFrame
list_stimuli()[source]

Return a list of the stimuli presented in the experiment.

Returns:
stimuli: list of strings
number_of_cells

Number of cells in the experiment

save_analysis_arrays(*datasets)[source]
save_analysis_dataframes(*tables)[source]
allensdk.core.brain_observatory_nwb_data_set.align_running_speed(dxcm, dxtime, timestamps)[source]

If running speed timestamps differ from fluorescence timestamps, adjust by inserting NaNs to running speed.

Returns:
tuple: dxcm, dxtime
allensdk.core.brain_observatory_nwb_data_set.get_epoch_mask_list(st, threshold, max_cuts=2)[source]

Convenience function to cut a stim table into multiple epochs

Parameters:
  • st – input stimtable
  • threshold – threshold on the max duration of a subepoch
  • max_cuts – maximum number of allowed epochs to cut into
Returns:

epoch_mask_list, a list of indices that define the start and end of sub-epochs

allensdk.core.brain_observatory_nwb_data_set.make_display_mask(*args, **kwargs)[source]
allensdk.core.brain_observatory_nwb_data_set.mask_stimulus_template(*args, **kwargs)[source]
allensdk.core.brain_observatory_nwb_data_set.warp_stimulus_coords(*args, **kwargs)[source]