def buildPlaneSegmentationNoRois(self): """ Return an PlaneSegmentation and set related objects """ ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.device = Device(name='dev1') self.optical_channel = OpticalChannel( name='test_optical_channel', description='optical channel description', emission_lambda=500.) self.imaging_plane = ImagingPlane( name='test_imaging_plane', optical_channel=self.optical_channel, description='imaging plane description', device=self.device, excitation_lambda=600., imaging_rate=300., indicator='GFP', location='somewhere in the brain', reference_frame='a frame to refer to') return PlaneSegmentation(description='description', imaging_plane=self.imaging_plane, name='test_plane_seg_name', reference_images=self.image_series)
def buildPlaneSegmentation(self): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [(1, 2, 1.0), (3, 4, 1.0), (5, 6, 1.0), (7, 8, 2.0), (9, 10, 2.)] ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', source='a hypothetical source', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.optical_channel = OpticalChannel('test_optical_channel', 'optical channel source', 'optical channel description', 500.) self.imaging_plane = ImagingPlane( 'test_imaging_plane', 'ophys integration tests', self.optical_channel, 'imaging plane description', 'imaging_device_1', 600., '2.718', 'GFP', 'somewhere in the brain', (1, 2, 1, 2, 3), 4.0, 'manifold unit', 'A frame to refer to') self.img_mask = deepcopy(img_mask) self.pix_mask = deepcopy(pix_mask) pS = PlaneSegmentation('integration test PlaneSegmentation', 'plane segmentation description', self.imaging_plane, 'test_plane_seg_name', self.image_series) pS.add_roi('1234', pix_mask[0:3], img_mask[0]) pS.add_roi('5678', pix_mask[3:5], img_mask[1]) return pS
def test_init(self): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS = ImageSeries(name='test_iS', source='a hypothetical source', data=list(), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list()) oc = OpticalChannel('test_optical_channel', 'test_source', 'description', 500.) ip = ImagingPlane('test_imaging_plane', 'test_source', oc, 'description', 'device', 600., 'imaging_rate', 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') pS = PlaneSegmentation('test source', 'description', ip, 'test_name', iSS) pS.add_roi("1234", pix_mask[0:3], img_mask[0]) pS.add_roi("5678", pix_mask[3:5], img_mask[1]) self.assertEqual(pS.description, 'description') self.assertEqual(pS.source, 'test source') self.assertEqual(pS.imaging_plane, ip) self.assertEqual(pS.reference_images, iSS) self.assertEqual(pS.pixel_masks.data, pix_mask) self.assertEqual(pS.image_masks.data, img_mask)
def CreatePlaneSegmentation(): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS = ImageSeries(name='test_iS', source='a hypothetical source', data=list(), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list()) oc = OpticalChannel('test_optical_channel', 'test_source', 'description', 'emission_lambda') ip = ImagingPlane('test_imaging_plane', 'test_source', oc, 'description', 'device', 'excitation_lambda', 'imaging_rate', 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') pS = PlaneSegmentation('test source', 'description', ip, 'test_name', iSS) pS.add_roi(pix_mask[0:3], img_mask[0]) pS.add_roi(pix_mask[3:5], img_mask[1]) return pS
def cicada_add_plane_segmentation(self): """ class pynwb.ophys.PlaneSegmentation(description, imaging_plane, name=None, reference_images=None, id=None, columns=None, colnames=None) """ required_metadata = ["plane_segmentation_description"] metadata_to_add = list( set(required_metadata) - set(list(self.data['ophys_metadata'].keys()))) for i in metadata_to_add: self.data["ophys_metadata"] = self.add_required_metadata( self.data["ophys_metadata"], i, "ophys") # Nom du module où récupérer les infos de métadonnée name_module = "plane_segmentation_" self.plane_segmentation = PlaneSegmentation( description=self.data['ophys_metadata'].get(name_module + "description"), imaging_plane=self.imaging_plane, name=self.data['ophys_metadata'].get(name_module + "name"), reference_images=self.data['ophys_metadata'].get( name_module + "reference_image"), id=self.data['ophys_metadata'].get(name_module + "id"), columns=self.data['ophys_metadata'].get(name_module + "columns"), colnames=self.data['ophys_metadata'].get(name_module + "colnames")) self.image_segmentation.add_plane_segmentation(self.plane_segmentation)
def CreatePlaneSegmentation(): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS = ImageSeries(name='test_iS', data=np.ones((2, 2, 2)), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=[1., 2.]) oc = OpticalChannel('test_optical_channel', 'description', 500.) device = Device(name='device_name') ip = ImagingPlane('test_imaging_plane', oc, 'description', device, 600., 300., 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) return pS
def CreatePlaneSegmentation(): w, h = 5, 5 img_mask = [[0 for x in range(w)] for y in range(h)] w, h = 5, 2 pix_mask = [[0 for x in range(w)] for y in range(h)] pix_mask_weight = [0 for x in range(w)] iSS = ImageSeries(name='test_iS', source='a hypothetical source', data=list(), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=list()) roi1 = ROI('roi1', 'test source', 'roi description1', pix_mask, pix_mask_weight, img_mask, iSS) roi2 = ROI('roi2', 'test source', 'roi description2', pix_mask, pix_mask_weight, img_mask, iSS) roi_list = (roi1, roi2) oc = OpticalChannel('test_optical_channel', 'test_source', 'description', 'emission_lambda') ip = ImagingPlane('test_imaging_plane', 'test_source', oc, 'description', 'device', 'excitation_lambda', 'imaging_rate', 'indicator', 'location', (1, 2, 1, 2, 3), 4.0, 'unit', 'reference_frame') ps = PlaneSegmentation('name', 'test source', 'description', roi_list, ip, iSS) return ps
def create_basic_plane_segmentation(self): """Creates a basic plane segmentation used for testing""" iSS, ip = self.set_up_dependencies() pS = PlaneSegmentation(description='description', imaging_plane=ip, name='test_name', reference_images=iSS) return iSS, ip, pS
def test_init_3d_image_mask(self): img_masks = np.random.randn(2, 20, 30, 4) iSS, ip = self.getBoilerPlateObjects() pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(image_mask=img_masks[0]) pS.add_roi(image_mask=img_masks[1]) self.assertTrue(np.allclose(pS['image_mask'][0], img_masks[0])) self.assertTrue(np.allclose(pS['image_mask'][1], img_masks[1]))
def test_init_3d_pixel_mask(self): pix_masks = np.random.randn(2, 20, 30, 4) iSS, ip = self.getBoilerPlateObjects() pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(pixel_mask=pix_masks[0].tolist()) pS.add_roi(pixel_mask=pix_masks[1].tolist()) self.assertTrue(np.allclose(pS['pixel_mask'][0], pix_masks[0])) self.assertTrue(np.allclose(pS['pixel_mask'][1], pix_masks[1]))
def test_show_plane_segmentation_3d_voxel(self): ps3v = PlaneSegmentation( "output from segmenting my favorite imaging plane", self.imaging_plane, "3d_voxel", self.image_series, ) voxel_mask = [(i, i, i, 1.0) for i in range(3)] ps3v.add_roi(voxel_mask=voxel_mask) voxel_mask = [(1, 1, i, 1.2) for i in range(3)] ps3v.add_roi(voxel_mask=voxel_mask) wid = show_plane_segmentation_3d_voxel(ps3v) assert isinstance(wid, widgets.Widget)
def setBoilerPlateObjects(self): ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.device = Device(name='dev1') self.optical_channel = OpticalChannel('test_optical_channel', '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, 1, 2, 3), 4.0, 'manifold unit', 'A frame to refer to') return PlaneSegmentation('description', self.imaging_plane, 'test_plane_seg_name', self.image_series)
def test_init_image_mask(self): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] iSS, ip = self.getBoilerPlateObjects() pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(image_mask=img_mask[0]) pS.add_roi(image_mask=img_mask[1]) self.assertEqual(pS.description, 'description') self.assertEqual(pS.imaging_plane, ip) self.assertEqual(pS.reference_images, (iSS,)) self.assertEqual(pS['image_mask'].data, img_mask)
def test_init_voxel_mask(self): vox_mask = [[1, 2, 3, 1.0], [3, 4, 1, 1.0], [5, 6, 3, 1.0], [7, 8, 3, 2.0], [9, 10, 2, 2.0]] iSS, ip = self.getBoilerPlateObjects() pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(voxel_mask=vox_mask[0:3]) pS.add_roi(voxel_mask=vox_mask[3:5]) self.assertEqual(pS.description, 'description') self.assertEqual(pS.imaging_plane, ip) self.assertEqual(pS.reference_images, (iSS, )) self.assertEqual(pS['voxel_mask'].target.data, vox_mask) self.assertEqual(pS['voxel_mask'][0], vox_mask[0:3]) self.assertEqual(pS['voxel_mask'][1], vox_mask[3:5])
def buildPlaneSegmentation(self): """ Return an PlaneSegmentation and set related objects """ w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [(1, 2, 1.0), (3, 4, 1.0), (5, 6, 1.0), (7, 8, 2.0), (9, 10, 2.)] ts = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9] self.image_series = ImageSeries(name='test_iS', dimension=[2], external_file=['images.tiff'], starting_frame=[1, 2, 3], format='tiff', timestamps=ts) self.device = Device(name='dev1') self.optical_channel = OpticalChannel('test_optical_channel', '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', reference_frame='unknown') self.img_mask = deepcopy(img_mask) self.pix_mask = deepcopy(pix_mask) self.pxmsk_index = [3, 5] pS = PlaneSegmentation('plane segmentation description', self.imaging_plane, 'test_plane_seg_name', self.image_series) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) return pS
def test_show_plane_segmentation_3d_mask(self): ps3 = PlaneSegmentation( "output from segmenting my favorite imaging plane", self.imaging_plane, "3d_plane_seg", self.image_series, ) w, h, d = 3, 3, 3 img_mask1 = np.zeros((w, h, d)) for i in range(3): img_mask1[i, i, i] = 1.0 ps3.add_roi(image_mask=img_mask1) img_mask2 = np.zeros((w, h, d)) for i in range(3): img_mask2[i, i, i] = 1.2 ps3.add_roi(image_mask=img_mask2) wid = show_plane_segmentation_3d_mask(ps3) assert isinstance(wid, widgets.Widget)
def test_init(self): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS, ip = self.getBoilerPlateObjects() pS = PlaneSegmentation('description', ip, 'test_name', iSS) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) self.assertEqual(pS.description, 'description') self.assertEqual(pS.imaging_plane, ip) self.assertEqual(pS.reference_images, (iSS,)) self.assertEqual(pS['pixel_mask'].target.data, pix_mask) self.assertEqual(pS['pixel_mask'][0], pix_mask[0:3]) self.assertEqual(pS['pixel_mask'][1], pix_mask[3:5]) self.assertEqual(pS['image_mask'].data, img_mask)
def create_plane_segmentation(): w, h = 5, 5 img_mask = [[[1.0 for x in range(w)] for y in range(h)], [[2.0 for x in range(w)] for y in range(h)]] pix_mask = [[1, 2, 1.0], [3, 4, 1.0], [5, 6, 1.0], [7, 8, 2.0], [9, 10, 2.0]] iSS = ImageSeries(name='test_iS', data=np.ones((2, 2, 2)), unit='unit', external_file=['external_file'], starting_frame=[1, 2, 3], format='tiff', timestamps=[1., 2.]) ip = create_imaging_plane() pS = PlaneSegmentation(description='description', imaging_plane=ip, name='test_name', reference_images=iSS) pS.add_roi(pixel_mask=pix_mask[0:3], image_mask=img_mask[0]) pS.add_roi(pixel_mask=pix_mask[3:5], image_mask=img_mask[1]) return pS
def create_basic_plane_segmentation(self): """Creates a basic plane segmentation used for testing""" iSS, ip = self.getBoilerPlateObjects() return PlaneSegmentation('description', ip, 'test_name', iSS)