From 4d90ec98c7d2f3bb54c12e1b6b806c611dfbba0e Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Fri, 27 Oct 2023 16:45:29 +0200 Subject: [PATCH 1/3] add default view for OnePhotonSeries --- nwbwidgets/view.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nwbwidgets/view.py b/nwbwidgets/view.py index 2dbf2e19..b7f56355 100644 --- a/nwbwidgets/view.py +++ b/nwbwidgets/view.py @@ -42,7 +42,7 @@ ) from .ophys import ( RoiResponseSeriesWidget, - TwoPhotonSeriesWidget, + PhotonSeriesWidget, route_plane_segmentation, show_df_over_f, show_grayscale_volume, @@ -78,7 +78,8 @@ def show_dynamic_table(node, **kwargs) -> widgets.Widget: pynwb.file.Subject: show_fields, pynwb.ecephys.SpikeEventSeries: show_spike_event_series, pynwb.ophys.ImageSegmentation: show_image_segmentation, - pynwb.ophys.TwoPhotonSeries: TwoPhotonSeriesWidget, + pynwb.ophys.TwoPhotonSeries: PhotonSeriesWidget, + pynwb.ophys.OnePhotonSeries: PhotonSeriesWidget, ndx_grayscalevolume.GrayscaleVolume: show_grayscale_volume, pynwb.ophys.PlaneSegmentation: route_plane_segmentation, pynwb.ophys.DfOverF: show_df_over_f, From b362b7eb4b2e0bdece08261bc15499e5939fedb6 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Fri, 27 Oct 2023 17:03:53 +0200 Subject: [PATCH 2/3] add test for widget --- test/test_ophys.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/test_ophys.py b/test/test_ophys.py index 63c92654..5388bac0 100644 --- a/test/test_ophys.py +++ b/test/test_ophys.py @@ -11,13 +11,13 @@ ImagingPlane, OpticalChannel, PlaneSegmentation, - TwoPhotonSeries, + TwoPhotonSeries, OnePhotonSeries, ) from pynwb.testing.mock.ophys import mock_PlaneSegmentation from nwbwidgets.ophys import ( PlaneSegmentation2DWidget, - TwoPhotonSeriesWidget, + PhotonSeriesWidget, show_df_over_f, show_grayscale_volume, show_image_segmentation, @@ -61,6 +61,16 @@ def setUpClass(self): rate=1.0, unit="n.a", ) + + self.one_photon_series = OnePhotonSeries( + name="test_one_photon_series", + data=np.random.randn(100, 5, 5), + imaging_plane=self.imaging_plane, + starting_frame=[0], + rate=1.0, + unit="n.a.", + ) + self.img_seg = ImageSegmentation() self.ps2 = self.img_seg.create_plane_segmentation( "output from segmenting my favorite imaging plane", @@ -105,7 +115,7 @@ def setUpClass(self): self.df_over_f = DfOverF(rrs) def test_show_two_photon_series(self): - wid = TwoPhotonSeriesWidget(self.image_series, default_neurodata_vis_spec) + wid = PhotonSeriesWidget(self.image_series, default_neurodata_vis_spec) assert isinstance(wid, widgets.Widget) wid.controls["slider"].value = 50 @@ -118,7 +128,12 @@ def test_show_3d_two_photon_series(self): rate=1.0, unit="n.a", ) - wid = TwoPhotonSeriesWidget(image_series3, default_neurodata_vis_spec) + wid = PhotonSeriesWidget(image_series3, default_neurodata_vis_spec) + assert isinstance(wid, widgets.Widget) + wid.controls["slider"].value = 50 + + def test_show_one_photon_series(self): + wid = PhotonSeriesWidget(self.one_photon_series, default_neurodata_vis_spec) assert isinstance(wid, widgets.Widget) wid.controls["slider"].value = 50 From 395ef955c3d73f6f78f43c0c3f74c01f07cccef6 Mon Sep 17 00:00:00 2001 From: weiglszonja Date: Fri, 27 Oct 2023 17:04:48 +0200 Subject: [PATCH 3/3] refactor widget to PhotonSeriesWidget --- nwbwidgets/ophys.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nwbwidgets/ophys.py b/nwbwidgets/ophys.py index 7f864bfd..59ebe78b 100644 --- a/nwbwidgets/ophys.py +++ b/nwbwidgets/ophys.py @@ -1,4 +1,5 @@ from functools import lru_cache +from typing import Union import ipywidgets as widgets import numpy as np @@ -11,6 +12,7 @@ ImageSegmentation, PlaneSegmentation, RoiResponseSeries, + OnePhotonSeries, TwoPhotonSeries, ) from skimage import measure @@ -25,10 +27,10 @@ color_wheel = px.colors.qualitative.Dark24 -class TwoPhotonSeriesWidget(widgets.VBox): - """Widget showing Image stack recorded over time from 2-photon microscope.""" +class PhotonSeriesWidget(widgets.VBox): + """Widget showing Image stack recorded over time from 2-photon or 1-photon microscope.""" - def __init__(self, indexed_timeseries: TwoPhotonSeries, neurodata_vis_spec: dict): + def __init__(self, indexed_timeseries: Union[TwoPhotonSeries, OnePhotonSeries], neurodata_vis_spec: dict): super().__init__() def _add_fig_trace(img_fig: go.Figure, index):