Skip to content

Commit 179b413

Browse files
committed
add basic tests for EXTRACTSegmentation
1 parent 3b72ab6 commit 179b413

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

src/pynwb/tests/test_extract.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from datetime import datetime
2+
from pathlib import Path
3+
from shutil import rmtree
4+
from tempfile import mkdtemp
5+
6+
import numpy as np
7+
from hdmf.testing import TestCase
8+
from numpy.testing import assert_array_equal
9+
from pynwb import NWBFile, NWBHDF5IO
10+
11+
from ndx_extract import EXTRACTSegmentation
12+
13+
14+
class TestExtractSegmentation(TestCase):
15+
@classmethod
16+
def setUpClass(cls):
17+
cls.file_path = "extract_public_output.mat"
18+
cls.output_struct_name = "output"
19+
20+
cls.session_start_time = datetime.now().astimezone()
21+
22+
cls.image_segmentation_name = "ExtractSegmentation"
23+
24+
def setUp(self):
25+
self.nwbfile = NWBFile(
26+
session_description="session_description",
27+
identifier="file_id",
28+
session_start_time=self.session_start_time,
29+
)
30+
31+
self.tmpdir = Path(mkdtemp())
32+
self.nwbfile_path = self.tmpdir / "test_nwb.nwb"
33+
34+
def tearDown(self):
35+
rmtree(self.tmpdir)
36+
37+
def test_extract_defaults(self):
38+
image_segmentation = EXTRACTSegmentation()
39+
self.assertEqual(image_segmentation.name, "ImageSegmentation")
40+
41+
def test_extract_name_propagates(self):
42+
image_segmentation = EXTRACTSegmentation(name=self.image_segmentation_name)
43+
self.assertEqual(image_segmentation.name, self.image_segmentation_name)
44+
45+
def test_extract_roundtrip(self):
46+
image_segmentation = EXTRACTSegmentation(
47+
name="test_name",
48+
version="1.1.0",
49+
preprocess=True,
50+
movie_mask=np.ones((15, 15)),
51+
)
52+
53+
ophys_module = self.nwbfile.create_processing_module(
54+
name="ophys",
55+
description="optical physiology processed data",
56+
)
57+
58+
ophys_module.add(image_segmentation)
59+
60+
with NWBHDF5IO(self.nwbfile_path, mode="w") as io:
61+
io.write(self.nwbfile)
62+
63+
with NWBHDF5IO(self.nwbfile_path, mode="r") as io:
64+
nwbfile_in = io.read()
65+
66+
movie_mask = (
67+
nwbfile_in.processing["ophys"]
68+
.data_interfaces["test_name"]
69+
.movie_mask[:]
70+
)
71+
72+
assert_array_equal(
73+
movie_mask,
74+
np.ones((15, 15)),
75+
)
76+
77+
self.assertEqual(
78+
nwbfile_in.processing["ophys"].data_interfaces["test_name"].version,
79+
"1.1.0",
80+
)
81+
82+
self.assertEqual(
83+
nwbfile_in.processing["ophys"].data_interfaces["test_name"].preprocess,
84+
True,
85+
)

0 commit comments

Comments
 (0)