allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping module

class allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.ReceptiveFieldMapping(ecephys_session, col_pos_x='x_position', col_pos_y='y_position', trial_duration=0.25, minimum_spike_count=10.0, mask_threshold=0.5, **kwargs)[source]

Bases: allensdk.brain_observatory.ecephys.stimulus_analysis.stimulus_analysis.StimulusAnalysis

A class for computing single-unit metrics from the receptive field mapping stimulus of an ecephys session NWB file.

To use, pass in a EcephysSession object::
session = EcephysSession.from_nwb_path(‘/path/to/my.nwb’) rf_analysis = ReceptiveFieldMapping(session)
or, alternatively, pass in the file path::
rf_analysis = ReceptiveFieldMapping(‘/path/to/my.nwb’)

You can also pass in a unit filter dictionary which will only select units with certain properties. For example to get only those units which are on probe C and found in the VISp area:

rf_analysis = ReceptiveFieldMapping(session, filter={'location': 'probeC', 'ecephys_structure_acronym': 'VISp'})
To get a table of the individual unit metrics ranked by unit ID::
metrics_table_df = rf_analysis.metrics()
METRICS_COLUMNS
azimuths

Array of stimulus azimuths

elevations

Array of stimulus elevations

get_receptive_field(self, unit_id)[source]

Alias for _get_rf

classmethod known_stimulus_keys()[source]

Used for discovering the correct stimulus_name key for a given StimulusAnalysis subclass (when stimulus_key is not explicity set). Should return a list of “stimulus_name” strings.

metrics

Returns a pandas DataFrame of the stimulus response metrics for each unit.

name

Return the stimulus name.

null_condition

Stimulus condition ID for null stimulus (not used, so set to -1)

number_azimuths

Number of stimulus azimuths

number_elevations

Number of stimulus elevations

plot_raster(self, stimulus_condition_id, unit_id)[source]

Plot raster for one condition and one unit

plot_rf(self, unit_id)[source]

Plot the spike counts across conditions

receptive_fields

Spatial receptive fields for N units (9 x 9 x N matrix of responses)

allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.convert_azimuth_to_degrees(azimuth_in_pixels, azimuth_offset_degrees=10)[source]

Converts a pixel-based azimuth into degrees relative to center of gaze

Parameters:
azimuth_in_pixels : float
azimuth_offset_degrees: float
Returns:
azimuth_in_degrees : float
allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.convert_elevation_to_degrees(elevation_in_pixels, elevation_offset_degrees=-30)[source]

Converts a pixel-based elevation into degrees relative to center of gaze

The receptive field computed by this class is oriented such that the pixel values are in the correct relative location when using matplotlib.pyplot.imshow(), which places (0,0) in the upper-left corner of the figure.

Therefore, we need to invert the elevation value prior to converting to degrees.

Parameters:
elevation_in_pixels : float
elevation_offset_degrees: float
Returns:
elevation_in_degrees : float
allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.convert_pixel_area_to_degrees(area_in_pixels)[source]

Converts a pixel-based area measure into degrees

Each pixel is a square with side of length <degrees_to_pixels_ratio>

So the area in degrees is area_in_pixels * <degrees to_pixels_ratio>^2

Parameters:
area_in_pixels : float
Returns:
area_in_degrees : float
allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.convert_pixels_to_degrees(value_in_pixels, degrees_to_pixels_ratio=10)[source]

Converts a pixel-based distance into degrees

Parameters:
value_in_pixels : float
degrees_to_pixels_ratio: float
Returns:
value in degrees : float
allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.fit_2d_gaussian(matrix)[source]

Fits a receptive field with a 2-dimensional Gaussian distribution

Parameters:
matrix : numpy.ndarray

2D matrix of spike counts

Returns:
parameters - tuple

peak_height : peak of distribution center_y : y-coordinate of distribution center center_x : x-coordinate of distribution center width_y : width of distribution along x-axis width_x : width of distribution along y-axis

success - bool

True if a fit was found, False otherwise

allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.gaussian_moments_2d(data)[source]

Finds the moments of a 2D Gaussian distribution, given an input matrix

Parameters:
data : numpy.ndarray

2D matrix

Returns:
peak_height :

peak of distribution

center_y :

y-coordinate of distribution center

center_x :

x-coordinate of distribution center

width_y :

width of distribution along x-axis

width_x :

width of distribution along y-axis

allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.invert_rf(rf)[source]

Creates an inverted version of the receptive field

Parameters:
rf - matrix of spike counts at each stimulus position
Returns:
rf_inverted - new RF matrix
allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.is_rf_inverted(rf_thresh)[source]

Checks if the receptive field mapping timulus is suppressing or exciting the cell

Parameters:
rf_thresh : matrix

matrix of spike counts at each stimulus position

Returns:
if_rf_inverted : bool

True if the receptive field is inverted

allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.rf_on_screen(rf, center_y, center_x)[source]

Checks whether the receptive field is on the screen, given the center location.

allensdk.brain_observatory.ecephys.stimulus_analysis.receptive_field_mapping.threshold_rf(rf, threshold)[source]

Creates a spatial mask based on the receptive field peak, and returns the x, y coordinates of the center of mass, as well as the area.

Parameters:
rf : numpy.ndarray

2D matrix of spike counts

threshold : float

Threshold as ratio of the RF’s standard deviation

Returns:
threshold_rf : numpy.ndarray

Thresholded version of the original RF

center_x : float

x-coordinate of mask center of mass

center_y : float

y-coordinate of mask center of mass

area : float

area of mask