NeuroAnalysis - Neural Signal Analysis
API Reference
NeuroAnalysis.ColorMaps
— Constant.Predefined ColorMaps
NeuroAnalysis.CondDCh
— Constant.Default digital input channels
NeuroAnalysis.SecondPerUnit
— Constant.Time Unit set to millisecond by default.
NeuroAnalysis.alphamask
— Method.Masking alpha channel of an image, match the implementation in Experica
shaders.
NeuroAnalysis.assignlayer
— Method.Try to locate cell layer.
- y coordinate of cell postion
- layer definition
NeuroAnalysis.cas
— Method.2D cas
function defined as $cas(x+y) = cos(x+y) + sin(x+y)$
- kx: Frequency in cycle/unit_x
- ky: Frequency in cycle/unit_y
- phase: Phase of a cycle in [0, 1] scale
- isnorm: scale
cas
in [-√2, √2] to [-1, 1]
NeuroAnalysis.cas
— Method.cas
function defined as $cas(x) = cos(x) + sin(x)$
- f: Frequency in cycle/unit_x
- phase: Phase of a cycle in [0, 1] scale
- isnorm: scale
cas
in [-√2, √2] to [-1, 1]
NeuroAnalysis.cas2sin
— Method.2D cas
to 2D sin gratingf
NeuroAnalysis.cas2sin
— Method.cas
phase to sin
phase, phase is in [0, 1] scale
$cas(x) = √2 sin(x + π/4)$
NeuroAnalysis.chmasknp
— Method.Logical mask for Neuropixels
channels in probe shape
NeuroAnalysis.circaxial
— Function.Transforms p-axial data to a common scale α: sample of angles in radians p: number of modes
NeuroAnalysis.circaxialmean
— Function.Mean direction for circular data with axial
NeuroAnalysis.circmean
— Function.Mean for circular data
NeuroAnalysis.circr
— Function.Mean Resultant Vector Length for circular data α: sample of angles in radians w: number of incidences in case of binned angle data d: spacing of bin centers for binned data, if supplied correction factor is used to correct for bias
NeuroAnalysis.circtuningfeature
— Method.Properties of Circular Tuning: - Prefered Direction/Orientation - Selectivity Index - version 1: (ResponsePrefered - ResponseOpposing)/ResponsePrefered - version 2: (ResponsePrefered - ResponseOpposing)/(ResponsePrefered + ResponseOpposing) - Full Width at Half Maximum
- x: angles in radius
- y: responses
- od: opposing angle distance, π for DSI, 0.5π for OSI
- fn: factor name
NeuroAnalysis.circvar
— Function.Circular Variance
NeuroAnalysis.clampscale
— Method.clamp value to min
and max
, and linearly map range [min, max]
to [0, 1]
NeuroAnalysis.condfactor
— Method.Get factors of conditions
NeuroAnalysis.condin
— Method.In Condition Tests, find each unique condition, number of repeats and its indices
NeuroAnalysis.condresponse
— Method.Group repeats of Conditions, get Mean
and SEM
of responses
- rs: responses of each trial
- ci: trial indices of repeats for each condition
NeuroAnalysis.condstring
— Method.Print Condition in String
NeuroAnalysis.condtest
— Method.Get CondTest
DataFrame
NeuroAnalysis.condtestcond
— Method.Get CondTestCond
DataFrame
NeuroAnalysis.correlogram
— Method.Shift(shuffle) corrected, normalized(coincidence/spike), condition/trial-averaged Cross-Correlogram of binary spike trains. (Bair, W., Zohary, E., and Newsome, W.T. (2001). Correlated Firing in Macaque Visual Area MT: Time Scales and Relationship to Behavior. J. Neurosci. 21, 1676–1697.)
NeuroAnalysis.csd
— Method.1D Current Source Density for a set of voltage traces from a linear array of electrodes.
- data: ch x sample or ch x sample x epoch(volts)
- method:
CSD: finite difference method of second spatial derivatives of potentials, I = - ∇σ⋅∇ϕ, σ is conductivities, ϕ is potentials, on the continuous assumption when spacing is around 20-100 um. (Nicholson & Freeman, 1975, J Neurophysiol, 38(2): 356-68)
iCSD: solve I -> ϕ forward problem, then get the inverse transformation matrix. (Petterson et al., 2006, J Neurosci Methods, 154(1-2):116-33)
iCSDdelta: δ method where infinitely thin current source discs of radius r.
iCSDspline: cubic spline method where current source between electrode be modeled by smooth spline
kCSD: kernal CSD ()
h: channel spacing(micrometers)
c: conductivity of the extracellular medium in siemans/meter
r: radius(micrometers) of the model current source/sink in reverse method
return: CSD(amps/meters^3)
NeuroAnalysis.csd_cubicspline
— Function.cubic spline inverse CSD
contact_positions: contact positions data: measured potentials Fcs: cubic spline transformation matrix corresponding to the given contact positions E0,E1,E2,E3: matrixes containing the "recursive rules"
NeuroAnalysis.ctctc
— Method.Get CondTest
and CondTestCond
DataFrame
NeuroAnalysis.digitalbit
— Method.Parse bit event time and value.
NeuroAnalysis.digitaldata
— Method.Get digital channel time and value.
NeuroAnalysis.dirsigtest
— Method.Direction tuning significance using dot product with empirical orientation preference This function calculates the probability that the "true" direction tuning vector of a neuron has non-zero length. It performs this by empirically determing the unit orientation vector, and then computing the dot product of the direction vector for each trial onto the overall orientation vector, and then looking to see if the average is non-zero.
Inputs: ANGLES is a vector of direction angles at which the response has been measured. RATES is the response of the neuron in to each angle; each row should contain responses from a different trial. Output: P the probability that the "true" direction tuning vector is non-zero.
See: Mazurek, Kagan, Van Hooser 2014; Frontiers in Neural Circuits
NeuroAnalysis.dogf
— Method.Difference of Gaussians
function
NeuroAnalysis.dropmatdim!
— Method.Drop array dims according to MATLAB
convention.
- scalar: scalar instead of 1x1 array
- rvector: vector instead of 1xN array
- cvector: vector instead of Nx1 array
NeuroAnalysis.e_matrixes
— Method.Computes the E0, E1, E2 and E3 matrixes used in the cubic spline iCSD method. These matrixes contains the recursive formulas for finding the F matrix
NeuroAnalysis.epoch2sampleindex
— Method.Convert epochs in time to sample index
NeuroAnalysis.epochsample
— Method.Epochs of Channel Sample.
NeuroAnalysis.epochsamplenp
— Method.Epochs of Neuropixels
Channel Sample x
, optionally gain corrected(voltage), line noise(60,120,180Hz) removed and bandpass filtered
NeuroAnalysis.epochspiketrain
— Method.Epochs of a Spike Train in between binedges
NeuroAnalysis.epochspiketrain
— Method.Epoch of a Spike Train x
, where min <= x[i] < max
.
kwargs isminzero
, ismaxzero
and shift
set epoch zero value to min+shift
or max+shift
.
return:
- y: epoch of the Spike Train
- n: number of elements in the epoch, or divided by duration(max-min) of the epoch, based on kwargs
israte
- w: epoch window(min,max)
- i: indices of epoch elements in the original Spike Train, such that y = x[i]
See also: epochspiketrains
, epochspiketrainresponse
NeuroAnalysis.epochspiketrainresponse
— Method.Response of each epoch of a Spike Train, could be mean firing rate or number of spikes based on kwarg israte
.
See also: epochspiketrainresponse_ono
Response of each epoch of a Spike Train, could be mean firing rate or number of spikes based on kwarg israte
.
This is a faster(~500x) version compared to epochspiketrainresponse
, but only works when x
, mins
and maxs
are ascendingly ordered, and each maxs-mins
range are none-overlapping.
NeuroAnalysis.epochspiketrains
— Method.Epochs for each Spike Trains
NeuroAnalysis.exchmasknp
— Method.Logical mask for Neuropixels
excluded channels in probe shape
NeuroAnalysis.expericafileregex
— Method.Regular Expression to match Experica
data file name
NeuroAnalysis.f1orisf
— Method.Estimate the F1 Ori and SpatialFreq of an image from its 2D powerspectrum.
- x: 2D powerspectrum
- freqd1: frequencies of dim 1
- freqd2: frequencies of dim 2
return:
- ori: Orientation in radius, 0 is -, increase counter-clock wise
- sf: SpatialFreq along the line perpendicular to ori
NeuroAnalysis.f_cubicspline
— Function.F and E matrix of the cubic spline inverse CSD
NeuroAnalysis.factorresponse
— Method.Condition Response in Factor Space
NeuroAnalysis.factorresponsefeature
— Method.Tuning properties of factor response
fl: factor levels
fr: factor responses
HueAngle, Orientation and Direction follow the same convention such that 0 is -/→, then increase counter-clock wise.
For cases where Orientation and Direction are interlocked(drifting grating): - when Orientation is -(0), then Direction is ↑(90) - when Direction is →(0), then Orientation is |(-90)
NeuroAnalysis.finalfactor
— Method.Get Final
factors of conditions
NeuroAnalysis.findclosestangle
— Method.find the index i
in thetas
that thetas[i]
is closest to a
, all in radius
NeuroAnalysis.fitmodel
— Method.Fit model to data
NeuroAnalysis.flatspiketrains
— Function.Flat Spike Trains to SpikeTimes and Trials, optionally sort trial based on sv
NeuroAnalysis.flin
— Method.Find levels for each factor and indices, repetition for each level
NeuroAnalysis.gaborf
— Method.Gabor
function
NeuroAnalysis.gaincorrectnp
— Method.Convert raw Neuropixels
data to gain-corrected voltages. The saved-channel id subset in data will be used to get corresponding gain.
The full conversion with gain is:
$dataVolts = dataInt * fi2v / gain$
Note that each channel may have its own gain.
- y: the saved data stream, excluding the last Sync channel.
- meta: corresponding meta for y
NeuroAnalysis.gaussianf
— Method.Gaussian
function
NeuroAnalysis.getdatafile
— Method.Get matched file names in path
NeuroAnalysis.getexpericafile
— Method.Get matched Experica
files in directory
NeuroAnalysis.getoifile
— Method.Get Optical Imaging VDAQ
matched files in directory
NeuroAnalysis.grating
— Method.Generate Grating Image, match the implementation in Experica
grating shader.
- θ: Orientation (radius), 0 is -, increase counter-clock wise
- sf: SpatialFreq (cycle/deg)
- tf: TemporalFreq (cycle/sec)
- t: Time (second)
- phase: Phase of a cycle in [0, 1] scale
- size: Tuple of image size in degree
- ppd: pixel per degree
- isnorm: return image in [0, 1] or [-1, 1]
NeuroAnalysis.gratingf
— Method.2D sin
grating function
- θ: Orientation in radius, 0 is -, increase counter-clock wise
- f: Frequency in cycle/unit_x/y
- phase: Phase of a cycle in [0, 1] scale
NeuroAnalysis.gratingf
— Method.sin
grating function
- f: Frequency in cycle/unit_x
- phase: Phase of a cycle in [0, 1] scale
NeuroAnalysis.gvmf
— Method.NeuroAnalysis.hartley
— Method.Generate gratings in Hartley space (PL)
- kx, ky: wavenumber along x, y axis
- bw: black and white (phase) flip
- stisize: stimulus size in visual angle (degree); note that sz[1]=sz[2]
if norm=true,Return image in [0,1], otherwise return image in [-1,1]
NeuroAnalysis.hartleysubspace
— Method.Generate Hartley Subspace, where k is frequency in cycle/unit_x/y. [1]
- kbegin: k >= kbegin
- kend: k <= kend
- dk: Δk, step on k axis
- phase: phase in [0, 1] scale, default 0.
- shape:
:square
or:circle
shape subspace - addhalfcycle: add half cycle shifted hartleys
- blank: the element of hartley as blank, default uniform gray.
- nblank: number of blanks to add
Ringach, D.L., Sapiro, G., and Shapley, R. (1997). A subspace reverse-correlation technique for the study of visual neurons. Vision Research 37, 2455–2464.
NeuroAnalysis.hlpass
— Method.High pass and low pass filtering
NeuroAnalysis.hotellingt2test
— Function.Hotelling's T-Squared test for one multivariate sample.
Performs Hotelling's T^2 test on multivariate samples X to determine if the data have mean MU. X should be a NxP matrix with N observations of P-dimensional data, and the mean MU to be tested should be 1xP. the significance level α is 0.05 by default.
H is 1 if the null hypothesis (that the mean of X is equal to MU) can be rejected at significance level α. P is the actual P value.
The code is based on HotellingT2.m by A. Trujillo-Ortiz and R. Hernandez-Walls.
NeuroAnalysis.ismodulative
— Method.Check if any factors and their interactions significently modulate response using ANOVA
NeuroAnalysis.isresponsive
— Method.Check if any sub group of response
is significently different from baseline
by Wilcoxon Signed Rank Test
NeuroAnalysis.isresponsive
— Method.Check if response
is significently different from baseline
by Wilcoxon Signed Rank Test
NeuroAnalysis.loadimageset
— Method.Load images in directory
NeuroAnalysis.localcontrast
— Method.local RMS contrast of each image, highlighting local structure regions
NeuroAnalysis.maptodatatime
— Method.Map time to data timeline, optionally add latency.
NeuroAnalysis.matchfile
— Method.Get matched file names in directory, optionally join directory to get file path
NeuroAnalysis.matdictarray2df
— Method.convert Matlab
struct of array to DataFrame
NeuroAnalysis.normalized
— Method.Normalize values of an array to be between -1 and 1
original sign of the array values is maintained.
NeuroAnalysis.oifileregex
— Method.Regular Expression to match Optical Imaging VDAQ
block file name
NeuroAnalysis.parsedigitalinanalog
— Function.Get digital rising and falling edges in a analog stream return di: edges index dv: edges active/inactive state
NeuroAnalysis.plotcondresponse
— Method.Plot Mean
and SEM
of responses for each condition
NeuroAnalysis.plothartleysubspace
— Method.plot hartley subspace
NeuroAnalysis.plotspiketrain
— Method.scatter plot of spike trains
NeuroAnalysis.poissonspiketrain
— Method.Generate a Poisson Spike Train
NeuroAnalysis.powerspectrum
— Method.Multi-Taper power spectrum estimation
NeuroAnalysis.powerspectrum2
— Method.2D powerspectrum of an image.
NeuroAnalysis.prepare
— Method.Read and Prepare Dataset in MATLAB
MAT File
NeuroAnalysis.prepare_experica!
— Method.Prepare Experica
Experiment Data
NeuroAnalysis.prepare_oi!
— Method.Prepare Optical Imaging
Block Data
NeuroAnalysis.prepare_ripple!
— Method.Prepare Ripple
Data
NeuroAnalysis.psthspiketrains
— Method.PSTH of Spike Trains
NeuroAnalysis.readmat
— Method.Read variables of a MATLAB
MAT file into a Dictionary
- f: MAT file path
- vars: variable names in the varset to read
- varset: variable names to select in vars
- scalar: scalar instead of 1x1 matrix
- rvector: vector instead of 1xN matrix
- cvector: vector instead of Nx1 matrix
NeuroAnalysis.readmeta
— Method.Read DataExport
Metadata MAT File
NeuroAnalysis.refchmasknp
— Method.Logical mask for Neuropixels
reference channels in probe shape
NeuroAnalysis.reshape2mask
— Method.reshape data stream in the same shape of chmask, where masked channels are replaced with local average
NeuroAnalysis.rmline!
— Method.Remove line noise and its harmonics by notch filter
NeuroAnalysis.roccurve
— Method.This function calculates the ROC curve, which represents the 1-specificity and sensitivity of two classes of data, (i.e., class1 and class2).
The function also returns all the needed quantitative parameters: threshold position, distance to the optimum point, sensitivity, specificity, accuracy, area under curve (AROC), positive and negative predicted values (PPV, NPV), false negative and positive rates (FNR, FPR), false discovery rate (FDR), false omission rate (FOR), F1 score, Matthews correlation coefficient (MCC), Informedness (BM) and Markedness; as well as the number of true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN).
Rewrite from Víctor Martínez-Cagigal (2020). ROC Curve, MATLAB Central File Exchange. Retrieved February 11, 2020.
NeuroAnalysis.sampleindex2time
— Method.sample index to time
NeuroAnalysis.sbxexd
— Method.Find the extreme value
NeuroAnalysis.sbxjoinhartleyFourier
— Method.Peichao:
Join the results from differernt Hartleys after hartleyFourier analysis
NeuroAnalysis.sbxpeakroi
— Method.peak ROI region and its delay
NeuroAnalysis.sbxrffit!
— Method.fit responsive sta to each type of models
NeuroAnalysis.sin2cas
— Method.2D sin gratingf
to 2D cas
NeuroAnalysis.sin2cas
— Method.sin
phase to cas
phase, phase is in [0, 1] scale
$cas(x) = √2 sin(x + π/4)$
NeuroAnalysis.sta
— Method.Spike Triggered Average of Images
- x: Matrix where each row is one image
- y: Vector of image response
- norm: normalization factor, default no normalization. it could be $sum(y)$ if y is number of spike or spike rate, then STA would be spiking probability.
- whiten: whiten factor, default no whiten. it could be $(xᵀx)⁻¹$ or inverse of covariance matrix, that decorrelate STA.
NeuroAnalysis.statetime
— Method.Extract state time of condtest
NeuroAnalysis.stfilter
— Method.Spatial and Temporal filter of data stream
NeuroAnalysis.time2sampleindex
— Method.time to sample index
NeuroAnalysis.unitspike_kilosort
— Method.Organize each spiking unit info from Kilosort
result.
NeuroAnalysis.vlabregex
— Method.Regular expression to match VLab
data file names
NeuroAnalysis.vmeanse
— Method.Vertical Mean and SEM of a matrix
NeuroAnalysis.vmf
— Method.NeuroAnalysis.vstack
— Method.Vertical stack same length vectors to matrix
Base.range
— Method.Generates linearly interpolated colors between key colors inclusively.
return an Array
of colors.
PlotUtils.cgrad
— Method.Generates linearly interpolated ColorGradient
PlotUtils.cgrad
— Method.Generates linearly interpolated ColorGradient
between key colors.
Index
NeuroAnalysis.ColorMaps
NeuroAnalysis.CondDCh
NeuroAnalysis.SecondPerUnit
NeuroAnalysis.alphamask
NeuroAnalysis.assignlayer
NeuroAnalysis.cas
NeuroAnalysis.cas
NeuroAnalysis.cas2sin
NeuroAnalysis.cas2sin
NeuroAnalysis.chmasknp
NeuroAnalysis.circaxial
NeuroAnalysis.circaxialmean
NeuroAnalysis.circmean
NeuroAnalysis.circr
NeuroAnalysis.circtuningfeature
NeuroAnalysis.circvar
NeuroAnalysis.clampscale
NeuroAnalysis.condfactor
NeuroAnalysis.condin
NeuroAnalysis.condresponse
NeuroAnalysis.condstring
NeuroAnalysis.condtest
NeuroAnalysis.condtestcond
NeuroAnalysis.correlogram
NeuroAnalysis.csd
NeuroAnalysis.csd_cubicspline
NeuroAnalysis.ctctc
NeuroAnalysis.digitalbit
NeuroAnalysis.digitaldata
NeuroAnalysis.dirsigtest
NeuroAnalysis.dogf
NeuroAnalysis.dropmatdim!
NeuroAnalysis.e_matrixes
NeuroAnalysis.epoch2sampleindex
NeuroAnalysis.epochsample
NeuroAnalysis.epochsamplenp
NeuroAnalysis.epochspiketrain
NeuroAnalysis.epochspiketrain
NeuroAnalysis.epochspiketrainresponse
NeuroAnalysis.epochspiketrainresponse_ono
NeuroAnalysis.epochspiketrains
NeuroAnalysis.exchmasknp
NeuroAnalysis.expericafileregex
NeuroAnalysis.f1orisf
NeuroAnalysis.f_cubicspline
NeuroAnalysis.factorresponse
NeuroAnalysis.factorresponsefeature
NeuroAnalysis.finalfactor
NeuroAnalysis.findclosestangle
NeuroAnalysis.fitmodel
NeuroAnalysis.flatspiketrains
NeuroAnalysis.flin
NeuroAnalysis.gaborf
NeuroAnalysis.gaincorrectnp
NeuroAnalysis.gaussianf
NeuroAnalysis.getdatafile
NeuroAnalysis.getexpericafile
NeuroAnalysis.getoifile
NeuroAnalysis.grating
NeuroAnalysis.gratingf
NeuroAnalysis.gratingf
NeuroAnalysis.gvmf
NeuroAnalysis.hartley
NeuroAnalysis.hartleysubspace
NeuroAnalysis.hlpass
NeuroAnalysis.hotellingt2test
NeuroAnalysis.ismodulative
NeuroAnalysis.isresponsive
NeuroAnalysis.isresponsive
NeuroAnalysis.loadimageset
NeuroAnalysis.localcontrast
NeuroAnalysis.maptodatatime
NeuroAnalysis.matchfile
NeuroAnalysis.matdictarray2df
NeuroAnalysis.normalized
NeuroAnalysis.oifileregex
NeuroAnalysis.parsedigitalinanalog
NeuroAnalysis.plotcondresponse
NeuroAnalysis.plothartleysubspace
NeuroAnalysis.plotspiketrain
NeuroAnalysis.poissonspiketrain
NeuroAnalysis.powerspectrum
NeuroAnalysis.powerspectrum2
NeuroAnalysis.prepare
NeuroAnalysis.prepare_experica!
NeuroAnalysis.prepare_oi!
NeuroAnalysis.prepare_ripple!
NeuroAnalysis.psthspiketrains
NeuroAnalysis.readmat
NeuroAnalysis.readmeta
NeuroAnalysis.refchmasknp
NeuroAnalysis.reshape2mask
NeuroAnalysis.rmline!
NeuroAnalysis.roccurve
NeuroAnalysis.sampleindex2time
NeuroAnalysis.sbxexd
NeuroAnalysis.sbxjoinhartleyFourier
NeuroAnalysis.sbxpeakroi
NeuroAnalysis.sbxrffit!
NeuroAnalysis.sin2cas
NeuroAnalysis.sin2cas
NeuroAnalysis.sta
NeuroAnalysis.statetime
NeuroAnalysis.stfilter
NeuroAnalysis.time2sampleindex
NeuroAnalysis.unitspike_kilosort
NeuroAnalysis.vlabregex
NeuroAnalysis.vmeanse
NeuroAnalysis.vmf
NeuroAnalysis.vstack