diff --git a/src/pynwb/ndx_microscopy/testing/_mock.py b/src/pynwb/ndx_microscopy/testing/_mock.py index 2fd4004..2b5e7a3 100644 --- a/src/pynwb/ndx_microscopy/testing/_mock.py +++ b/src/pynwb/ndx_microscopy/testing/_mock.py @@ -78,7 +78,7 @@ def mock_PlanarImagingSpace( name: Optional[str] = None, description: str = "This is a mock instance of a PlanarImagingSpace type to be used for rapid testing.", origin_coordinates: Tuple[float, float, float] = (-1.2, -0.6, -2), - grid_spacing_in_mm: Tuple[float, float, float] = (0.2, 0.2), + grid_spacing_in_um: Tuple[float, float, float] = (20, 20), location: str = "The location targeted by the mock imaging space.", reference_frame: str = "The reference frame of the mock planar imaging space.", ) -> ndx_microscopy.PlanarImagingSpace: @@ -87,7 +87,7 @@ def mock_PlanarImagingSpace( description=description, microscope=microscope, origin_coordinates=origin_coordinates, - grid_spacing_in_mm=grid_spacing_in_mm, + grid_spacing_in_um=grid_spacing_in_um, location=location, reference_frame=reference_frame, ) @@ -100,7 +100,7 @@ def mock_VolumetricImagingSpace( name: Optional[str] = None, description: str = "This is a mock instance of a VolumetricImagingSpace type to be used for rapid testing.", origin_coordinates: Tuple[float, float, float] = (-1.2, -0.6, -2), - grid_spacing_in_mm: Tuple[float, float, float] = (0.2, 0.2, 0.5), + grid_spacing_in_um: Tuple[float, float, float] = (20, 20, 50), location: str = "The location targeted by the mock imaging space.", reference_frame: str = "The reference frame of the mock volumetric imaging space.", ) -> ndx_microscopy.VolumetricImagingSpace: @@ -109,7 +109,7 @@ def mock_VolumetricImagingSpace( description=description, microscope=microscope, origin_coordinates=origin_coordinates, - grid_spacing_in_mm=grid_spacing_in_mm, + grid_spacing_in_um=grid_spacing_in_um, location=location, reference_frame=reference_frame, ) @@ -122,7 +122,12 @@ def mock_MicroscopySegmentations( microscopy_plane_segmentations: Optional[Iterable[ndx_microscopy.MicroscopyPlaneSegmentation]] = None, ) -> ndx_microscopy.MicroscopySegmentations: name = name or name_generator("MicroscopySegmentations") - microscopy_plane_segmentations = microscopy_plane_segmentations or [mock_MicroscopyPlaneSegmentation()] + + microscope = mock_Microscope() + imaging_space = mock_PlanarImagingSpace(microscope=microscope) + microscopy_plane_segmentations = microscopy_plane_segmentations or [ + mock_MicroscopyPlaneSegmentation(imaging_space=imaging_space) + ] segmentations = ndx_microscopy.MicroscopySegmentations( name=name, microscopy_plane_segmentations=microscopy_plane_segmentations @@ -142,11 +147,14 @@ def mock_MicroscopyPlaneSegmentation( name = name or name_generator("MicroscopyPlaneSegmentation") plane_segmentation = ndx_microscopy.MicroscopyPlaneSegmentation( - name=name, description=description, imaging_space=imaging_space + name=name, description=description, imaging_space=imaging_space, id=list(range(number_of_rois)) ) + # plane_segmentation.add_column(name="id", description="", data=list(range(number_of_rois))) + image_masks = list() for _ in range(number_of_rois): - plane_segmentation.add_roi(image_mask=np.zeros(image_shape, dtype=bool)) + image_masks.append(np.zeros(image_shape, dtype=bool)) + plane_segmentation.add_column(name="image_mask", description="", data=image_masks) return plane_segmentation @@ -357,9 +365,9 @@ def mock_MultiChannelMicroscopyVolume( def mock_VariableDepthMultiChannelMicroscopyVolume( *, microscope: ndx_microscopy.Microscope, - light_sources: List[ndx_microscopy.MicroscopyLightSource], imaging_space: ndx_microscopy.VolumetricImagingSpace, - optical_channels: List[ndx_microscopy.MicroscopyOpticalChannel], + light_sources: pynwb.base.VectorData, + optical_channels: pynwb.base.VectorData, name: Optional[str] = None, description: str = "This is a mock instance of a MultiChannelMicroscopyVolume type to be used for rapid testing.", data: Optional[np.ndarray] = None, @@ -382,9 +390,9 @@ def mock_VariableDepthMultiChannelMicroscopyVolume( name=series_name, description=description, microscope=microscope, - light_sources=light_sources[0], # TODO: figure out how to specify list imaging_space=imaging_space, - optical_channels=optical_channels[0], # TODO: figure out how to specify list + light_sources=light_sources, + optical_channels=optical_channels, data=imaging_data, depth_per_frame_in_um=volume_depth_per_frame_in_um, unit=unit, diff --git a/src/pynwb/tests/test_constructors.py b/src/pynwb/tests/test_constructors.py index af884f5..f5c29aa 100644 --- a/src/pynwb/tests/test_constructors.py +++ b/src/pynwb/tests/test_constructors.py @@ -129,15 +129,26 @@ def test_constructor_multi_channel_microscopy_volume(): def test_constructor_variable_depth_multi_channel_microscopy_volume(): microscope = mock_Microscope() - light_source = mock_MicroscopyLightSource() imaging_space = mock_VolumetricImagingSpace(microscope=microscope) - optical_channel = mock_MicroscopyOpticalChannel() + light_sources = [mock_MicroscopyLightSource()] + optical_channels = [mock_MicroscopyOpticalChannel()] + light_sources_used_by_volume = pynwb.base.VectorData( + name="light_sources", description="Light sources used by this MultiChannelVolume.", data=light_sources + ) + optical_channels_used_by_volume = pynwb.base.VectorData( + name="optical_channels", + description=( + "Optical channels ordered to correspond to the third axis (e.g., [0, 0, :, 0]) " + "of the data for this MultiChannelVolume." + ), + data=optical_channels, + ) mock_VariableDepthMultiChannelMicroscopyVolume( microscope=microscope, - light_source=light_source, imaging_space=imaging_space, - optical_channels=[optical_channel], + light_sources=light_sources_used_by_volume, + optical_channels=optical_channels_used_by_volume, ) diff --git a/src/pynwb/tests/test_roundtrip.py b/src/pynwb/tests/test_roundtrip.py index ff17ef3..4d9f830 100644 --- a/src/pynwb/tests/test_roundtrip.py +++ b/src/pynwb/tests/test_roundtrip.py @@ -247,10 +247,10 @@ def tearDown(self): def test_roundtrip(self): nwbfile = mock_NWBFile() - microscope = mock_Microscope() + microscope = mock_Microscope(name="Microscope") nwbfile.add_device(devices=microscope) - imaging_space = mock_PlanarImagingSpace(microscope=microscope) + imaging_space = mock_PlanarImagingSpace(name="PlanarImagingSpace", microscope=microscope) nwbfile.add_lab_meta_data(lab_meta_data=imaging_space) # Would prefer .add_imaging_space() plane_segmentation_1 = mock_MicroscopyPlaneSegmentation( @@ -261,8 +261,10 @@ def test_roundtrip(self): ) microscopy_plane_segmentations = [plane_segmentation_1, plane_segmentation_2] - segmentations = mock_MicroscopySegmentations(microscopy_plane_segmentations=microscopy_plane_segmentations) - processing_module = nwbfile.create_processing_module(name="ophys") + segmentations = mock_MicroscopySegmentations( + name="MicroscopySegmentations", microscopy_plane_segmentations=microscopy_plane_segmentations + ) + processing_module = nwbfile.create_processing_module(name="ophys", description="") processing_module.add(segmentations) with pynwb.NWBHDF5IO(path=self.nwbfile_path, mode="w") as io: