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:
- tracesnp.ndarray
2D array of traces to be analyzed.
- dff_computation_cbfunction
Function that takes traces as an argument and returns an array of the same shape that is the calculated dF/F.
- save_plot_dirstr
Directory to save dF/F plots to. By default no plots are saved.
- Returns:
- dffnp.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:
- tracesnp.ndarray
2D array of traces to be analyzed.
- median_kernel_longint
Window size to use for long timescale median detrending.
- median_kernel_shortint
Window size to use for short timescale median detrending.
- noise_stdslist
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_frameslist
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:
- dffnp.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:
- tracesnp.ndarray
2D array of traces to be analyzed.
- mode_kernelsizeint
Window size to use for windowed_mode.
- mean_kernelsizeint
Window size to use for windowed_mean.
- Returns:
- dffnp.ndarray
2D array of dF/F traces.
- allensdk.brain_observatory.dff.movingaverage(x, kernelsize, y)[source]¶
Compute the windowed average of an array.
- Parameters:
- xnp.ndarray
Array to be analyzed
- kernelsizeint
Size of the moving window
- ynp.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:
- xnp.ndarray
Array to be analyzed
- kernelsizeint
Size of the moving window
- ynp.ndarray
Output array to store the results