Skip to content

Commit e723dbd

Browse files
Redefine SummaryImage to allow for 3d summary images (#42)
* Add neurodata types for core and ndx-ophys-devices in namespace * Add 3d SummaryImage * Add description attribute to imaging space and segmentation classes * Update mock segmentation functions to use ndx_microscopy.SummaryImage type for summary_images
1 parent b3ba7e0 commit e723dbd

File tree

4 files changed

+82
-41
lines changed

4 files changed

+82
-41
lines changed

spec/ndx-microscopy.extensions.yaml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ groups:
5858
neurodata_type_inc: NWBContainer
5959
doc: Abstract class to contain metadata about the region of physical space that imaging data was recorded from. Extended by PlanarImagingSpace and VolumetricImagingSpace.
6060
datasets:
61-
- name: description
62-
dtype: text
63-
doc: Description of the imaging space.
6461
- name: origin_coordinates
6562
dtype: float64
6663
dims:
@@ -77,6 +74,9 @@ groups:
7774
default_value: micrometers
7875
doc: Measurement units for origin coordinates. The default value is 'micrometers'.
7976
attributes:
77+
- name: description
78+
dtype: text
79+
doc: Description of the imaging space.
8080
- name: location
8181
dtype: text
8282
doc:
@@ -220,15 +220,39 @@ groups:
220220
doc: Results from image segmentation of a specific imaging space.
221221
quantity: "+"
222222

223-
- neurodata_type_def: SummaryImages
224-
neurodata_type_inc: Images
223+
- neurodata_type_def: SummaryImage
224+
neurodata_type_inc: NWBContainer
225225
doc: Summary images that are related to the segmentation, e.g., mean, correlation, maximum projection.
226+
datasets:
227+
- name: data
228+
doc: Summary image data.
229+
dtype: numeric
230+
dims:
231+
- - height
232+
- width
233+
- - height
234+
- width
235+
- depth
236+
shape:
237+
- - null
238+
- null
239+
- - null
240+
- null
241+
- null
242+
attributes:
243+
- name: description
244+
dtype: text
245+
doc: Description of the summary image.
226246

227247
- neurodata_type_def: Segmentation
228248
neurodata_type_inc: DynamicTable
229249
doc: Abstract class to contain the results from image segmentation of a specific imaging space.
250+
attributes:
251+
- name: description
252+
dtype: text
253+
doc: Description of the segmentation method used.
230254
groups:
231-
- neurodata_type_inc: SummaryImages
255+
- neurodata_type_inc: SummaryImage
232256
doc: Summary images that are related to the segmentation, e.g., mean, correlation, maximum projection.
233257
quantity: "*"
234258

spec/ndx-microscopy.namespace.yaml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
namespaces:
2-
- name: ndx-microscopy
3-
doc: Microscopy extension to NWB standard.
4-
author:
5-
- Cody Baker
6-
- Alessandra Trapani
7-
contact:
8-
- cody.baker@catalystneuro.com
9-
- alessandra.trapani@catalystneuro.com
10-
schema:
11-
- namespace: core
12-
- namespace: ndx-ophys-devices
13-
- source: ndx-microscopy.extensions.yaml
14-
version: 0.1.0
2+
- name: ndx-microscopy
3+
doc: Microscopy extension to NWB standard.
4+
author:
5+
- Cody Baker
6+
- Alessandra Trapani
7+
contact:
8+
- cody.baker@catalystneuro.com
9+
- alessandra.trapani@catalystneuro.com
10+
schema:
11+
- namespace: core
12+
neurodata_types:
13+
- Device
14+
- LabMetaData
15+
- NWBContainer
16+
- TimeSeries
17+
- NWBDataInterface
18+
- DynamicTable
19+
- VectorData
20+
- VectorIndex
21+
- DynamicTableRegion
22+
- namespace: ndx-ophys-devices
23+
neurodata_types:
24+
- ExcitationSource
25+
- Indicator
26+
- OpticalFilter
27+
- Photodetector
28+
- DichroicMirror
29+
- source: ndx-microscopy.extensions.yaml
30+
version: 0.1.0

src/pynwb/ndx_microscopy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
)
3636

3737
Microscope = get_class("Microscope", extension_name)
38-
38+
SummaryImage = get_class("SummaryImage", extension_name)
3939
PlanarImagingSpace = get_class("PlanarImagingSpace", extension_name)
4040
VolumetricImagingSpace = get_class("VolumetricImagingSpace", extension_name)
4141

src/pynwb/ndx_microscopy/testing/_mock.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,32 @@ def mock_VolumetricImagingSpace(
114114
return volumetric_imaging_space
115115

116116

117+
def mock_SummaryImage(
118+
*,
119+
name: Optional[str] = None,
120+
description: str = "A mock instance of a SummaryImage type to be used for rapid testing.",
121+
image_shape: Tuple[int, int] = (10, 10),
122+
data: Optional[np.ndarray] = None,
123+
) -> ndx_microscopy.SummaryImage:
124+
name = name or name_generator("SummaryImage")
125+
data = data if data is not None else np.ones(image_shape)
126+
summary_image = ndx_microscopy.SummaryImage(name=name, description=description, data=data)
127+
return summary_image
128+
129+
117130
def mock_Segmentation(
118131
*,
119132
name: Optional[str] = None,
120133
description: str = "A mock instance of a Segmentation type to be used for rapid testing.",
121-
summary_images: Optional[List[pynwb.base.Images]] = None,
134+
summary_images: Optional[List[ndx_microscopy.SummaryImage]] = None,
122135
) -> ndx_microscopy.Segmentation:
123136
"""Base abstract class with summary images."""
124137
name = name or name_generator("Segmentation")
125138

126139
# Create default summary images if none provided
127140
if summary_images is None:
128-
mean_image = pynwb.base.Image(
129-
name="mean", data=np.ones((10, 10)), description="Mean intensity projection" # Example shape
130-
)
131-
max_image = pynwb.base.Image(
132-
name="max", data=np.ones((10, 10)), description="Maximum intensity projection" # Example shape
133-
)
141+
mean_image = mock_SummaryImage(name="mean", description="Mean intensity projection")
142+
max_image = mock_SummaryImage(name="max", description="Maximum intensity projection")
134143
summary_images = [mean_image, max_image]
135144

136145
segmentation = ndx_microscopy.Segmentation(name=name, description=description, summary_images=summary_images)
@@ -145,15 +154,15 @@ def mock_Segmentation2D(
145154
description: str = "A mock instance of a Segmentation2D type to be used for rapid testing.",
146155
number_of_rois: int = 5,
147156
image_shape: Tuple[int, int] = (10, 10),
148-
summary_images: Optional[List[pynwb.base.Images]] = None,
157+
summary_images: Optional[List[ndx_microscopy.SummaryImage]] = None,
149158
) -> ndx_microscopy.Segmentation2D:
150159
"""2D segmentation with image_mask/pixel_mask."""
151160
name = name or name_generator("Segmentation2D")
152161

153162
# Create default summary images if none provided
154163
if summary_images is None:
155-
mean_image = pynwb.base.Image(name="mean", data=np.ones(image_shape), description="Mean intensity projection")
156-
max_image = pynwb.base.Image(name="max", data=np.ones(image_shape), description="Maximum intensity projection")
164+
mean_image = mock_SummaryImage(name="mean", description="Mean intensity projection", image_shape=image_shape)
165+
max_image = mock_SummaryImage(name="max", description="Maximum intensity projection", image_shape=image_shape)
157166
summary_images = [mean_image, max_image]
158167

159168
segmentation_2D = ndx_microscopy.Segmentation2D(
@@ -181,23 +190,15 @@ def mock_Segmentation3D(
181190
description: str = "A mock instance of a Segmentation3D type to be used for rapid testing.",
182191
number_of_rois: int = 5,
183192
image_shape: Tuple[int, int, int] = (10, 10, 10),
184-
summary_images: Optional[List[pynwb.base.Images]] = None,
193+
summary_images: Optional[List[ndx_microscopy.SummaryImage]] = None,
185194
) -> ndx_microscopy.Segmentation3D:
186195
"""3D segmentation with image_mask/voxel_mask."""
187196
name = name or name_generator("Segmentation3D")
188197

189198
# Create default summary images if none provided
190199
if summary_images is None:
191-
mean_image = pynwb.base.Image(
192-
name="mean",
193-
data=np.ones((image_shape[0], image_shape[1])), # Project along Z
194-
description="Mean intensity projection",
195-
)
196-
max_image = pynwb.base.Image(
197-
name="max",
198-
data=np.ones((image_shape[0], image_shape[1])), # Project along Z
199-
description="Maximum intensity projection",
200-
)
200+
mean_image = mock_SummaryImage(name="mean", description="Mean intensity projection", image_shape=image_shape)
201+
max_image = mock_SummaryImage(name="max", description="Maximum intensity projection", image_shape=image_shape)
201202
summary_images = [mean_image, max_image]
202203

203204
volumetric_segmentation = ndx_microscopy.Segmentation3D(

0 commit comments

Comments
 (0)