Skip to content

Commit 76c5bd6

Browse files
updating docs and tests
1 parent 28cd1fb commit 76c5bd6

15 files changed

Lines changed: 8 additions & 684 deletions

.github/workflows/test_and_deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
platform: [ubuntu-latest, windows-latest]
25-
python-version: [3.8]
24+
platform: [ubuntu-latest] #, windows-latest]
25+
python-version: [3.11]
2626

2727
steps:
2828
- uses: actions/checkout@v4

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def data_dir():
1818
data_path.mkdir(exist_ok=True)
1919
download_cached_inputs(data_path)
2020
cached_outputs = data_path.joinpath('test_outputs')
21-
cached_outputs_url = 'https://osf.io/download/6984d8cfe14e1c4246442669'
21+
cached_outputs_url = 'https://osf.io/download/69890166f7d481f73ae24adb'
2222
if not os.path.exists(cached_outputs):
2323
extract_zip(data_path.joinpath('test_outputs.zip'), cached_outputs_url, data_path)
2424
return data_path
@@ -32,7 +32,7 @@ def test_settings(tmpdir, data_dir):
3232
def download_cached_inputs(data_path):
3333
""" Downloads test_input data if not present on machine. This function was created so it can also be used by scripts/generate_test_data.py."""
3434
cached_inputs = data_path.joinpath('test_inputs')
35-
cached_inputs_url = 'https://osf.io/download/6984d9ca54398fbd42f5575d'
35+
cached_inputs_url = 'https://osf.io/download/69890549bffbac83ffe2530a'
3636
if not os.path.exists(cached_inputs):
3737
print('Cached inputs not found. Downloading now...')
3838
extract_zip(data_path.joinpath('test_inputs.zip'), cached_inputs_url, data_path)

mkdocs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
site_name: Suite2p Documentation
2+
3+
repo_name: mouseland/suite2p
4+
repo_url: https://github.com/mouseland/suite2p
5+
26
theme:
37
name: material
48
logo: _static/favicon.ico

scripts/generate_test_data.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
import os
2-
<<<<<<< HEAD
3-
import suite2p
4-
import shutil
5-
import numpy as np
6-
7-
from pathlib import Path
8-
from conftest import initialize_ops, download_cached_inputs #Guarantees that tests and this script use the same ops
9-
from tests.regression.utils import FullPipelineTestUtils, DetectionTestUtils, ExtractionTestUtils
10-
from suite2p.extraction import masks
11-
12-
"""
13-
IMPORTANT: When running this script, make sure to use it in the scripts directory
14-
(e.g., suite2p/scripts). The generated test data will be placed in the directory
15-
suite2p/scripts/test_data. Take the directories in this folder and replace the directories
16-
with the same name in suite2p/data/test_data (e.g.,replace suite2p/data/test_data/1plane1chan1500 with suite2p/scripts/test_data/1plane1chan1500).
17-
"""
18-
=======
192
import suite2p
203
import shutil
214
import numpy as np
@@ -107,7 +90,6 @@ class TestDataConfigs:
10790
'baseline_methods': ['maximin', 'constant', 'constant_prctile'],
10891
'subdirs': ['1plane1chan', '2plane2chan']
10992
}
110-
>>>>>>> suite2p_dev/tomerge
11193

11294
current_dir = Path(os.getcwd())
11395
# Assumes the input file has already been downloaded

tests/regression/test_classification_pipeline.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ def get_stat_iscell(data_dir_path):
1313
return stat, expected_output
1414

1515

16-
<<<<<<< HEAD
17-
def test_classification_output(test_ops, data_dir):
18-
"""
19-
Regression test that checks to see if the main_classify function works. Only checks iscell output.
20-
"""
21-
test_ops['save_path'] = test_ops['save_path0']
22-
=======
2316
def test_classification_output(test_settings, data_dir):
2417
"""
2518
Regression test that checks to see if the main_classify function works. Only checks iscell output.
2619
"""
27-
>>>>>>> suite2p_dev/tomerge
2820
stat, expected_output = get_stat_iscell(data_dir)
2921
iscell = classification.classify(stat, classfile=classification.builtin_classfile)
3022
assert np.allclose(iscell, expected_output, atol=1e-1)

tests/regression/test_detection_pipeline.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,5 @@
11
"""
22
Tests for the Suite2p Detection module.
3-
<<<<<<< HEAD
4-
"""
5-
from pathlib import Path
6-
import numpy as np
7-
import utils
8-
from suite2p import detection
9-
from suite2p.extraction import masks
10-
11-
def detect_wrapper(ops):
12-
"""
13-
Calls the main detect function and compares output dictionaries (cell_pix, cell_masks,
14-
neuropil_masks, stat) with prior output dicts.
15-
"""
16-
for i in range(len(ops)):
17-
op = ops[i]
18-
op['neuropil_extract'] = True
19-
op, stat = detection.detect(ops=op)
20-
output_check = np.load(
21-
op['data_path'][0].parent.joinpath(f"test_outputs/detection/expected_detect_output_{ op['nplanes'] }p{ op['nchannels'] }c{ i }.npy"),
22-
allow_pickle=True
23-
)[()]
24-
#assert np.array_equal(output_check['cell_pix'], cell_pix)
25-
cell_masks, neuropil_masks = masks.create_masks(stat, op['Ly'], op['Lx'], ops=op)
26-
assert all(np.allclose(a, b, rtol=1e-4, atol=5e-2) for a, b in zip(cell_masks, output_check['cell_masks']))
27-
assert all(np.allclose(a, b, rtol=1e-4, atol=5e-2) for a, b in zip(neuropil_masks, output_check['neuropil_masks']))
28-
for gt_dict, output_dict in zip(stat, output_check['stat']):
29-
for k in gt_dict.keys():
30-
if k=='ypix' or k=='xpix' or k=='lam':
31-
assert np.allclose(gt_dict[k], output_dict[k], rtol=1e-4, atol=5e-2)
32-
33-
def test_detection_output_1plane1chan(test_ops):
34-
test_ops.update({
35-
'tiff_list': ['input.tif'],
36-
})
37-
ops = utils.DetectionTestUtils.prepare(
38-
test_ops,
39-
[[test_ops['data_path'][0].joinpath('detection/pre_registered.npy')]],
40-
(404, 360)
41-
)
42-
detect_wrapper(ops)
43-
44-
45-
def test_detection_output_2plane2chan(test_ops):
46-
test_ops.update({
47-
'nchannels': 2,
48-
'nplanes': 2,
49-
})
50-
detection_dir = test_ops['data_path'][0].joinpath('detection')
51-
ops = utils.DetectionTestUtils.prepare(
52-
test_ops,
53-
[
54-
[detection_dir.joinpath('pre_registered01.npy'), detection_dir.joinpath('pre_registered02.npy')],
55-
[detection_dir.joinpath('pre_registered11.npy'), detection_dir.joinpath('pre_registered12.npy')]
56-
]
57-
, (404, 360),
58-
)
59-
ops[0]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p0.npy'))
60-
ops[1]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p1.npy'))
61-
detect_wrapper(ops)
62-
nplanes = test_ops['nplanes']
63-
64-
outputs_to_check = ['redcell']
65-
# rely on the 2plane2chan1500's redcell
66-
for i in range(nplanes):
67-
assert all(utils.compare_list_of_outputs(
68-
outputs_to_check,
69-
utils.get_list_of_data(outputs_to_check, test_ops['data_path'][0].parent.joinpath(f"test_outputs/detection/suite2p/plane{i}")),
70-
utils.get_list_of_data(outputs_to_check, Path(test_ops['save_path0']).joinpath(f"suite2p/plane{i}")),
71-
))
72-
=======
733
Structured to match generate_test_data.py pattern for true regression testing.
744
"""
755
from pathlib import Path
@@ -162,4 +92,3 @@ def test_detection_output_2plane2chan(test_settings):
16292
for k in gt_dict.keys():
16393
if k in ['ypix', 'xpix', 'lam']:
16494
assert np.allclose(gt_dict[k], output_dict[k], rtol=1e-4, atol=5e-2)
165-
>>>>>>> suite2p_dev/tomerge

tests/regression/test_extraction_pipeline.py

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,5 @@
11
"""
22
Tests for the Suite2p Extraction module.
3-
<<<<<<< HEAD
4-
"""
5-
import numpy as np
6-
from suite2p import extraction
7-
from suite2p.io import BinaryFile
8-
9-
from pathlib import Path
10-
import utils
11-
12-
def extract_wrapper(ops):
13-
for plane in range(ops[0]['nplanes']):
14-
curr_op = ops[plane]
15-
plane_dir = Path(curr_op['save_path0']).joinpath(f'suite2p/plane{plane}')
16-
plane_dir.mkdir(exist_ok=True, parents=True)
17-
extract_input = np.load(
18-
curr_op['data_path'][0].parent.joinpath(
19-
'test_outputs',
20-
'detection',
21-
'expected_detect_output_{0}p{1}c{2}.npy'.format(curr_op['nplanes'], curr_op['nchannels'], plane)),
22-
allow_pickle=True
23-
)[()]
24-
#extraction.create_masks_and_extract(curr_op, extract_input['stat'])
25-
stat, F, Fneu, F_chan2, Fneu_chan2 = extraction.create_masks_and_extract(
26-
curr_op,
27-
extract_input['stat'],
28-
extract_input['cell_masks'],
29-
extract_input['neuropil_masks']
30-
)
31-
dF = F - curr_op['neucoeff'] * Fneu
32-
dF = extraction.preprocess(
33-
F=dF,
34-
baseline=curr_op['baseline'],
35-
win_baseline=curr_op['win_baseline'],
36-
sig_baseline=curr_op['sig_baseline'],
37-
fs=curr_op['fs'],
38-
prctile_baseline=curr_op['prctile_baseline']
39-
)
40-
spks = extraction.oasis(F=dF, batch_size=curr_op['batch_size'], tau=curr_op['tau'], fs=curr_op['fs'])
41-
np.save(plane_dir.joinpath('ops.npy'), curr_op)
42-
np.save(plane_dir.joinpath('stat.npy'), stat)
43-
np.save(plane_dir.joinpath('F.npy'), F)
44-
np.save(plane_dir.joinpath('Fneu.npy'), Fneu)
45-
np.save(plane_dir.joinpath('F_chan2.npy'), F_chan2)
46-
np.save(plane_dir.joinpath('Fneu_chan2.npy'), Fneu_chan2)
47-
np.save(plane_dir.joinpath('spks.npy'), spks)
48-
49-
50-
def run_preprocess(f: np.ndarray, test_ops):
51-
=======
523
Structured to match generate_test_data.py pattern for true regression testing.
534
"""
545
import numpy as np
@@ -71,74 +22,11 @@ def test_pre_process_baseline(test_settings):
7122
f = np.load(op['data_path'][0].parent.joinpath('test_outputs/1plane1chan1500/suite2p/plane0/F.npy'))
7223

7324
# Test all baseline methods like generate_test_data.py
74-
>>>>>>> suite2p_dev/tomerge
7525
baseline_vals = ['maximin', 'constant', 'constant_prctile']
7626
for bv in baseline_vals:
7727
pre_f = extraction.preprocess(
7828
F=f,
7929
baseline=bv,
80-
<<<<<<< HEAD
81-
win_baseline=test_ops['win_baseline'],
82-
sig_baseline=test_ops['sig_baseline'],
83-
fs=test_ops['fs'],
84-
prctile_baseline=test_ops['prctile_baseline']
85-
)
86-
test_f = np.load(test_ops['data_path'][0].parent.joinpath('test_outputs/extraction/{}_f.npy'.format(bv)))
87-
yield np.allclose(pre_f, test_f, rtol=1e-4, atol=5e-2)
88-
89-
90-
def test_pre_process_baseline(test_ops):
91-
f = np.load(test_ops['data_path'][0].parent.joinpath('test_outputs/1plane1chan1500/suite2p/plane0/F.npy'))
92-
assert all(run_preprocess(f, test_ops))
93-
94-
95-
def test_extraction_output_1plane1chan(test_ops):
96-
test_ops.update({
97-
'tiff_list': ['input.tif'],
98-
})
99-
ops = utils.ExtractionTestUtils.prepare(
100-
test_ops,
101-
[[test_ops['data_path'][0].joinpath('detection/pre_registered.npy')]],
102-
(404, 360)
103-
)
104-
extract_wrapper(ops)
105-
ops = ops[0]
106-
nplanes = ops['nplanes']
107-
outputs_to_check = ['F', 'Fneu', 'stat', 'spks']
108-
for i in range(nplanes):
109-
assert all(utils.compare_list_of_outputs(
110-
outputs_to_check,
111-
utils.get_list_of_data(outputs_to_check, Path(ops['data_path'][0]).parent.joinpath(f"test_outputs/extraction/1plane1chan/plane0")),
112-
utils.get_list_of_data(outputs_to_check, Path(ops['save_path0']).joinpath(f"suite2p/plane0")),
113-
))
114-
115-
116-
def test_extraction_output_2plane2chan(test_ops):
117-
test_ops.update({
118-
'nchannels': 2,
119-
'nplanes': 2,
120-
'tiff_list': ['input.tif'],
121-
})
122-
detection_dir = test_ops['data_path'][0].joinpath('detection')
123-
ops = utils.ExtractionTestUtils.prepare(
124-
test_ops,
125-
[
126-
[detection_dir.joinpath('pre_registered01.npy'), detection_dir.joinpath('pre_registered02.npy')],
127-
[detection_dir.joinpath('pre_registered11.npy'), detection_dir.joinpath('pre_registered12.npy')]
128-
]
129-
, (404, 360),
130-
)
131-
ops[0]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p0.npy'))
132-
ops[1]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p1.npy'))
133-
extract_wrapper(ops)
134-
outputs_to_check = ['F', 'Fneu', 'F_chan2', 'Fneu_chan2', 'stat', 'spks']
135-
for i in range(len(ops)):
136-
assert all(utils.compare_list_of_outputs(
137-
outputs_to_check,
138-
utils.get_list_of_data(outputs_to_check, Path(ops[i]['data_path'][0].parent.joinpath(f"test_outputs/extraction/2plane2chan/plane{i}"))),
139-
utils.get_list_of_data(outputs_to_check, Path(ops[i]['save_path0']).joinpath(f"suite2p/plane{i}")),
140-
))
141-
=======
14230
win_baseline=op['dcnv_preprocess']['win_baseline'],
14331
sig_baseline=op['dcnv_preprocess']['sig_baseline'],
14432
fs=op['fs'],
@@ -266,4 +154,3 @@ def test_extraction_output_2plane2chan(test_settings):
266154
assert np.allclose(F_chan2, expected_F_chan2, rtol=1e-4, atol=5e-2)
267155
assert np.allclose(Fneu_chan2, expected_Fneu_chan2, rtol=1e-4, atol=5e-2)
268156
assert np.allclose(spks, expected_spks, rtol=1e-4, atol=5e-2)
269-
>>>>>>> suite2p_dev/tomerge

0 commit comments

Comments
 (0)