Skip to content

Commit

Permalink
change imaging_rate to be optional (#1221)
Browse files Browse the repository at this point in the history
* change imaging_rate to be optional

* use kwargs for all the ImagingPlane tests

* more kwargs

* update ophys tutorial

* flake8

Co-authored-by: Ryan Ly <[email protected]>
  • Loading branch information
bendichter and rly authored Apr 14, 2020
1 parent 05b5c8f commit 856c6b5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
11 changes: 6 additions & 5 deletions docs/gallery/domain/ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from datetime import datetime
from dateutil.tz import tzlocal

import numpy as np

from pynwb import NWBFile
from pynwb.ophys import TwoPhotonSeries, OpticalChannel, ImageSegmentation, Fluorescence
from pynwb.device import Device
Expand Down Expand Up @@ -53,9 +51,12 @@
device = Device('imaging_device_1')
nwbfile.add_device(device)
optical_channel = OpticalChannel('my_optchan', 'description', 500.)
imaging_plane = nwbfile.create_imaging_plane('my_imgpln', optical_channel, 'a very interesting part of the brain',
device, 600., 300., 'GFP', 'my favorite brain location',
np.ones((5, 5, 3)), 4.0, 'manifold unit', 'A frame to refer to')
imaging_plane = nwbfile.create_imaging_plane('my_imgpln', optical_channel,
description='a very interesting part of the brain',
device=device, excitation_lambda=600., imaging_rate=300., indicator='GFP',
location='my favorite brain location',
reference_frame='A frame to refer to',
grid_spacing=(.01, .01))


####################
Expand Down
4 changes: 3 additions & 1 deletion src/pynwb/ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class ImagingPlane(NWBContainer):
{'name': 'description', 'type': str, 'doc': 'Description of this ImagingPlane.'}, # required
{'name': 'device', 'type': Device, 'doc': 'the device that was used to record'}, # required
{'name': 'excitation_lambda', 'type': 'float', 'doc': 'Excitation wavelength in nm.'}, # required
{'name': 'imaging_rate', 'type': 'float', 'doc': 'Rate images are acquired, in Hz.'}, # required
{'name': 'indicator', 'type': str, 'doc': 'Calcium indicator'}, # required
{'name': 'location', 'type': str, 'doc': 'Location of image plane.'}, # required
{'name': 'imaging_rate', 'type': 'float',
'doc': 'Rate images are acquired, in Hz. If the corresponding TimeSeries is present, the rate should be '
'stored there instead.', 'default': None},
{'name': 'manifold', 'type': 'array_data',
'doc': ('DEPRECATED: Physical position of each pixel. size=("height", "width", "xyz"). '
'Deprecated in favor of origin_coords and grid_spacing.'),
Expand Down
31 changes: 17 additions & 14 deletions tests/integration/hdf5/test_ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def setUpContainer(self):
""" Return the test ImagingPlane to read/write """
self.device = Device(name='dev1')
self.optical_channel = OpticalChannel('optchan1', 'a fake OpticalChannel', 500.)
return ImagingPlane('imgpln1', self.optical_channel, 'a fake ImagingPlane', self.device,
600., 300., 'GFP', 'somewhere in the brain', reference_frame='unknonwn')
return ImagingPlane('imgpln1', self.optical_channel, description='a fake ImagingPlane', device=self.device,
excitation_lambda=600., imaging_rate=300., indicator='GFP',
location='somewhere in the brain', reference_frame='unknonwn')

def addContainer(self, nwbfile):
""" Add the test ImagingPlane and Device to the given NWBFile """
Expand All @@ -39,8 +40,9 @@ def make_imaging_plane(self):
""" Make an ImagingPlane and related objects """
self.device = Device(name='dev1')
self.optical_channel = OpticalChannel('optchan1', 'a fake OpticalChannel', 500.)
self.imaging_plane = ImagingPlane('imgpln1', self.optical_channel, 'a fake ImagingPlane', self.device,
600., 300., 'GFP', 'somewhere in the brain', reference_frame='unknown')
self.imaging_plane = ImagingPlane('imgpln1', self.optical_channel, description='a fake ImagingPlane',
device=self.device, excitation_lambda=600., imaging_rate=300.,
indicator='GFP', location='somewhere in the brain', reference_frame='unknown')

def setUpContainer(self):
""" Return the test TwoPhotonSeries to read/write """
Expand Down Expand Up @@ -79,11 +81,12 @@ def buildPlaneSegmentation(self):
'optical channel description', 500.)
self.imaging_plane = ImagingPlane('imgpln1',
self.optical_channel,
'a fake ImagingPlane',
self.device,
600., 200., 'GFP', 'somewhere in the brain',
(((1., 2., 3.), (4., 5., 6.)),),
2., 'a unit',
description='a fake ImagingPlane',
device=self.device,
excitation_lambda=600., imaging_rate=200., indicator='GFP',
location='somewhere in the brain',
manifold=(((1., 2., 3.), (4., 5., 6.)),),
conversion=2., unit='a unit',
reference_frame='unknown')

self.img_mask = deepcopy(img_mask)
Expand Down Expand Up @@ -131,11 +134,11 @@ def buildPlaneSegmentationNoRois(self):
'optical channel description', 500.)
self.imaging_plane = ImagingPlane('test_imaging_plane',
self.optical_channel,
'imaging plane description',
self.device,
600., 300., 'GFP', 'somewhere in the brain',
(((1., 2., 3.), (4., 5., 6.)),),
4.0, 'manifold unit', 'A frame to refer to')
description='imaging plane description',
device=self.device,
excitation_lambda=600., imaging_rate=300., indicator='GFP',
location='somewhere in the brain', manifold=(((1., 2., 3.), (4., 5., 6.)),),
conversion=4.0, unit='manifold unit', reference_frame='A frame to refer to')
return PlaneSegmentation('description', self.imaging_plane, 'test_plane_seg_name',
self.image_series)

Expand Down
33 changes: 19 additions & 14 deletions tests/unit/test_ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def CreatePlaneSegmentation():

oc = OpticalChannel('test_optical_channel', 'description', 500.)
device = Device(name='device_name')
ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600.,
300., 'indicator', 'location', reference_frame='reference_frame')
ip = ImagingPlane(name='test_imaging_plane', optical_channel=oc, description='description', device=device,
excitation_lambda=600., imaging_rate=300., indicator='indicator', location='location',
reference_frame='reference_frame')

pS = PlaneSegmentation('description', ip, 'test_name', iSS)
pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0])
Expand All @@ -36,8 +37,9 @@ def test_init(self):
self.assertEqual(oc.emission_lambda, 500.)

device = Device(name='device_name')
ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600.,
300., 'indicator', 'location', reference_frame='reference_frame',
ip = ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location',
reference_frame='reference_frame',
origin_coords=[10, 20], origin_coords_unit='oc_unit',
grid_spacing=[1, 2, 3], grid_spacing_unit='gs_unit')
self.assertEqual(ip.optical_channel[0], oc)
Expand Down Expand Up @@ -69,8 +71,9 @@ def test_init(self):
def test_args(self):
oc = OpticalChannel('test_name', 'description', 500.)
device = Device(name='device_name')
ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600.,
300., 'indicator', 'location', reference_frame='reference_frame')
ip = ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location',
reference_frame='reference_frame')
with self.assertRaises(ValueError): # no data or external file
TwoPhotonSeries('test_tPS', unit='unit', field_of_view=[2., 3.],
imaging_plane=ip, pmt_gain=1.0, scan_line_rate=2.0,
Expand All @@ -85,8 +88,9 @@ def test_manifold_deprecated(self):

msg = "The 'manifold' argument is deprecated in favor of 'origin_coords' and 'grid_spacing'."
with self.assertWarnsWith(DeprecationWarning, msg):
ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location',
(1, 1, (2, 2, 2)))
ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location',
manifold=(1, 1, (2, 2, 2)))

def test_conversion_deprecated(self):
oc = OpticalChannel('test_name', 'description', 500.)
Expand All @@ -97,8 +101,8 @@ def test_conversion_deprecated(self):

msg = "The 'conversion' argument is deprecated in favor of 'origin_coords' and 'grid_spacing'."
with self.assertWarnsWith(DeprecationWarning, msg):
ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location',
None, 2.0)
ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location', conversion=2.0)

def test_unit_deprecated(self):
oc = OpticalChannel('test_name', 'description', 500.)
Expand All @@ -109,8 +113,8 @@ def test_unit_deprecated(self):

msg = "The 'unit' argument is deprecated in favor of 'origin_coords_unit' and 'grid_spacing_unit'."
with self.assertWarnsWith(DeprecationWarning, msg):
ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location',
None, 1.0, 'my_unit')
ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location', conversion=1.0, unit='my_unit')


class MotionCorrectionConstructor(TestCase):
Expand Down Expand Up @@ -190,8 +194,9 @@ def getBoilerPlateObjects(self):

device = Device(name='device_name')
oc = OpticalChannel('test_optical_channel', 'description', 500.)
ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600.,
300., 'indicator', 'location', reference_frame='reference_frame')
ip = ImagingPlane('test_imaging_plane', oc, description='description', device=device, excitation_lambda=600.,
imaging_rate=300., indicator='indicator', location='location',
reference_frame='reference_frame')
return iSS, ip

def create_basic_plane_segmentation(self):
Expand Down

0 comments on commit 856c6b5

Please sign in to comment.