|
1 | 1 | import os |
| 2 | +from unittest.mock import Mock |
2 | 3 |
|
3 | 4 | import pynwb |
4 | | -from pynwb import NWBHDF5IO |
| 5 | +from pynwb import NWBHDF5IO, ProcessingModule |
5 | 6 |
|
6 | 7 | from datetime import datetime |
7 | 8 | from dateutil.tz import tzlocal |
8 | 9 | from pynwb import NWBFile |
| 10 | +from pynwb.behavior import BehavioralTimeSeries |
9 | 11 | from pynwb.device import Device |
10 | 12 | from pynwb.testing import TestCase |
11 | 13 |
|
| 14 | +from src.pynwb.ndx_franklab_novela.camera_device import CameraDevice |
12 | 15 | from src.pynwb.ndx_franklab_novela.data_acq_device import DataAcqDevice |
13 | 16 | from src.pynwb.ndx_franklab_novela.header_device import HeaderDevice |
14 | 17 | from src.pynwb.ndx_franklab_novela.nwb_electrode_group import NwbElectrodeGroup |
| 18 | +from src.pynwb.ndx_franklab_novela.nwb_image_series import NwbImageSeries |
15 | 19 | from src.pynwb.ndx_franklab_novela.probe import Probe, Shank, ShanksElectrode |
16 | 20 |
|
17 | 21 |
|
@@ -116,6 +120,54 @@ def test_read_nwb_data_acq_device_successfully(self): |
116 | 120 |
|
117 | 121 | self.delete_nwb('data_acq_device') |
118 | 122 |
|
| 123 | + def test_read_nwb_camera_device_successfully(self): |
| 124 | + camera_device = CameraDevice( |
| 125 | + name='CameraDevice1', |
| 126 | + meters_per_pixel=0.20 |
| 127 | + ) |
| 128 | + self.nwb_file_content.add_device(camera_device) |
| 129 | + |
| 130 | + nwb_file_handler = NWBHDF5IO('camera_device.nwb', mode='w') |
| 131 | + nwb_file_handler.write(self.nwb_file_content) |
| 132 | + nwb_file_handler.close() |
| 133 | + |
| 134 | + self.assertTrue(os.path.exists('camera_device.nwb')) |
| 135 | + with pynwb.NWBHDF5IO('camera_device.nwb', 'r', load_namespaces=True) as nwb_file_handler: |
| 136 | + nwb_file = nwb_file_handler.read() |
| 137 | + self.assertContainerEqual(nwb_file.devices['CameraDevice1'], camera_device) |
| 138 | + |
| 139 | + self.delete_nwb('camera_device') |
| 140 | + |
| 141 | + def test_read_nwb_nwb_image_series_successfully(self): |
| 142 | + mock_device_1 = Mock(spec=Device) |
| 143 | + mock_device_2 = Mock(spec=Device) |
| 144 | + mock_timestamps = [1, 2, 3] |
| 145 | + mock_external_file = [] |
| 146 | + |
| 147 | + nwb_image_series = NwbImageSeries( |
| 148 | + name='NwbImageSeries1', |
| 149 | + timestamps=mock_timestamps, |
| 150 | + external_file=mock_external_file, |
| 151 | + devices=[mock_device_1, mock_device_2] |
| 152 | + ) |
| 153 | + behavioral_time_series = BehavioralTimeSeries(name="ImageSeries") |
| 154 | + behavioral_time_series.add_timeseries(nwb_image_series) |
| 155 | + processing_module = ProcessingModule(name='PM_ImageSeries', description='') |
| 156 | + self.nwb_file_content.add_processing_module(processing_module) |
| 157 | + self.nwb_file_content.processing['PM_ImageSeries'].add(behavioral_time_series) |
| 158 | + |
| 159 | + nwb_file_handler = NWBHDF5IO('nwb_image_series.nwb', mode='w') |
| 160 | + nwb_file_handler.write(self.nwb_file_content) |
| 161 | + # nwb_file_handler.close() |
| 162 | + # |
| 163 | + # self.assertTrue(os.path.exists('nwb_image_series.nwb')) |
| 164 | + # with pynwb.NWBHDF5IO('nwb_image_series.nwb', 'r', load_namespaces=True) as nwb_file_handler: |
| 165 | + # nwb_file = nwb_file_handler.read() |
| 166 | + # print(nwb_file.processing['PM_ImageSeries']) |
| 167 | + # self.assertContainerEqual(nwb_file.processing['PM_ImageSeries'], nwb_image_series) |
| 168 | + # |
| 169 | + # self.delete_nwb('nwb_image_series') |
| 170 | + |
119 | 171 | def test_read_nwb_nwb_electrode_group_successfully(self): |
120 | 172 | device = Device('device_0') |
121 | 173 | self.nwb_file_content.add_device(device) |
|
0 commit comments