Skip to content

Commit 17501ef

Browse files
Merge pull request #547 from MouseLand/dev
Dev
2 parents 0858b6b + 08f4702 commit 17501ef

File tree

5 files changed

+265
-177
lines changed

5 files changed

+265
-177
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ install:
5757
- dvc pull -r gdrive-travis
5858
- pip install coveralls
5959
script:
60-
- coverage run --source=suite2p setup.py test
60+
- coverage run --source=suite2p --omit=suite2p/gui/* setup.py test
6161
after_success: coveralls
6262
deploy:
6363
skip_cleanup: true

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929
'sphinx_rtd_theme',
3030
'sphinx-prompt',
3131
'sphinx-autodoc-typehints',
32+
'importlib-metadata',
33+
'natsort',
34+
'rastermap>0.1.0',
35+
'tifffile',
36+
'scanimage-tiff-reader>=1.4.1',
37+
'pyqtgraph',
38+
'importlib-metadata',
39+
'paramiko',
40+
'numpy>=1.16',
41+
'numba>=0.43.1',
42+
'matplotlib',
43+
'scipy',
44+
'h5py',
45+
'scikit-learn',
3246
],
3347
# Note: Available in pypi, but cleaner to install as pyqt from conda.
3448
"gui": [

suite2p/registration/bidiphase.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
from numpy import fft
33

44

5-
def compute(frames) -> int:
6-
""" computes the bidirectional phase offset
7-
8-
sometimes in line scanning there will be offsets between lines;
9-
if ops['do_bidiphase'], then bidiphase is computed and applied
5+
def compute(frames: np.ndarray) -> int:
6+
"""
7+
Returns the bidirectional phase offset, the offset between lines that sometimes occurs in line scanning.
108
119
Parameters
1210
----------
13-
frames : int16
11+
frames : frames x Ly x Lx
1412
random subsample of frames in binary (frames x Ly x Lx)
1513
1614
Returns
@@ -38,14 +36,12 @@ def compute(frames) -> int:
3836

3937

4038
def shift(frames: np.ndarray, bidiphase: int) -> None:
41-
""" shift frames by bidirectional phase offset in-place, bidiphase
42-
43-
sometimes in line scanning there will be offsets between lines;
44-
shifts last axis by bidiphase
39+
"""
40+
Shift last axis of 'frames' by bidirectional phase offset in-place, bidiphase.
4541
4642
Parameters
4743
----------
48-
frames : (frames x Ly x Lx)
44+
frames : frames x Ly x Lx
4945
bidiphase : int
5046
bidirectional phase offset in pixels
5147
"""

suite2p/registration/metrics.py

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,32 @@
1616
from .. import io
1717

1818
def 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):
6365
def 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

178193
def 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

Comments
 (0)