allensdk.brain_observatory.receptive_field_analysis package

Submodules

allensdk.brain_observatory.receptive_field_analysis.chisquarerf module

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.NLL_to_pvalue(NLLs, log_base=10.0)[source]
allensdk.brain_observatory.receptive_field_analysis.chisquarerf.build_trial_matrix(LSN_template, num_trials, on_off_luminance=(255, 0))[source]

Construct indicator arrays for on/off pixels across trials.

Parameters:

LSN_template : np.ndarray

Dimensions are (nTrials, nYPixels, nXPixels). Luminance values per pixel and trial. The size of the first dimension may be larger than the num_trials argument (in which case only the first num_trials slices will be used) but may not be smaller.

num_trials : int

The number of trials (left-justified) to build indicators for.

on_off_luminance : array-like, optional

The zeroth element is the luminance value of a pixel when on, the first when off. Defaults are [255, 0].

Returns:

trial_mat : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}, nTrials). Boolean values indicate that a pixel was on/off on a particular trial.

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.chi_square_binary(events, LSN_template)[source]
allensdk.brain_observatory.receptive_field_analysis.chisquarerf.chi_square_within_mask(exclusion_mask, events_per_pixel, trials_per_pixel)[source]

Determine if cells respond preferentially to on/off pixels in a mask using a chi2 test.

Parameters:

exclusion_mask : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}). Integer indicator for INCLUSION (!) of a pixel within the testing region.

events_per_pixel : np.ndarray

Dimensions are (nCells, nYPixels, nXPixels, {on, off}). Integer values are response counts by cell to on/off luminance at each pixel.

trials_per_pixel : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}). Integer values are counts of trials where a pixel is on/off.

Returns:

p_vals : np.ndarray

One-dimensional, of length nCells. Float values are p-values for the hypothesis that a given cell has a receptive field within the exclusion mask.

chi : np.ndarray

Dimensions are (nCells, nYPixels, nXPixels, {on, off}). Values (float) are squared residual event counts divided by expected event counts.

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.deinterpolate_RF(rf_map, x_pnts, y_pnts, deg_per_pnt)[source]

Downsample an image

Parameters:

rf_map : np.ndarray

Input image

x_pnts : np.ndarray

Count of sample points along the first (column) axis

y_pnts : np.ndarray

Count of sample points along the zeroth (row) axis

deg_per_pnt : numeric

scale factor

Returns:

sampled_yx : np.ndarray

Downsampled image

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.get_disc_masks(LSN_template, radius=3, on_luminance=255, off_luminance=0)[source]

Obtain an indicator mask surrounding each pixel. The mask is a square, excluding pixels which are coactive on any trial with the main pixel.

Parameters:

LSN_template : np.ndarray

Dimensions are (nTrials, nYPixels, nXPixels). Luminance values per pixel and trial.

radius : int

The base mask will be a box whose sides are 2 * radius + 1 in length.

on_luminance : int, optional

The value of the luminance for on trials. Default is 255

off_luminance : int, optional

The value of the luminance for off trials. Default is 0

Returns:

masks : np.ndarray

Dimensions are (nYPixels, nXPixels, nYPixels, nXPixels). The first 2 dimensions describe the pixel from which the mask was computed. The last 2 serve as the dimensions of the mask images themselves. Masks are binary arrays of type float, with 1 indicating inside, 0 outside.

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.get_events_per_pixel(responses_np, trial_matrix)[source]

Obtain a matrix linking cellular responses to pixel activity.

Parameters:

responses_np : np.ndarray

Dimensions are (nTrials, nCells). Boolean values indicate presence/absence of a response on a given trial.

trial_matrix : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}, nTrials). Boolean values indicate that a pixel was on/off on a particular trial.

Returns:

events_per_pixel : np.ndarray

Dimensions are (nCells, nYPixels, nXPixels, {on, off}). Values for each cell, pixel, and on/off state are the sum of events for that cell across all trials where the pixel was in the on/off state.

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.get_expected_events_by_pixel(exclusion_mask, events_per_pixel, trials_per_pixel)[source]

Calculate expected number of events per pixel

Parameters:

exclusion_mask : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}). Integer indicator for INCLUSION (!) of a pixel within the testing region.

events_per_pixel : np.ndarray

Dimensions are (nCells, nYPixels, nXPixels, {on, off}). Integer values are response counts by cell to on/off luminance at each pixel.

trials_per_pixel : np.ndarray

Dimensions are (nYPixels, nXPixels, {on, off}). Integer values are counts of trials where a pixel is on/off.

Returns:

np.ndarray :

Dimensions (nCells, nYPixels, nXPixels, {on, off}). Float values are pixelwise counts of events expected if events are evenly distributed in mask across trials.

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.get_peak_significance(chi_square_grid_NLL, LSN_template, alpha=0.05)[source]
allensdk.brain_observatory.receptive_field_analysis.chisquarerf.interpolate_RF(rf_map, deg_per_pnt)[source]

Upsample an image

Parameters:

rf_map : np.ndarray

Input image

deg_per_pnt : numeric

scale factor

Returns:

interpolated : np.ndarray

Upsampled image

allensdk.brain_observatory.receptive_field_analysis.chisquarerf.locate_median(y, x)[source]
allensdk.brain_observatory.receptive_field_analysis.chisquarerf.pvalue_to_NLL(p_values, max_NLL=10.0)[source]
allensdk.brain_observatory.receptive_field_analysis.chisquarerf.smooth_STA(STA, gauss_std=0.75, total_degrees=64)[source]

Smooth an image by convolution with a gaussian kernel

Parameters:

STA : np.ndarray

Input image

gauss_std : numeric, optional

Standard deviation of the gaussian kernel. Will be applied to the upsampled image, so units are visual degrees. Default is 0.75

total_degrees : int, optional

Size in visual degrees of the input image along its zeroth (row) axis. Used to set the scale factor for up/downsampling.

Returns:

STA_smoothed : np.ndarray

Smoothed image

allensdk.brain_observatory.receptive_field_analysis.eventdetection module

allensdk.brain_observatory.receptive_field_analysis.eventdetection.detect_events(data, cell_index, stimulus, debug_plots=False)[source]

allensdk.brain_observatory.receptive_field_analysis.fit_parameters module

allensdk.brain_observatory.receptive_field_analysis.fit_parameters.add_to_fit_parameters_dict_single(fit_parameters_dict, p)[source]
allensdk.brain_observatory.receptive_field_analysis.fit_parameters.compute_distance(center_on, center_off)[source]
allensdk.brain_observatory.receptive_field_analysis.fit_parameters.compute_overlap(data_fitted_on, data_fitted_off)[source]
allensdk.brain_observatory.receptive_field_analysis.fit_parameters.get_gaussian_fit_single_channel(rf, fit_parameters_dict)[source]

allensdk.brain_observatory.receptive_field_analysis.fitgaussian2D module

exception allensdk.brain_observatory.receptive_field_analysis.fitgaussian2D.GaussianFitError[source]

Bases: exceptions.RuntimeError

allensdk.brain_observatory.receptive_field_analysis.fitgaussian2D.fitgaussian2D(data)[source]

Fit a 2D gaussian to an image

Parameters:

data : np.ndarray

input image

Returns:

p2 : list

height row mean column mean row standard deviation column standard deviation rotation

Notes

see gaussian2D for details about output values

allensdk.brain_observatory.receptive_field_analysis.fitgaussian2D.gaussian2D(height, center_x, center_y, width_x, width_y, rotation)[source]

Build a function which evaluates a scaled 2d gaussian pdf

Parameters:

height : float

scale factor

center_x : float

first coordinate of mean

center_y : float

second coordinate of mean

width_x : float

standard deviation along x axis

width_y : float

standard deviation along y axis

rotation : float

degrees clockwise by which to rotate the gaussian

Returns:

rotgauss: fn

parameters are x and y positions (row/column semantics are set by your inputs to this function). Return value is the scaled gaussian pdf evaluated at the argued point.

allensdk.brain_observatory.receptive_field_analysis.fitgaussian2D.moments2(data)[source]

Treating input image data as an independent multivariate gaussian, estimate mean and standard deviations

Parameters:

data : np.ndarray

2d numpy array.

Returns:

height : float

The maximum observed value in the data

y : float

Mean row index

x : float

Mean column index

width_y : float

The standard deviation along the mean row

width_x : float

The standard deviation along the mean column

None :

This function returns an instance of None.

Notes

uses original method from website for finding center

allensdk.brain_observatory.receptive_field_analysis.postprocessing module

allensdk.brain_observatory.receptive_field_analysis.postprocessing.get_gaussian_fit(rf)[source]
allensdk.brain_observatory.receptive_field_analysis.postprocessing.run_postprocessing(data, rf)[source]

allensdk.brain_observatory.receptive_field_analysis.receptive_field module

allensdk.brain_observatory.receptive_field_analysis.receptive_field.compute_receptive_field(data, cell_index, stimulus, **kwargs)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.compute_receptive_field_with_postprocessing(data, cell_index, stimulus, **kwargs)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.events_to_pvalues_no_fdr_correction(data, event_vector, A, number_of_shuffles=5000, response_detection_error_std_dev=0.1, seed=1)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.get_attribute_dict(rf)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.print_summary(rf)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.read_h5_group(g)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.read_receptive_field_from_h5(file_name, path=None)[source]
allensdk.brain_observatory.receptive_field_analysis.receptive_field.write_receptive_field_to_h5(rf, file_name, prefix='')[source]

allensdk.brain_observatory.receptive_field_analysis.tools module

allensdk.brain_observatory.receptive_field_analysis.tools.dict_generator(indict, pre=None)[source]
allensdk.brain_observatory.receptive_field_analysis.tools.list_of_dicts_to_dict_of_lists(list_of_dicts)[source]
allensdk.brain_observatory.receptive_field_analysis.tools.read_h5_group(g)[source]

allensdk.brain_observatory.receptive_field_analysis.utilities module

allensdk.brain_observatory.receptive_field_analysis.utilities.convolve(img, sigma=4)[source]

2D Gaussian convolution

allensdk.brain_observatory.receptive_field_analysis.utilities.get_A(*args, **kwargs)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.get_A_blur(*args, **kwargs)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.get_attribute_dict(rf)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.get_components(receptive_field_data)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.get_shuffle_matrix(data, event_vector, A, number_of_shuffles=5000, response_detection_error_std_dev=0.1)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.get_sparse_noise_epoch_mask_list(st, number_of_acquisition_frames, threshold=7)[source]
allensdk.brain_observatory.receptive_field_analysis.utilities.smooth(x, window_len=11, window='hanning', mode='valid')[source]

smooth the data using a window with requested size.

This method is based on the convolution of a scaled window with the signal. The signal is prepared by introducing reflected copies of the signal (with the window size) in both ends so that transient parts are minimized in the begining and end part of the output signal.

input:

x: the input signal window_len: the dimension of the smoothing window; should be an odd integer window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’

flat window will produce a moving average smoothing.
output:
the smoothed signal

example:

t=linspace(-2,2,0.1) x=sin(t)+randn(len(t))*0.1 y=smooth(x)

see also:

numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve scipy.signal.lfilter

TODO: the window parameter could be the window itself if an array instead of a string NOTE: length(output) != length(input), to correct this: return y[(window_len/2-1):-(window_len/2)] instead of just y.

allensdk.brain_observatory.receptive_field_analysis.utilities.upsample_image_to_degrees(img)[source]

allensdk.brain_observatory.receptive_field_analysis.visualization module

allensdk.brain_observatory.receptive_field_analysis.visualization.plot_chi_square_summary(rf_data, ax=None, cax=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_ellipses(gaussian_fit_dict, ax=None, show=True, close=True, save_file_name=None, color='b')[source]

Example Usage: oeid, cell_index, stimulus = 512176430, 12, ‘locally_sparse_noise’ brain_observatory_cache = BrainObservatoryCache() data_set = brain_observatory_cache.get_ophys_experiment_data(oeid) lsn = LocallySparseNoise(data_set, stimulus) result = compute_receptive_field_with_postprocessing(data_set, cell_index, stimulus, alpha=.05, number_of_shuffles=5000) plot_ellipses(result[‘off’][‘gaussian_fit’], color=’r’)

allensdk.brain_observatory.receptive_field_analysis.visualization.plot_fields(on_data, off_data, on_axes, off_axes, cbar_axes=None, clim=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_gaussian_fit(rf_data, ax_on, ax_off, ax_cbar=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_mask(rf_data, ax_on, ax_off, ax_cbar=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_msr_summary(lsn, cell_index, ax_on, ax_off, ax_cbar=None, cmap=None)[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_p_values(rf_data, ax_on, ax_off, ax_cbar=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_receptive_field_data(rf, lsn, show=True, save_file_name=None, close=True, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_rts_blur_summary(rf_data, ax_on, ax_off, ax_cbar=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.plot_rts_summary(rf_data, ax_on, ax_off, ax_cbar=None, cmap='magma')[source]
allensdk.brain_observatory.receptive_field_analysis.visualization.pvalue_to_NLL(p_values, max_NLL=10.0)[source]

Module contents