1616from .. import io
1717
1818def pclowhigh (mov , nlowhigh , nPC , random_state ):
19- """ get mean of top and bottom PC weights for nPC's of mov
20-
21- computes nPC PCs of mov and returns average of top and bottom
22-
23- Parameters
24- ----------
25- mov : int16, array
26- subsampled frames from movie size frames x Ly x Lx
27- nlowhigh : int
28- number of frames to average at top and bottom of each PC
29- nPC : int
30- number of PCs to compute
31-
32- Returns
33- -------
34- pclow : float, array
35- average of bottom of spatial PC: nPC x Ly x Lx
36- pchigh : float, array
37- average of top of spatial PC: nPC x Ly x Lx
38- w : float, array
39- singular values of decomposition of mov
40- v : float, array
41- frames x nPC, how the PCs vary across frames
42-
19+ """
20+ Compute mean of top and bottom PC weights for nPC's of mov
21+
22+ computes nPC PCs of mov and returns average of top and bottom
23+
24+ Parameters
25+ ----------
26+ mov : frames x Ly x Lx
27+ subsampled frames from movie
28+ nlowhigh : int
29+ number of frames to average at top and bottom of each PC
30+ nPC : int
31+ number of PCs to compute
32+ random_state:
33+ a value that sets the seed for the PCA randomizer.
34+
35+ Returns
36+ -------
37+ pclow : float, array
38+ average of bottom of spatial PC: nPC x Ly x Lx
39+ pchigh : float, array
40+ average of top of spatial PC: nPC x Ly x Lx
41+ w : float, array
42+ singular values of decomposition of mov
43+ v : float, array
44+ frames x nPC, how the PCs vary across frames
4345 """
4446 nframes , Ly , Lx = mov .shape
4547 mov = mov .reshape ((nframes , - 1 ))
@@ -63,31 +65,44 @@ def pclowhigh(mov, nlowhigh, nPC, random_state):
6365def pc_register (pclow , pchigh , bidi_corrected , spatial_hp = None , pre_smooth = None , smooth_sigma = 1.15 , smooth_sigma_time = 0 ,
6466 block_size = (128 ,128 ), maxregshift = 0.1 , maxregshiftNR = 10 , reg_1p = False , snr_thresh = 1.25 ,
6567 is_nonrigid = True , pad_fft = False , bidiphase = 0 , spatial_taper = 50.0 ):
66- """ register top and bottom of PCs to each other
67-
68- Parameters
69- ----------
70- pclow : float, array
71- average of bottom of spatial PC: nPC x Ly x Lx
72- pchigh : float, array
73- average of top of spatial PC: nPC x Ly x Lx
74- refImg : int16, array
75- reference image from registration
76- smooth_sigma : :obj:`int`, optional
77- default 1.15, see registration settings
78- block_size : :obj:`tuple`, optional
79- default (128,128), see registration settings
80- maxregshift : :obj:`float`, optional
81- default 0.1, see registration settings
82- maxregshiftNR : :obj:`int`, optional
83- default 10, see registration settings
84- 1Preg : :obj:`bool`, optional
85- default True, see 1Preg settings
86-
87- Returns
88- -------
89- X : float, array
90- nPC x 3 where X[:,0] is rigid, X[:,1] is average nonrigid, X[:,2] is max nonrigid shifts
68+ """
69+ register top and bottom of PCs to each other
70+
71+ Parameters
72+ ----------
73+ pclow : float, array
74+ average of bottom of spatial PC: nPC x Ly x Lx
75+ pchigh : float, array
76+ average of top of spatial PC: nPC x Ly x Lx
77+ bidi_corrected: bool
78+ whether to do bidi correction.
79+ spatial_hp: int
80+ high-pass filter window size for the spatial dimensions
81+ pre_smooth: int
82+ low-pass filter window size for the spatial dimensions
83+ smooth_sigma : int
84+ see registration settings
85+ smooth_sigma_time: int
86+ see registration settings
87+ block_size : int, int
88+ see registration settings
89+ maxregshift : float
90+ see registration settings
91+ maxregshiftNR : int
92+ see registration settings
93+ reg_1p : bool
94+ see 1Preg settings
95+ snr_thresh: float
96+ signal to noise threshold to use.
97+ is_nonrigid: bool
98+ pad_fft: bool
99+ bidiphase: int
100+ spatial_taper: float
101+
102+ Returns
103+ -------
104+ X : float array
105+ nPC x 3 where X[:,0] is rigid, X[:,1] is average nonrigid, X[:,2] is max nonrigid shifts
91106 """
92107 # registration settings
93108 nPC , Ly , Lx = pclow .shape
@@ -176,28 +191,27 @@ def pc_register(pclow, pchigh, bidi_corrected, spatial_hp=None, pre_smooth=None,
176191
177192
178193def get_pc_metrics (ops , use_red = False ):
179- """ computes registration metrics using top PCs of registered movie
180-
181- movie saved as binary file ops['reg_file']
182- metrics saved to ops['regPC'] and ops['X']
183- 'regDX' is nPC x 3 where X[:,0] is rigid, X[:,1] is average nonrigid, X[:,2] is max nonrigid shifts
184- 'regPC' is average of top and bottom frames for each PC
185- 'tPC' is PC across time frames
186-
187- Parameters
188- ----------
189- ops : dictionary
190- 'nframes', 'Ly', 'Lx', 'reg_file' (if use_red=True, 'reg_file_chan2')
191- (optional, 'refImg', 'block_size', 'maxregshiftNR', 'smooth_sigma', 'maxregshift', '1Preg')
192- use_red : :obj:`bool`, optional
193- default False, whether to use 'reg_file' or 'reg_file_chan2'
194- nPC : int
195- # n PCs to compute motion for
196-
197- Returns
198- -------
199- ops : dictionary
200- adds 'regPC' and 'tPC' and 'regDX'
194+ """
195+ Computes registration metrics using top PCs of registered movie
196+
197+ movie saved as binary file ops['reg_file']
198+ metrics saved to ops['regPC'] and ops['X']
199+ 'regDX' is nPC x 3 where X[:,0] is rigid, X[:,1] is average nonrigid, X[:,2] is max nonrigid shifts
200+ 'regPC' is average of top and bottom frames for each PC
201+ 'tPC' is PC across time frames
202+
203+ Parameters
204+ ----------
205+ ops : dict
206+ 'nframes', 'Ly', 'Lx', 'reg_file' (if use_red=True, 'reg_file_chan2')
207+ (optional, 'refImg', 'block_size', 'maxregshiftNR', 'smooth_sigma', 'maxregshift', '1Preg')
208+ use_red : :obj:`bool`, optional
209+ default False, whether to use 'reg_file' or 'reg_file_chan2'
210+
211+ Returns
212+ -------
213+ ops : dict
214+ The same as the ops input, but will now include 'regPC', 'tPC', and 'regDX'.
201215
202216 """
203217 random_state = ops ['reg_metrics_rs' ] if 'reg_metrics_rs' in ops else None
0 commit comments