-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Documentation]: question about pynwb.ophys modules #1921
Comments
Thanks for submitting these questions @ssapir. @alessandratrapani would you be able to help answer these questions? |
Hi @ssapir!
The pynwb.ophys.Fluorescence object is intended to store raw fluorescence traces (RoiResponseSereis), while pynwb.ophys.DfOverF is intended to store baseline corrected fluorescence traces.
The
Interesting point, I am not aware of an already existing example but, I can propose this solution (@rly do you think this could be a good solution?): from pynwb.testing.mock.file import mock_NWBFile
from pynwb.testing.mock.ophys import mock_ImagingPlane
from pynwb.ophys import PlaneSegmentation
import numpy as np
nwbfile = mock_NWBFile()
# create a plane segmentation for the higher level of hierarchical image segmentation
plane_segmentation_synapses = PlaneSegmentation(
description="higher level of hierarchical image segmentation",
imaging_plane=mock_ImagingPlane(nwbfile=nwbfile),
name="PlaneSegmentationSynapses",
)
# add synapses masks
for _ in range(3):
plane_segmentation_synapses.add_roi(image_mask=np.zeros((10, 10)))
# create a plane segmentation for the lower level of hierarchical image segmentation
plane_segmentation_subregions = PlaneSegmentation(
description="lower level of hierarchical image segmentation",
imaging_plane=mock_ImagingPlane(nwbfile=nwbfile),
name="PlaneSegmentationSubregions",
)
# adda all subregions masks
for _ in range(10):
plane_segmentation_subregions.add_roi(image_mask=np.zeros((3, 3)))
# create roi table regions pointing to the plane_segmentation_subregions, one for each synapse
table_region_0 = plane_segmentation_subregions.create_roi_table_region(description="description", region=[0,1,2])
table_region_1 = plane_segmentation_subregions.create_roi_table_region(description="description", region=[3,4,5])
table_region_2 = plane_segmentation_subregions.create_roi_table_region(description="description", region=[6,7,8])
# add a column to hold the links to the table region that correspond to each synapse
plane_segmentation_synapses.add_column(name="synapse_subregions",description="description", data=[table_region_1, table_region_2, table_region_3])
if nwbfile is not None:
if "ophys" not in nwbfile.processing:
nwbfile.create_processing_module("ophys", "ophys")
nwbfile.processing["ophys"].add(plane_segmentation_synapses)
nwbfile.processing["ophys"].add(plane_segmentation_subregions) |
@alessandratrapani I think that would be a good solution, but I have one suggestion - it is more conventional to use a single ragged from pynwb.testing.mock.file import mock_NWBFile
from pynwb.testing.mock.ophys import mock_ImagingPlane
from pynwb.ophys import PlaneSegmentation
import numpy as np
nwbfile = mock_NWBFile()
nwbfile.create_processing_module("ophys", "ophys")
# create a plane segmentation for the higher level of hierarchical image segmentation
plane_segmentation_synapses = PlaneSegmentation(
description="higher level of hierarchical image segmentation",
imaging_plane=mock_ImagingPlane(nwbfile=nwbfile),
name="PlaneSegmentationSynapses",
)
nwbfile.processing["ophys"].add(plane_segmentation_synapses)
# add synapses masks
for _ in range(3):
plane_segmentation_synapses.add_roi(image_mask=np.zeros((10, 10)))
# create a plane segmentation for the lower level of hierarchical image segmentation
plane_segmentation_subregions = PlaneSegmentation(
description="lower level of hierarchical image segmentation",
imaging_plane=mock_ImagingPlane(nwbfile=nwbfile),
name="PlaneSegmentationSubregions",
)
nwbfile.processing["ophys"].add(plane_segmentation_subregions)
# adda all subregions masks
for _ in range(10):
plane_segmentation_subregions.add_roi(image_mask=np.zeros((3, 3)))
# add a column to hold references to the rows of the lower level for each higher level
# e.g., synapse 0 refers to subregions with row indices 0, 1, 2.
# synapse 1 refers to subregions with row indices 3, 4, 5.
# synapse 2 refers to subregions with row indices 6, 7.
plane_segmentation_synapses.add_column(name="synapse_subregions", description="description", data=[[0,1,2], [3,4,5], [6,7]], table=plane_segmentation_subregions, index=True)
from pynwb import NWBHDF5IO
with NWBHDF5IO("test_pynwb_1921.nwb", "w") as io:
io.write(nwbfile)
io = NWBHDF5IO("test_pynwb_1921.nwb", "r")
read_nwbfile = io.read()
# this returns the subregions of synapse with row index 2, which are rows 6 and 7 of the subregions table
read_nwbfile.processing["ophys"]["PlaneSegmentationSynapses"][2, "synapse_subregions"]
io.close() I also moved the creation of the ophys module and addition of tables to the ophys module earlier in the script to avoid the warning when creating the DynamicTableRegion column that the linked table doesn't share an ancestor. @ssapir to be clear, what we are proposing in this example code is to create two |
thanks @rly and @alessandratrapani for the suggestions. I will close this issue for now, but please reopen if there are any further questions! |
What would you like changed or added to the documentation and why?
Thank you!
Do you have any interest in helping write or edit the documentation?
Yes.
Code of Conduct
The text was updated successfully, but these errors were encountered: