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

Add optional link to Device in ImageSeries #1265

Merged
merged 4 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/pynwb/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from . import register_class, CORE_NAMESPACE
from .base import TimeSeries, Image
from .device import Device


@register_class('ImageSeries', CORE_NAMESPACE)
Expand All @@ -17,7 +18,8 @@ class ImageSeries(TimeSeries):
__nwbfields__ = ('dimension',
'external_file',
'starting_frame',
'format')
'format',
'device')

@docval(*get_docval(TimeSeries.__init__, 'name'), # required
{'name': 'data', 'type': ('array_data', 'data', TimeSeries), 'shape': ([None] * 3, [None] * 4),
Expand All @@ -39,10 +41,12 @@ class ImageSeries(TimeSeries):
{'name': 'dimension', 'type': Iterable,
'doc': 'Number of pixels on x, y, (and z) axes.', 'default': None},
*get_docval(TimeSeries.__init__, 'resolution', 'conversion', 'timestamps', 'starting_time', 'rate',
'comments', 'description', 'control', 'control_description'))
'comments', 'description', 'control', 'control_description'),
{'name': 'device', 'type': Device,
'doc': 'Device used to capture the images/video.', 'default': None},)
def __init__(self, **kwargs):
bits_per_pixel, dimension, external_file, starting_frame, format = popargs(
'bits_per_pixel', 'dimension', 'external_file', 'starting_frame', 'format', kwargs)
bits_per_pixel, dimension, external_file, starting_frame, format, device = popargs(
'bits_per_pixel', 'dimension', 'external_file', 'starting_frame', 'format', 'device', kwargs)
call_docval_func(super(ImageSeries, self).__init__, kwargs)
if external_file is None and self.data is None:
raise ValueError('must supply either external_file or data to ' + self.name)
Expand All @@ -51,6 +55,7 @@ def __init__(self, **kwargs):
self.external_file = external_file
self.starting_frame = starting_frame
self.format = format
self.device = device

@property
def bits_per_pixel(self):
Expand Down Expand Up @@ -109,7 +114,11 @@ class ImageMaskSeries(ImageSeries):
'doc': 'Link to ImageSeries that mask is applied to.'},
*get_docval(ImageSeries.__init__, 'format', 'external_file', 'starting_frame', 'bits_per_pixel',
'dimension', 'resolution', 'conversion', 'timestamps', 'starting_time', 'rate', 'comments',
'description', 'control', 'control_description'))
'description', 'control', 'control_description'),
{'name': 'device', 'type': Device,
'doc': ('Device used to capture the mask data. This field will likely not be needed. '
'The device used to capture the masked ImageSeries data should be stored in the ImageSeries.'),
'default': None},)
def __init__(self, **kwargs):
name, data = popargs('name', 'data', kwargs)
masked_imageseries = popargs('masked_imageseries', kwargs)
Expand Down Expand Up @@ -143,7 +152,7 @@ class OpticalSeries(ImageSeries):
'Must also specify frame of reference.'},
*get_docval(ImageSeries.__init__, 'external_file', 'starting_frame', 'bits_per_pixel',
'dimension', 'resolution', 'conversion', 'timestamps', 'starting_time', 'rate', 'comments',
'description', 'control', 'control_description'))
'description', 'control', 'control_description', 'device'))
def __init__(self, **kwargs):
name, data, = popargs('name', 'data', kwargs)
distance, field_of_view, orientation = popargs('distance', 'field_of_view', 'orientation', kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/ophys.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TwoPhotonSeries(ImageSeries):
'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'))
'comments', 'description', 'control', 'control_description', 'device'))
def __init__(self, **kwargs):
field_of_view, imaging_plane, pmt_gain, scan_line_rate = popargs(
'field_of_view', 'imaging_plane', 'pmt_gain', 'scan_line_rate', kwargs)
Expand Down
49 changes: 39 additions & 10 deletions tests/integration/hdf5/test_image.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
import numpy as np

from pynwb.image import OpticalSeries
from pynwb.testing import NWBH5IOMixin, TestCase
from pynwb.device import Device
from pynwb.image import ImageSeries, OpticalSeries
from pynwb.testing import AcquisitionH5IOMixin, NWBH5IOMixin, TestCase


class TestImageSeriesIO(AcquisitionH5IOMixin, TestCase):

def setUpContainer(self):
""" Return a test ImageSeries to read/write """
self.dev1 = Device('dev1')
iS = ImageSeries(
name='test_iS',
data=np.ones((3, 3, 3)),
unit='unit',
external_file=['external_file'],
starting_frame=[1, 2, 3],
format='tiff',
timestamps=list(),
device=self.dev1,
)
return iS

def addContainer(self, nwbfile):
""" Add the test ElectrodeGroup to the given NWBFile """
nwbfile.add_device(self.dev1)
super().addContainer(nwbfile)


class TestOpticalSeriesIO(NWBH5IOMixin, TestCase):

def setUpContainer(self):
""" Return a test OpticalSeries to read/write """
self.optical_series = OpticalSeries(name='OpticalSeries',
distance=8.,
field_of_view=(4., 5.),
orientation='upper left',
data=np.ones((10, 3, 3)),
unit='m',
format='raw',
timestamps=np.arange(10.))
self.dev1 = Device('dev1')
self.optical_series = OpticalSeries(
name='OpticalSeries',
distance=8.,
field_of_view=(4., 5.),
orientation='upper left',
data=np.ones((10, 3, 3)),
unit='m',
format='raw',
timestamps=np.arange(10.),
device=self.dev1,
)
return self.optical_series

def addContainer(self, nwbfile):
""" Add the test OpticalSeries to the given NWBFile """
nwbfile.add_device(self.dev1)
nwbfile.add_stimulus(self.optical_series)

def getContainer(self, nwbfile):
Expand Down
18 changes: 14 additions & 4 deletions tests/unit/test_image.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import numpy as np

from pynwb import TimeSeries
from pynwb.image import ImageSeries, IndexSeries, ImageMaskSeries, OpticalSeries, \
GrayscaleImage, RGBImage, RGBAImage
from pynwb.device import Device
from pynwb.image import ImageSeries, IndexSeries, ImageMaskSeries, OpticalSeries, GrayscaleImage, RGBImage, RGBAImage
from pynwb.testing import TestCase


class ImageSeriesConstructor(TestCase):

def test_init(self):
iS = ImageSeries(name='test_iS', data=np.ones((3, 3, 3)), unit='unit',
external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list())
dev = Device('test_device')
iS = ImageSeries(
name='test_iS',
data=np.ones((3, 3, 3)),
unit='unit',
external_file=['external_file'],
starting_frame=[1, 2, 3],
format='tiff',
timestamps=list(),
device=dev,
)
self.assertEqual(iS.name, 'test_iS')
self.assertEqual(iS.unit, 'unit')
self.assertEqual(iS.external_file, ['external_file'])
self.assertEqual(iS.starting_frame, [1, 2, 3])
self.assertEqual(iS.format, 'tiff')
self.assertIs(iS.device, dev)
# self.assertEqual(iS.bits_per_pixel, np.nan)


Expand Down