-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b01ba6
commit 448c29b
Showing
1 changed file
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
"""Test roundtrip (write and read back) of the Python API for the ndx-microscopy extension.""" | ||
|
||
from pynwb.testing import TestCase as pynwb_TestCase | ||
from pynwb.testing.mock.file import mock_NWBFile | ||
|
||
import pynwb | ||
from ndx_microscopy.testing import ( | ||
mock_LightSource, | ||
mock_Microscope, | ||
mock_MicroscopyOpticalChannel, | ||
mock_PlanarImagingSpace, | ||
mock_PlanarMicroscopySeries, | ||
mock_VariableDepthMicroscopySeries, | ||
mock_VolumetricImagingSpace, | ||
mock_VolumetricMicroscopySeries, | ||
) | ||
|
||
|
||
class TestPlanarMicroscopySeriesSimpleRoundtrip(pynwb_TestCase): | ||
"""Simple roundtrip test for PlanarMicroscopySeries.""" | ||
|
||
def setUp(self): | ||
self.nwbfile_path = "test.nwb" | ||
|
||
def tearDown(self): | ||
pynwb.testing.remove_test_file(self.nwbfile_path) | ||
|
||
def test_roundtrip(self): | ||
nwbfile = mock_NWBFile() | ||
|
||
microscope = mock_Microscope(name="Microscope") | ||
nwbfile.add_device(devices=microscope) | ||
|
||
light_source = mock_LightSource(name="LightSource") | ||
nwbfile.add_device(devices=light_source) | ||
|
||
imaging_space = mock_PlanarImagingSpace(name="PlanarImagingSpace", microscope=microscope) | ||
nwbfile.add_lab_meta_data(lab_meta_data=imaging_space) # Would prefer .add_imaging_spacec() | ||
|
||
optical_channel = mock_MicroscopyOpticalChannel(name="MicroscopyOpticalChannel") | ||
nwbfile.add_lab_meta_data(lab_meta_data=optical_channel) | ||
|
||
planar_microscopy_series = mock_PlanarMicroscopySeries( | ||
name="PlanarMicroscopySeries", | ||
microscope=microscope, | ||
light_source=light_source, | ||
imaging_space=imaging_space, | ||
optical_channel=optical_channel, | ||
) | ||
nwbfile.add_acquisition(nwbdata=planar_microscopy_series) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="w") as io: | ||
io.write(nwbfile) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="r", load_namespaces=True) as io: | ||
read_nwbfile = io.read() | ||
|
||
self.assertContainerEqual(microscope, read_nwbfile.devices["Microscope"]) | ||
self.assertContainerEqual(light_source, read_nwbfile.devices["LightSource"]) | ||
|
||
self.assertContainerEqual(imaging_space, read_nwbfile.lab_meta_data["PlanarImagingSpace"]) | ||
self.assertContainerEqual(optical_channel, read_nwbfile.lab_meta_data["MicroscopyOpticalChannel"]) | ||
|
||
self.assertContainerEqual(planar_microscopy_series, read_nwbfile.acquisition["PlanarMicroscopySeries"]) | ||
|
||
|
||
class TestVolumetricMicroscopySeriesSimpleRoundtrip(pynwb_TestCase): | ||
"""Simple roundtrip test for VolumetricMicroscopySeries.""" | ||
|
||
def setUp(self): | ||
self.nwbfile_path = "test.nwb" | ||
|
||
def tearDown(self): | ||
pynwb.testing.remove_test_file(self.nwbfile_path) | ||
|
||
def test_roundtrip(self): | ||
nwbfile = mock_NWBFile() | ||
|
||
microscope = mock_Microscope(name="Microscope") | ||
nwbfile.add_device(devices=microscope) | ||
|
||
light_source = mock_LightSource(name="LightSource") | ||
nwbfile.add_device(devices=light_source) | ||
|
||
imaging_space = mock_VolumetricImagingSpace(name="VolumetricImagingSpace", microscope=microscope) | ||
nwbfile.add_lab_meta_data(lab_meta_data=imaging_space) # Would prefer .add_imaging_spacec() | ||
|
||
optical_channel = mock_MicroscopyOpticalChannel(name="MicroscopyOpticalChannel") | ||
nwbfile.add_lab_meta_data(lab_meta_data=optical_channel) | ||
|
||
volumetric_microscopy_series = mock_VolumetricMicroscopySeries( | ||
name="VolumetricMicroscopySeries", | ||
microscope=microscope, | ||
light_source=light_source, | ||
imaging_space=imaging_space, | ||
optical_channel=optical_channel, | ||
) | ||
nwbfile.add_acquisition(nwbdata=volumetric_microscopy_series) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="w") as io: | ||
io.write(nwbfile) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="r", load_namespaces=True) as io: | ||
read_nwbfile = io.read() | ||
|
||
self.assertContainerEqual(microscope, read_nwbfile.devices["Microscope"]) | ||
self.assertContainerEqual(light_source, read_nwbfile.devices["LightSource"]) | ||
|
||
self.assertContainerEqual(imaging_space, read_nwbfile.lab_meta_data["VolumetricImagingSpace"]) | ||
self.assertContainerEqual(optical_channel, read_nwbfile.lab_meta_data["MicroscopyOpticalChannel"]) | ||
|
||
self.assertContainerEqual( | ||
volumetric_microscopy_series, read_nwbfile.acquisition["VolumetricMicroscopySeries"] | ||
) | ||
|
||
|
||
class TestVariableDepthMicroscopySeriesSimpleRoundtrip(pynwb_TestCase): | ||
"""Simple roundtrip test for VariableDepthMicroscopySeries.""" | ||
|
||
def setUp(self): | ||
self.nwbfile_path = "test.nwb" | ||
|
||
def tearDown(self): | ||
pynwb.testing.remove_test_file(self.nwbfile_path) | ||
|
||
def test_roundtrip(self): | ||
nwbfile = mock_NWBFile() | ||
|
||
microscope = mock_Microscope(name="Microscope") | ||
nwbfile.add_device(devices=microscope) | ||
|
||
light_source = mock_LightSource(name="LightSource") | ||
nwbfile.add_device(devices=light_source) | ||
|
||
imaging_space = mock_PlanarImagingSpace(name="PlanarImagingSpace", microscope=microscope) | ||
nwbfile.add_lab_meta_data(lab_meta_data=imaging_space) # Would prefer .add_imaging_spacec() | ||
|
||
optical_channel = mock_MicroscopyOpticalChannel(name="MicroscopyOpticalChannel") | ||
nwbfile.add_lab_meta_data(lab_meta_data=optical_channel) | ||
|
||
variable_depth_microscopy_series = mock_VariableDepthMicroscopySeries( | ||
name="VariableDepthMicroscopySeries", | ||
microscope=microscope, | ||
light_source=light_source, | ||
imaging_space=imaging_space, | ||
optical_channel=optical_channel, | ||
) | ||
nwbfile.add_acquisition(nwbdata=variable_depth_microscopy_series) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="w") as io: | ||
io.write(nwbfile) | ||
|
||
with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="r", load_namespaces=True) as io: | ||
read_nwbfile = io.read() | ||
|
||
self.assertContainerEqual(microscope, read_nwbfile.devices["Microscope"]) | ||
self.assertContainerEqual(light_source, read_nwbfile.devices["LightSource"]) | ||
|
||
self.assertContainerEqual(imaging_space, read_nwbfile.lab_meta_data["PlanarImagingSpace"]) | ||
self.assertContainerEqual(optical_channel, read_nwbfile.lab_meta_data["MicroscopyOpticalChannel"]) | ||
|
||
self.assertContainerEqual( | ||
variable_depth_microscopy_series, read_nwbfile.acquisition["VariableDepthMicroscopySeries"] | ||
) |