allensdk.brain_observatory.dff module¶
-
allensdk.brain_observatory.dff.
calculate_dff
(traces, dff_computation_cb=None, save_plot_dir=None)[source]¶ Apply dF/F computation to a set of traces.
The default computation method is
compute_dff_windowed_median()
using default window parameters.Parameters: - traces : np.ndarray
2D array of traces to be analyzed.
- dff_computation_cb : function
Function that takes traces as an argument and returns an array of the same shape that is the calculated dF/F.
- save_plot_dir : str
Directory to save dF/F plots to. By default no plots are saved.
Returns: - dff : np.ndarray
2D array of dF/F traces.
-
allensdk.brain_observatory.dff.
compute_dff_windowed_median
(traces, median_kernel_long=5401, median_kernel_short=101, noise_stds=None, n_small_baseline_frames=None, **kwargs)[source]¶ Compute dF/F of a set of traces with median filter detrending.
The operation is basically:
T_long = windowed_median(T) # long timescale kernel
T_dff1 = (T - T_long) / elementwise_max(T_long, noise_std(T))
T_short = windowed_median(T_dff1) # short timescale kernel
T_dff = T_dff1 - elementwise_min(T_short, 2.5*noise_std(T_dff1))
Parameters: - traces : np.ndarray
2D array of traces to be analyzed.
- median_kernel_long : int
Window size to use for long timescale median detrending.
- median_kernel_short : int
Window size to use for short timescale median detrending.
- noise_stds : list
List that will contain noise_std(T_dff1) for each trace. The value for each trace will be appended to the list if provided.
- n_small_baseline_frames : list
List that will contain the number of frames for each trace where the long-timescale median window is less than noise_std(T). The value for each trace will be appended to the list if provided.
- kwargs:
Additional keyword arguments are passed to
noise_std()
.
Returns: - dff : np.ndarray
2D array of dF/F traces.
-
allensdk.brain_observatory.dff.
compute_dff_windowed_mode
(traces, mode_kernelsize=5400, mean_kernelsize=3000)[source]¶ Compute dF/F of a set of traces using a low-pass windowed-mode operator.
The operation is basically:
T_mm = windowed_mean(windowed_mode(T))
T_dff = (T - T_mm) / T_mm
Parameters: - traces : np.ndarray
2D array of traces to be analyzed.
- mode_kernelsize : int
Window size to use for windowed_mode.
- mean_kernelsize : int
Window size to use for windowed_mean.
Returns: - dff : np.ndarray
2D array of dF/F traces.
-
allensdk.brain_observatory.dff.
movingaverage
(x, kernelsize, y)[source]¶ Compute the windowed average of an array.
Parameters: - x : np.ndarray
Array to be analyzed
- kernelsize : int
Size of the moving window
- y : np.ndarray
Output array to store the results
-
allensdk.brain_observatory.dff.
movingmode_fast
(x, kernelsize, y)[source]¶ Compute the windowed mode of an array. A running mode is initialized with a histogram of values over the initial kernelsize/2 values. The mode is then updated as the kernel moves by adding and subtracting values from the histogram.
Parameters: - x : np.ndarray
Array to be analyzed
- kernelsize : int
Size of the moving window
- y : np.ndarray
Output array to store the results