Skip to content

Commit e4c0694

Browse files
committed
combine update_temporal_compoents & parallel
combine update_temporal_compoents & update_temporal_components_parallel into a single function. The default option is to use the parallel implementation if the parallel processing toolbox is present
1 parent 5bb34aa commit e4c0694

File tree

5 files changed

+275
-383
lines changed

5 files changed

+275
-383
lines changed

@Sources2D/Sources2D.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ function updateTemporal(obj, Y)
5656
[obj.C, obj.f, obj.P, obj.S] = update_temporal_components(...
5757
Y, obj.A, obj.b, obj.C, obj.f, obj.P, obj.options);
5858
end
59-
60-
%% update temporal components in parallel
61-
function updateTemporalParallel(obj, Y)
62-
[obj.C, obj.f, obj.P, obj.S] = update_temporal_components_parallel(...
63-
Y, obj.A, obj.b, obj.C, obj.f, obj.P, obj.options);
64-
end
65-
59+
6660
%% merge found components
6761
function [nr, merged_ROIs] = merge(obj, Y)
6862
[obj.A, obj.C, nr, merged_ROIs, obj.P, obj.S] = merge_components(...

CNMFSetParms.m

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,77 @@
88

99
Names = [
1010
% dataset info
11-
'd1 ' % number of rows
12-
'd2 ' % number of cols
11+
'd1 ' % number of rows
12+
'd2 ' % number of cols
1313
% INITIALIZATION (initialize_components.m)
14-
'ssub ' % spatial downsampling factor (default: 1)
15-
'tsub ' % temporal downsampling factor (default: 1)
16-
'init_method ' % initialization method ('greedy','sparse_NMF') (default: 'greedy')
14+
'ssub ' % spatial downsampling factor (default: 1)
15+
'tsub ' % temporal downsampling factor (default: 1)
16+
'init_method ' % initialization method ('greedy','sparse_NMF') (default: 'greedy')
1717
% greedyROI parameters (greedyROI2d.m)
18-
'gSig ' % half size of neurons to be found (default: [5,5])
19-
'gSiz ' % half size of bounding box for each neuron (default: 2*gSig+1)
20-
'nb ' % number of background components (default: 1)
21-
'nIter ' % maximum number of rank-1 NMF iterations during refining
22-
'med_app ' % number of timesteps to be interleaved for fast (approximate) median calculation (default: 1)
23-
'save_memory ' % process data sequentially to save memory (default: 0)
24-
'chunkSiz ' % filter this number of timesteps each time (default: 100)
25-
'windowSiz ' % size of window over which is computed sequentially (default: 32 x 32)
18+
'gSig ' % half size of neurons to be found (default: [5,5])
19+
'gSiz ' % half size of bounding box for each neuron (default: 2*gSig+1)
20+
'nb ' % number of background components (default: 1)
21+
'nIter ' % maximum number of rank-1 NMF iterations during refining
22+
'med_app ' % number of timesteps to be interleaved for fast (approximate) median calculation (default: 1)
23+
'save_memory ' % process data sequentially to save memory (default: 0)
24+
'chunkSiz ' % filter this number of timesteps each time (default: 100)
25+
'windowSiz ' % size of window over which is computed sequentially (default: 32 x 32)
2626
% sparse_NMF parameters (sparse_NMF_initialization.m)
27-
'snmf_max_iter ' % max # of sparse NMF iterations
28-
'err_thr ' % relative change threshold for stopping sparse_NMF
29-
'eta ' % frobenious norm factor *max(Y(:))^2
30-
'beta ' % sparsity factor
27+
'snmf_max_iter ' % max # of sparse NMF iterations
28+
'err_thr ' % relative change threshold for stopping sparse_NMF
29+
'eta ' % frobenious norm factor *max(Y(:))^2
30+
'beta ' % sparsity factor
3131
% HALS parameters (HALS_2d.m)
32-
'bSiz ' % expand kernel for HALS growing (default: 3)
33-
'maxIter ' % maximum number of HALS iterations (default: 5)
32+
'bSiz ' % expand kernel for HALS growing (default: 3)
33+
'maxIter ' % maximum number of HALS iterations (default: 5)
3434
% Noise and AR coefficients calculation (preprocess_data.m)
35-
'noise_range ' % frequency range over which to estimate the noise (default: [0.25,0.5])
36-
'noise_method ' % method for which to estimate the noise level (default: 'logmexp')
37-
'flag_g ' % compute global AR coefficients (default: false)
38-
'lags ' % number of extra lags when computing the AR coefficients (default: 5)
39-
'include_noise ' % include early lags when computing AR coefs (default: 0)
40-
'pixels ' % pixels to include when computing the AR coefs (default: 1:numel(Y)/size(Y,ndims(Y)))
41-
'split_data ' % split data into patches for memory reasons (default: 0)
42-
'block_size ' % block size for estimating noise std in patches (default: [64,64])
35+
'noise_range ' % frequency range over which to estimate the noise (default: [0.25,0.5])
36+
'noise_method ' % method for which to estimate the noise level (default: 'logmexp')
37+
'flag_g ' % compute global AR coefficients (default: false)
38+
'lags ' % number of extra lags when computing the AR coefficients (default: 5)
39+
'include_noise ' % include early lags when computing AR coefs (default: 0)
40+
'pixels ' % pixels to include when computing the AR coefs (default: 1:numel(Y)/size(Y,ndims(Y)))
41+
'split_data ' % split data into patches for memory reasons (default: 0)
42+
'block_size ' % block size for estimating noise std in patches (default: [64,64])
4343
% UPDATING SPATIAL COMPONENTS (unpdate_spatial_components.m)
44-
'search_method ' % method for determining footprint of spatial components 'ellipse' or 'dilate' (default: 'ellipse')
45-
'use_parallel ' % update pixels in parallel (default: 1 if present)
44+
'search_method ' % method for determining footprint of spatial components 'ellipse' or 'dilate' (default: 'ellipse')
45+
'use_parallel ' % update pixels in parallel (default: 1 if present)
4646
% determine_search_location.m
47-
'min_size ' % minimum size of ellipse axis (default: 3)
48-
'max_size ' % maximum size of ellipse axis (default: 8)
49-
'dist ' % expansion factor of ellipse (default: 3)
50-
'se ' % morphological element for dilation (default: strel('disk',4,0))
47+
'min_size ' % minimum size of ellipse axis (default: 3)
48+
'max_size ' % maximum size of ellipse axis (default: 8)
49+
'dist ' % expansion factor of ellipse (default: 3)
50+
'se ' % morphological element for dilation (default: strel('disk',4,0))
5151
% threshold_components.m
52-
'nrgthr ' % energy threshold (default: 0.9999)
53-
'clos_op ' % morphological element for closing (default: strel('square',3))
54-
'medw ' % size of median filter (default: [3,3])
52+
'nrgthr ' % energy threshold (default: 0.9999)
53+
'clos_op ' % morphological element for closing (default: strel('square',3))
54+
'medw ' % size of median filter (default: [3,3])
5555
% UPDATING TEMPORAL COMPONENTS (update_temporal_components.m)
56-
'deconv_method ' % method for spike deconvolution (default: 'constrained_foopsi')
57-
'restimate_g ' % flag for updating the time constants for each component (default: 1)
58-
'temporal_iter ' % number of block-coordinate descent iterations (default 2)
56+
'deconv_method ' % method for spike deconvolution (default: 'constrained_foopsi')
57+
'restimate_g ' % flag for updating the time constants for each component (default: 1)
58+
'temporal_iter ' % number of block-coordinate descent iterations (default: 2)
59+
'temporal_parallel ' % flag for parallel updating of temporal components (default: true if present)
5960
% CONSTRAINED DECONVOLUTION (constrained_foopsi.m)
60-
'method ' % methods for performing spike inference ('dual','cvx','spgl1','lars') (default:'cvx')
61-
'bas_nonneg ' % flag for setting the baseline lower bound. if 1, then b >= 0 else b >= min(y) (default 0)
62-
'fudge_factor ' % scaling constant to reduce bias in the time constant estimation (default 1 - no scaling)
63-
'resparse ' % number of times that the solution is resparsened (default: 0)
61+
'method ' % methods for performing spike inference ('dual','cvx','spgl1','lars') (default:'cvx')
62+
'bas_nonneg ' % flag for setting the baseline lower bound. if 1, then b >= 0 else b >= min(y) (default 0)
63+
'fudge_factor ' % scaling constant to reduce bias in the time constant estimation (default 1 - no scaling)
64+
'resparse ' % number of times that the solution is resparsened (default: 0)
6465
% MERGING (merge_ROIs.m)
65-
'merge_thr ' % merging threshold (default: 0.85)
66-
'fast_merge ' % flag for using fast merging (default 1)
66+
'merge_thr ' % merging threshold (default: 0.85)
67+
'fast_merge ' % flag for using fast merging (default 1)
6768
% VIDEO (make_patch_video.m)
68-
'ind ' % indeces of components to be shown (deafult: 1:4)
69-
'skip_frame ' % skip frames when showing the video (default: 1 (no skipping))
70-
'sx ' % half size of representative patches (default: 16)
71-
'make_avi ' % flag for saving avi video (default: 0)
72-
'show_background' % flag for displaying the background in the denoised panel (default: 1)
73-
'show_contours ' % flag for showing the contour plots of the patches in the FoV (default: 0)
74-
'cmap ' % colormap for plotting (default: 'default')
75-
'name ' % name of saved video file (default: based on current date)
69+
'ind ' % indeces of components to be shown (deafult: 1:4)
70+
'skip_frame ' % skip frames when showing the video (default: 1 (no skipping))
71+
'sx ' % half size of representative patches (default: 16)
72+
'make_avi ' % flag for saving avi video (default: 0)
73+
'show_background ' % flag for displaying the background in the denoised panel (default: 1)
74+
'show_contours ' % flag for showing the contour plots of the patches in the FoV (default: 0)
75+
'cmap ' % colormap for plotting (default: 'default')
76+
'name ' % name of saved video file (default: based on current date)
7677
% PLOT COMPONENTS (view_patches.m)
77-
'plot_df ' % flag for displaying DF/F estimates (default: 1)
78-
'make_gif ' % save animation (default: 0)
79-
'save_avi ' % save video (default: 0)
80-
'pause_time ' % time to pause between each component (default: Inf, user has to click)
78+
'plot_df ' % flag for displaying DF/F estimates (default: 1)
79+
'make_gif ' % save animation (default: 0)
80+
'save_avi ' % save video (default: 0)
81+
'pause_time ' % time to pause between each component (default: Inf, user has to click)
8182
];
8283

8384
[m,n] = size(Names);
@@ -207,6 +208,7 @@
207208
{'constrained_foopsi'}
208209
{1}
209210
{2}
211+
{~isempty(which('parpool'))}
210212
% CONSTRAINED DECONVOLUTION (constrained_foopsi.m)
211213
{'cvx'}
212214
{0}
@@ -216,7 +218,7 @@
216218
{0.85}
217219
{1}
218220
% VIDEO (make_patch_video.m)
219-
{[1:4]}
221+
{1:4}
220222
{1}
221223
{16}
222224
{0}

demo_script.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
num2read=2000; % user input: how many frames to read (optional, default until the end)
99

1010
Y = bigread2(nam,sframe,num2read);
11+
Y = Y - min(Y(:));
1112
if ~isa(Y,'double'); Y = double(Y); end % convert to double
1213

1314
[d1,d2,T] = size(Y); % dimensions of dataset
@@ -25,7 +26,7 @@
2526
'search_method','ellipse','dist',3,... % search locations when updating spatial components
2627
'deconv_method','constrained_foopsi',... % activity deconvolution method
2728
'temporal_iter',2,... % number of block-coordinate descent steps
28-
'fudge_factor',0.98,... % bias correction for AR coefficients
29+
'fudge_factor',0.98,... % bias correction for AR coefficients
2930
'merge_thr',merge_thr... % merging threshold
3031
);
3132
%% Data pre-processing
@@ -50,7 +51,6 @@
5051
[A,b] = update_spatial_components(Yr,Cin,fin,Ain,P,options);
5152

5253
%% update temporal components
53-
% consider using update_temporal_components_parallel for increased speed
5454
[C,f,P,S] = update_temporal_components(Yr,A,b,Cin,fin,P,options);
5555

5656
%% merge found components

0 commit comments

Comments
 (0)