Processing the different stream of data to calculate responses of retinal cells

Spatial stimulus (checkerboard)

eyetrack_stim_inten[source]

eyetrack_stim_inten(stim_inten, eye_track, upsampling=2, eye_calib=[[94, 8], [18, 59]], box_w=None, box_h=None, stim_axis='x')

From stimulus data and eye tracking, returns a corrected and upsampled stimulus data. Calibration corresponds to the width and height of the stimulus screen, in terms of pixels in the eye video: [[WIDTH_x, WIDTH_y], [HEIGHT_x, HEIGHT_y]]

params:

- stim_inten: Stimulus intensity matrix of shape (t, y, x), or (t, x) or (t, y) depending on stim_axis
- eye_track: Eye tracking data of shape (t, x_pos, y_pos, ...)
- upsampling: Factor for the upsampling (2 will multiply by 2 number of box in width and height)
- eye_calib: Calibration matrix of shape (2,2)
- box_w: Width of a block in pixel (40px in case of a 32 box in width of a checkerboard on a 1280px width)
- box_h: Height of a block in pixel. Both box_x and box_h are calculated from a 1280x720 screen if None
- stim_axis: Specify which direction to shift in case of stim shape different than (t, y, x)

return:

- Upsampled and shift corrected stimulus intensity

saccade_distances[source]

saccade_distances(eye_track)

Create a mask for the eye position timeserie that indicate how far was the last saccade. The eye positions need to be smoothed with smooth_eye_position.

params:

- eye_track: Eye tracking data of shape (t, x_pos, y_pos, ...)

return:

- Distance to last saccade array

smooth_eye_position[source]

smooth_eye_position(eye_track, threshold=2)

Smooth the eye positions. Uses clustering of eye position epochs to smooth. Clustering is made with sklearn.cluster.dbscan.

params:

- eye_track: Eye tracking data of shape (t, x_pos, y_pos, ...)
- threshold: Distance threshold in the position clustering

return:

- Distance to last saccade array

process_sta_batch[source]

process_sta_batch(stim_inten, spike_counts, Hw=30, Fw=2, return_pval=False, normalisation='abs')

Computes the STA and associated pvalues in parallel for a batch of cells.

params:

- stim_inten: stimulus intensity matrix of shape (t, ...)
- spike_counts: cells activity matrix of shape (t, n_cell)
- Hw: Lenght in frames of the history window, including the 0 timepoint
- Fw: Lenght in frames of the forward window
- return_pval: Flag to signal whether or not to return the pvalues
- normalisation: Normalization applied to the STA. One of ["abs", "L2", None]

return:

- stas of shape (n_cell, Hw+Fw, ...)
- stas and pvalues if return_pval=True, both of shape (n_cell, Hw+Fw, ...)

staEst_fromBins[source]

staEst_fromBins(stim, spike_counts, Hw, Fw=0)

Matrix mutliplication to compute the STA. Use the wrapper process_sta_batch to avoid bugs.

params:

- stim_inten: stimulus intensity matrix of shape (flattened_frame, t)
- spike_counts: cells activity matrix of shape (t, n_cell)
- Hw: Lenght in frames of the history window, including the 0 timepoint
- Fw: Lenght in frames of the forward window

return:

- STA of shape (n_cell, Hw+Fw, flattened_frame)

process_sta_batch_large[source]

process_sta_batch_large(stim_inten, spike_counts, Hw=30, Fw=2, return_pval=False, normalisation='abs', bs=1000)

Computes the STA and associated pvalues in parallel for a batch of cells, for a large stimulus.

params:

- stim_inten: stimulus intensity matrix of shape (t, ...)
- spike_counts: cells activity matrix of shape (t, n_cell)
- Hw: Lenght in frames of the history window, including the 0 timepoint
- Fw: Lenght in frames of the forward window
- return_pval: Flag to signal whether or not to return the pvalues
- normalisation: Normalization applied to the STA. One of ["abs", "L2", None]
- bs: batch size to compute partial STA

return:

- stas of shape (n_cell, Hw+Fw, ...)
- stas and pvalues if return_pval=True, both of shape (n_cell, Hw+Fw, ...)

cross_correlation[source]

cross_correlation(spike_counts, tail_len=100)

From calculate the cross correlation of the cells over a time window.

params:

- spike_counts of shape (t, n_cell)
- tail_len: time correlation window size

return:

- cross correlation between the cells

corrcoef[source]

corrcoef(spike_counts)

Computes correlation coefficient between the cells

params:

- spike_counts: Cells activity of shape (t, n_cell)

return:

- Correlation matrix

flatten_corrcoef[source]

flatten_corrcoef(corrcoef_matrix)

Retrieves a one dimensional array of the cells correlations

params:

- corrcoef_matrix: Correlation matrix from [`corrcoef`](/theonerig/processing.html#corrcoef)

return:

- flattened correlation matrix

stimulus_ensemble[source]

stimulus_ensemble(stim_inten, Hw=30, x=0, y=0, w=None, h=None)

Generate the stimulus ensemble used to compute the nonlinearity

params:

- stim_inten: stimulus intensity matrix of shape (t, ...)
- Hw: Lenght in frames of the history window, including the 0 timepoint
- x: Left position of the window where to get the ensemble from
- y: Up position of the window where to get the ensemble from
- w: Width of the window where to get the ensemble from. If None, is set to stim_inten.shape[2]
- h: Height of the window where to get the ensemble from. If None, is set to stim_inten.shape[1]

return:

- Flatten stimulus ensemble of size (len(stim_inten)-(Hw-1), w*h*Hw). To obtain the corresponding cell activity,
slice it like so: slice(Hw-1, None)

process_nonlinearity[source]

process_nonlinearity(stim_inten, spike_counts, bins, stas, p_norm=2)

Computes the nonlinearity of a single cell. The STA of the cell is in L2 normalization, which should restrict the histogram values.

params:

- stim_inten: stimulus intensity in shape (t, y, x)
- spike_counts: cells activity in shape (t, n_cell)
- bins: bins in which the transformed stimuli ensembles are set. (usually between -6 and 6)
- stas:  The STAs to convolve with stim_inten in shape (n_cell, Hw, ...)
- p_norm: Power for the normalization. https://en.wikipedia.org/wiki/Norm_(mathematics)#p-norm :
    1 -> can compare nonlinearites of stimuli with different dimensionality
    2 -> Common L2 normalization for STAs

return:

- nonlinearity of the cell.

activity_histogram[source]

activity_histogram(spike_counts)

Retrieve an histogram of the individual cells activity.

params:

- spike_counts: cells activity matrix of shape (t, n_cell)

return:

- Cells activity histogram

cross_distances[source]

cross_distances(masks)

Computes cross distances from the center of mass of a list of mask.

params:

- masks: cells mask of shape (n_mask, y, x)

return:

- cross distances matrix

cross_distances_sta[source]

cross_distances_sta(fits, sta_shape, f)

Computes cross distances between STAs

params:

- fits: fits of STA to compare
- sta_shape: shape of the STA
- f: function used to compute the stas from the fits parameters

return:

- cross distances matrix

paired_distances[source]

paired_distances(masks_1, masks_2)

Compute the distance between two masks

params:

- masks_1: Mask of the first cell
- masks_2: Mask of the second cell

return:

- distance between the two masks

paired_distances_sta[source]

paired_distances_sta(sta_fits_1, sta_fits_2, sta_shape, f)

Compute the distance between two STAs.

params:

- sta_fits_1: fits of STA of the first cell
- sta_fits_2: fits of STA of the second cell
- sta_shape: shape of the STA
- f: function used to compute the stas from the fits parameters

return:

- distance between the two STAs

Direction and orientation selectivity with imaginary numbers

We have 8 angles

n_angle = 8
x = np.linspace(0, (n_angle-1)/4*np.pi, num=n_angle)
print(x)
[0.         0.78539816 1.57079633 2.35619449 3.14159265 3.92699082
 4.71238898 5.49778714]

Exponentiating those and multiplying with 0+1i will wind up the angles around the origin in imag number space

vectors = np.exp(x*1j)
print(vectors)
[ 1.00000000e+00+0.00000000e+00j  7.07106781e-01+7.07106781e-01j
  6.12323400e-17+1.00000000e+00j -7.07106781e-01+7.07106781e-01j
 -1.00000000e+00+1.22464680e-16j -7.07106781e-01-7.07106781e-01j
 -1.83697020e-16-1.00000000e+00j  7.07106781e-01-7.07106781e-01j]

And so multiplying by two before exponentiation double the angle of the arrow. It gives to originally opposite vectors the same direction -> good to calculate orientation selectivity

import matplotlib.pyplot as plt
colors = plt.rcParams["axes.prop_cycle"].by_key()['color']

fig, axs = plt.subplots(1,2)
vectors = np.exp(x*1j)
for dx,dy, c in zip (vectors.real, vectors.imag, colors):
    axs[0].arrow(0, 0, dx, dy, head_width=0.2, head_length=0.1,length_includes_head=True, color=c, width=.04)
axs[0].set_xlim(-1.5,1.5)
axs[0].set_ylim(-1.5,1.5)
axs[0].set_title("DS vectors")

vectors = np.exp(x*1j*2)
for i,(dx,dy,c) in enumerate(zip(vectors.real, vectors.imag, colors)):
    if i>=4:
        dx = dx*0.8
        dy = dy*0.8
    axs[1].arrow(0, 0, dx, dy, head_width=0.2, head_length=0.1, length_includes_head=True, color=c, width=.04)
axs[1].set_xlim(-1.5,1.5)
axs[1].set_ylim(-1.5,1.5)
axs[1].set_title("OS vectors")
Text(0.5, 1.0, 'OS vectors')

direction_selectivity[source]

direction_selectivity(grouped_spikes_d, n_bootstrap=1000)

Compute the direction selectivity index of cells in the given dict containing for each condition as the keys, an array of shape (n_angle, n_repeat, trial_len, n_cell). Such dictionnary can be obtained by using utils.group_direction_response.

params:

- grouped_spikes_d: Results of the group_direction_response of shape (n_angle, n_repeat, t, n_cell)
- n_bootstrap: Number of bootstrap iteration to calculate the p-value

return:

- A dictionnary with a key for each condition retrieving a tuple containing list of the cells
(spike sum, direction pref, DS idx, orientation pref, OS idx, pval DS, pval OS)

wave_direction_selectivity[source]

wave_direction_selectivity(wave_array, spike_counts, moving_distance_th=1, looming_distance_th=0.3, n_bootstrap=1000)

Computes the direction, orientation and looming/shrinking indexes of the cells in response to the wave stimulus (in LED dome).

params:

- wave_array: The indexes of the waves from the record master.
- spike_counts: The cells response to the waves from the record master.
- moving_distance_th: Distance threshold in radians above which a stimulus can be considered for the OS and DS.
- looming_distance_th: Distance threshold in radians bellow which a stimulus can be considered for the looming/shrinking response
- n_bootstrap: Number of repetition in the bootstraping method to compute the pvalues

return:

- A tuple containing lists of the cells response, in order:
    * [0] summed_responses: Summed response of a cell to each wave condition
    * [1] dir_pref_l: Direction preference vector
    * [2] dir_idx_l : Direction indexes
    * [3] dir_pval_l: Direction p_values
    * [4] ori_pref_l: Orientation preference vector
    * [5] ori_idx_l : Orientation indexes
    * [6] ori_pval_l: Orientation p_values
    * [7] loom_idx_l : Looming indexes
    * [8] loom_pval_l: Looming p_values
    * [9] stas_position_l: Position (theta, phi) of the cells receptive fields with the water stimulus
    * [10] waves_position_l: Relative positions of the waves to the cells STA.

peri_saccadic_response[source]

peri_saccadic_response(spike_counts, eye_track, motion_threshold=5, window=15)

Computes the cell average response around saccades.

params:

- spike_counts: cells activity matrix of shape (t, n_cell)
- eye_track: Eye tracking data of shape (t, x_pos, y_pos, ...)
- motion_threshold: Amount of motion in pixel to account for a saccade
- window: Size of the window before and after the saccade on which to average the cell response

return:

- peri saccadic response of cells of shape (n_cell, window*2+1)