Skip to content
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

Adding OnePhotonSeries class #1593

Merged
merged 16 commits into from
Dec 21, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Upcoming

### Enhancements and minor changes
- Added a class and tests for the `OnePhotonSeries`. @CodyCBakerPhD [#1593](https://github.com/NeurodataWithoutBorders/pynwb/pull/1593)
- `Subject.age` can be input as a `timedelta` type. @bendichter [#1590](https://github.com/NeurodataWithoutBorders/pynwb/pull/1590)
- Add `Subject.age__reference` field. @bendichter ([#1540](https://github.com/NeurodataWithoutBorders/pynwb/pull/1540))
- `IntracellularRecordingsTable.add_recording`: the `electrode` arg is now optional, and is automatically populated from the stimulus or response.
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/nwb-schema
Submodule nwb-schema updated 0 files
76 changes: 76 additions & 0 deletions src/pynwb/ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,82 @@ def __init__(self, **kwargs):
setattr(self, key, val)


@register_class("OnePhotonSeries", CORE_NAMESPACE)
class OnePhotonSeries(ImageSeries):
"""Image stack recorded over time from 1-photon microscope."""

__nwbfields__ = (
"imaging_plane", "pmt_gain", "scan_line_rate", "exposure_time", "binning", "power", "intensity"
)

@docval(
*get_docval(ImageSeries.__init__, "name"), # required
{"name": "imaging_plane", "type": ImagingPlane, "doc": "Imaging plane class/pointer."}, # required
*get_docval(ImageSeries.__init__, "data", "unit", "format"),
{"name": "pmt_gain", "type": float, "doc": "Photomultiplier gain.", "default": None},
{
"name": "scan_line_rate",
"type": float,
"doc": (
"Lines imaged per second. This is also stored in /general/optophysiology but is kept "
"here as it is useful information for analysis, and so good to be stored w/ the actual data."
),
"default": None,
},
{
"name": "exposure_time",
"type": float,
"doc": "Exposure time of the sample; often the inverse of the frequency.",
"default": None,
},
{
"name": "binning",
"type": int,
"doc": "Amount of pixels combined into 'bins'; could be 1, 2, 4, 8, etc.",
"default": None,
},
{
"name": "power",
"type": float,
"doc": "Power of the excitation in mW, if known.",
"default": None,
},
{
"name": "intensity",
"type": float,
"doc": "Intensity of the excitation in mW/mm^2, if known.",
"default": None,
},
*get_docval(
ImageSeries.__init__,
"external_file",
"starting_frame",
"bits_per_pixel",
"dimension",
"resolution",
"conversion",
"timestamps",
"starting_time",
"rate",
"comments",
"description",
"control",
"control_description",
"device",
"offset",
)
)
def __init__(self, **kwargs):
keys_to_set = (
"imaging_plane", "pmt_gain", "scan_line_rate", "exposure_time", "binning", "power", "intensity"
)
args_to_set = popargs_to_dict(keys_to_set, kwargs)
super().__init__(**kwargs)

for key, val in args_to_set.items():
setattr(self, key, val)


@register_class('TwoPhotonSeries', CORE_NAMESPACE)
class TwoPhotonSeries(ImageSeries):
"""Image stack recorded over time from 2-photon microscope."""
Expand Down
49 changes: 47 additions & 2 deletions tests/unit/test_ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
from pynwb.base import TimeSeries
from pynwb.device import Device
from pynwb.image import ImageSeries
from pynwb.ophys import (TwoPhotonSeries, RoiResponseSeries, DfOverF, Fluorescence, PlaneSegmentation,
ImageSegmentation, OpticalChannel, ImagingPlane, MotionCorrection, CorrectedImageStack)
from pynwb.ophys import (
OnePhotonSeries,
TwoPhotonSeries,
RoiResponseSeries,
DfOverF,
Fluorescence,
PlaneSegmentation,
ImageSegmentation,
OpticalChannel,
ImagingPlane,
MotionCorrection,
CorrectedImageStack
)
from pynwb.testing import TestCase


Expand Down Expand Up @@ -171,6 +182,40 @@ def test_unit_deprecated(self):
)


class OnePhotonSeriesConstructor(TestCase):

def test_init(self):
ip = create_imaging_plane()
one_photon_series = OnePhotonSeries(
name="test_one_photon_series",
unit="unit",
imaging_plane=ip,
pmt_gain=1.,
scan_line_rate=2.,
exposure_time=123.,
binning=2,
power=9001.,
intensity=5.,
external_file=["external_file"],
starting_frame=[0],
format="external",
timestamps=list(),
)
self.assertEqual(one_photon_series.name, 'test_one_photon_series')
self.assertEqual(one_photon_series.unit, 'unit')
self.assertEqual(one_photon_series.imaging_plane, ip)
self.assertEqual(one_photon_series.pmt_gain, 1.)
self.assertEqual(one_photon_series.scan_line_rate, 2.)
self.assertEqual(one_photon_series.exposure_time, 123.)
self.assertEqual(one_photon_series.binning, 2)
self.assertEqual(one_photon_series.power, 9001.)
self.assertEqual(one_photon_series.intensity, 5.)
self.assertEqual(one_photon_series.external_file, ["external_file"])
self.assertEqual(one_photon_series.starting_frame, [0])
self.assertEqual(one_photon_series.format, "external")
self.assertIsNone(one_photon_series.dimension)


class TwoPhotonSeriesConstructor(TestCase):

def test_init(self):
Expand Down