Skip to content

Commit

Permalink
Merge branch 'all_previous_prs_and_variable_depth_static' into swap_t…
Browse files Browse the repository at this point in the history
…o_um
  • Loading branch information
CodyCBakerPhD authored Jul 18, 2024
2 parents a3ea976 + 5400462 commit 8e67e51
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
30 changes: 19 additions & 11 deletions src/pynwb/ndx_microscopy/testing/_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
)
Expand All @@ -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:
Expand All @@ -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,
)
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions src/pynwb/tests/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
10 changes: 6 additions & 4 deletions src/pynwb/tests/test_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down

0 comments on commit 8e67e51

Please sign in to comment.