예제 #1
0
    def test_constructor(self):
        """Test that the constructor for PoseEstimation sets values as expected."""
        pose_estimation_series = create_pose_series()
        pe = PoseEstimation(
            pose_estimation_series=pose_estimation_series,
            description='Estimated positions of front paws using DeepLabCut.',
            original_videos=['camera1.mp4', 'camera2.mp4'],
            labeled_videos=['camera1_labeled.mp4', 'camera2_labeled.mp4'],
            dimensions=[[640, 480], [1024, 768]],
            scorer='DLC_resnet50_openfieldOct30shuffle1_1600',
            source_software='DeepLabCut',
            source_software_version='2.2b8',
            nodes=['front_left_paw', 'front_right_paw'],
            edges=[[0, 1]],
            # devices=[self.nwbfile.devices['camera1'], self.nwbfile.devices['camera2']],
        )

        self.assertEqual(pe.name, 'PoseEstimation')
        self.assertEqual(len(pe.pose_estimation_series), 2)
        self.assertIs(pe.pose_estimation_series['front_left_paw'],
                      pose_estimation_series[0])
        self.assertIs(pe.pose_estimation_series['front_right_paw'],
                      pose_estimation_series[1])
        self.assertEqual(
            pe.description,
            'Estimated positions of front paws using DeepLabCut.')
        self.assertEqual(pe.original_videos, ['camera1.mp4', 'camera2.mp4'])
        self.assertEqual(pe.labeled_videos,
                         ['camera1_labeled.mp4', 'camera2_labeled.mp4'])
        self.assertEqual(pe.dimensions, [[640, 480], [1024, 768]])
        self.assertEqual(pe.scorer, 'DLC_resnet50_openfieldOct30shuffle1_1600')
        self.assertEqual(pe.source_software, 'DeepLabCut')
        self.assertEqual(pe.source_software_version, '2.2b8')
        self.assertEqual(pe.nodes, ['front_left_paw', 'front_right_paw'])
        self.assertEqual(pe.edges, [[0, 1]])
예제 #2
0
    def test_constructor(self):
        """Test that the constructor for PoseEstimation sets values as expected."""
        pose_estimation_series = create_pose_series()
        n_frames = pose_estimation_series[0].data.shape[0]
        pose_grouping_series = PoseGroupingSeries(
            name="Centroid",
            timestamps=pose_estimation_series[0].timestamps,
            data=np.random.rand(n_frames),
            location=np.random.rand(n_frames, 3),
        )
        animal_identity_series = AnimalIdentitySeries(
            name="Mouse1",
            timestamps=pose_estimation_series[0].timestamps,
            data=np.random.rand(n_frames),
        )

        pe = PoseEstimation(
            pose_estimation_series=pose_estimation_series,
            pose_grouping_series=[pose_grouping_series],
            animal_identity_series=[animal_identity_series],
            description='Estimated positions of front paws using DeepLabCut.',
            original_videos=['camera1.mp4', 'camera2.mp4'],
            labeled_videos=['camera1_labeled.mp4', 'camera2_labeled.mp4'],
            dimensions=[[640, 480], [1024, 768]],
            scorer='DLC_resnet50_openfieldOct30shuffle1_1600',
            source_software='DeepLabCut',
            source_software_version='2.2b8',
            nodes=['front_left_paw', 'front_right_paw'],
            edges=[[0, 1]],
            # devices=[self.nwbfile.devices['camera1'], self.nwbfile.devices['camera2']],
        )

        self.assertEqual(pe.name, 'PoseEstimation')
        self.assertEqual(len(pe.pose_estimation_series), 2)
        self.assertIs(pe.pose_estimation_series['front_left_paw'],
                      pose_estimation_series[0])
        self.assertIs(pe.pose_estimation_series['front_right_paw'],
                      pose_estimation_series[1])
        self.assertIs(pe.pose_grouping_series["Centroid"],
                      pose_grouping_series)
        self.assertIs(pe.animal_identity_series["Mouse1"],
                      animal_identity_series)
        self.assertEqual(
            pe.description,
            'Estimated positions of front paws using DeepLabCut.')
        self.assertEqual(pe.original_videos, ['camera1.mp4', 'camera2.mp4'])
        self.assertEqual(pe.labeled_videos,
                         ['camera1_labeled.mp4', 'camera2_labeled.mp4'])
        self.assertEqual(pe.dimensions, [[640, 480], [1024, 768]])
        self.assertEqual(pe.scorer, 'DLC_resnet50_openfieldOct30shuffle1_1600')
        self.assertEqual(pe.source_software, 'DeepLabCut')
        self.assertEqual(pe.source_software_version, '2.2b8')
        self.assertEqual(pe.nodes, ['front_left_paw', 'front_right_paw'])
        self.assertEqual(pe.edges, [[0, 1]])
예제 #3
0
 def setUpContainer(self):
     """ Return the test PoseEstimation to read/write """
     pose_estimation_series = create_series()
     pe = PoseEstimation(
         pose_estimation_series=pose_estimation_series,
         description='Estimated positions of front paws using DeepLabCut.',
         original_videos=['camera1.mp4', 'camera2.mp4'],
         labeled_videos=['camera1_labeled.mp4', 'camera2_labeled.mp4'],
         dimensions=[[640, 480], [1024, 768]],
         scorer='DLC_resnet50_openfieldOct30shuffle1_1600',
         source_software='DeepLabCut',
         source_software_version='2.2b8',
         nodes=['front_left_paw', 'front_right_paw'],
         edges=[[0, 1]],
         # devices=[self.nwbfile.devices['camera1'], self.nwbfile.devices['camera2']],
     )
     return pe
예제 #4
0
    def test_roundtrip(self):
        """
        Add a PoseEstimation to an NWBFile, write it, read it, and test that the read object matches the original.
        """
        pose_estimation_series = create_series()
        pe = PoseEstimation(
            pose_estimation_series=pose_estimation_series,
            description='Estimated positions of front paws using DeepLabCut.',
            original_videos=['camera1.mp4', 'camera2.mp4'],
            labeled_videos=['camera1_labeled.mp4', 'camera2_labeled.mp4'],
            dimensions=[[640, 480], [1024, 768]],
            scorer='DLC_resnet50_openfieldOct30shuffle1_1600',
            source_software='DeepLabCut',
            source_software_version='2.2b8',
            nodes=['front_left_paw', 'front_right_paw'],
            edges=[[0, 1]],
            # devices=[self.nwbfile.devices['camera1'], self.nwbfile.devices['camera2']],
        )

        behavior_pm = self.nwbfile.create_processing_module(
            name='behavior', description='processed behavioral data')
        behavior_pm.add(pe)

        with NWBHDF5IO(self.path, mode='w') as io:
            io.write(self.nwbfile)

        with NWBHDF5IO(self.path, mode='r', load_namespaces=True) as io:
            read_nwbfile = io.read()
            read_pe = read_nwbfile.processing['behavior']['PoseEstimation']
            self.assertContainerEqual(read_pe, pe)
            self.assertEqual(len(read_pe.pose_estimation_series), 2)
            self.assertContainerEqual(
                read_pe.pose_estimation_series['front_left_paw'],
                pose_estimation_series[0])
            self.assertContainerEqual(
                read_pe.pose_estimation_series['front_right_paw'],
                pose_estimation_series[1])
예제 #5
0
def test_example_usage():
    import datetime
    import numpy as np
    from pynwb import NWBFile, NWBHDF5IO
    from ndx_pose import PoseEstimationSeries, PoseEstimation

    nwbfile = NWBFile(session_description='session_description',
                      identifier='identifier',
                      session_start_time=datetime.datetime.now(
                          datetime.timezone.utc))

    camera1 = nwbfile.create_device(name='camera1',
                                    description='left camera',
                                    manufacturer='my manufacturer')
    camera2 = nwbfile.create_device(name='camera2',
                                    description='right camera',
                                    manufacturer='my manufacturer')

    data = np.random.rand(100, 3)  # num_frames x (x, y, z)
    timestamps = np.linspace(0, 10, num=100)  # a timestamp for every frame
    confidence = np.random.rand(100)  # a confidence value for every frame
    front_left_paw = PoseEstimationSeries(
        name='front_left_paw',
        description='Marker placed around fingers of front left paw.',
        data=data,
        unit='pixels',
        reference_frame='(0,0,0) corresponds to ...',
        timestamps=timestamps,
        confidence=confidence,
        confidence_definition='Softmax output of the deep neural network.',
    )

    data = np.random.rand(100, 2)  # num_frames x (x, y)
    timestamps = np.linspace(0, 10, num=100)  # a timestamp for every frame
    confidence = np.random.rand(100)  # a confidence value for every frame
    front_right_paw = PoseEstimationSeries(
        name='front_right_paw',
        description='Marker placed around fingers of front right paw.',
        data=data,
        unit='pixels',
        reference_frame='(0,0,0) corresponds to ...',
        timestamps=front_left_paw,  # link to timestamps of front_left_paw
        confidence=confidence,
        confidence_definition='Softmax output of the deep neural network.',
    )

    pose_estimation_series = [front_left_paw, front_right_paw]

    pe = PoseEstimation(
        pose_estimation_series=pose_estimation_series,
        description='Estimated positions of front paws using DeepLabCut.',
        original_videos=['camera1.mp4', 'camera2.mp4'],
        labeled_videos=['camera1_labeled.mp4', 'camera2_labeled.mp4'],
        dimensions=np.array([[640, 480], [1024, 768]], dtype='uint8'),
        scorer='DLC_resnet50_openfieldOct30shuffle1_1600',
        source_software='DeepLabCut',
        source_software_version='2.2b8',
        nodes=['front_left_paw', 'front_right_paw'],
        edges=np.array([[0, 1]], dtype='uint8'),
        # devices=[camera1, camera2],  # this is not yet supported
    )

    behavior_pm = nwbfile.create_processing_module(
        name='behavior', description='processed behavioral data')
    behavior_pm.add(pe)

    path = 'test_pose.nwb'
    with NWBHDF5IO(path, mode='w') as io:
        io.write(nwbfile)

    with NWBHDF5IO(path, mode='r', load_namespaces=True) as io:
        read_nwbfile = io.read()
        read_pe = read_nwbfile.processing['behavior']['PoseEstimation']
        print(read_pe)