11"""
22Tests 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- == == == =
523Structured to match generate_test_data.py pattern for true regression testing.
534"""
545import 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