示例#1
0
    def test_read_puncta(self):
        xml_file = _resource_path("puncta.xml")
        contents = read_xml(xml_file)
        self.assertEqual(4, contents.markers_count())
        marker = contents.get_marker(0)
        self.assertEqual(3, len(marker['properties']))

        channel = marker['properties'][0]
        self.assertEqual(2, channel.version())
        punctum = marker['properties'][1]
        self.assertEqual(4, punctum.version())
        volume_rle = marker['properties'][2]
        scale = volume_rle.scaling()
        self.assertEqual(1.38378, scale[0])
        self.assertEqual(1.38378, scale[1])
        self.assertEqual(1, scale[2])
        self.assertEqual(7175, volume_rle.foreground_voxels_total())
        counts = volume_rle.voxel_counts()
        self.assertEqual(28, counts[0])
        self.assertEqual(26, counts[1])
        self.assertEqual(33, counts[2])
        origin = volume_rle.origin()
        self.assertEqual(732.02, origin[0])
        self.assertEqual(-451.112, origin[1])
        self.assertEqual(-134, origin[2])

        voxel_run = volume_rle.voxel_run()
        self.assertEqual(1410, len(voxel_run))
        self.assertEqual(122, voxel_run[0])
        self.assertEqual(2, voxel_run[-1])
        self.assertEqual(16287, sum(voxel_run[::2]))
        self.assertEqual(7175, sum(voxel_run[1::2]))
        # I think this should be 24024 but that is not the case currently double checking this answer.
        self.assertEqual(23462, sum(voxel_run))
示例#2
0
    def test_tree_with_markers_in_tree_structure(self):
        xml_file = _resource_path("tree_with_marker_in_tree_structure.xml")
        neurolucida_data = read_xml(xml_file)

        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(1, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())
示例#3
0
 def test_read_multi_images(self):
     xml_file = _resource_path("scale_example_2.xml")
     neurolucida_data = read_xml(xml_file)
     self.assertEqual(1, neurolucida_data.contours_count())
     contour = neurolucida_data.get_contour(0)
     raw_data = contour['data']
     pt1 = raw_data[0]
     # The scale shouldn't be applied to the data so no scaling should take place
     self.assertAlmostEqual(8794.46, pt1.coordinates()[0])
示例#4
0
    def test_write_ex_with_multi_tree_and_annotation(self):
        ex_file = _resource_path("multi_tree_with_annotations.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("multi_tree_with_annotations.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
示例#5
0
    def test_write_ex_basic(self):
        ex_file = _resource_path("basic_vessel.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tracing_vessels_and_markers.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data)
        self.assertTrue(os.path.exists(ex_file))
示例#6
0
    def test_write_ex_basic_group(self):
        ex_file = _resource_path("basic_groups.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_anatomical_terms.xml")
        data = read_xml(xml_file)

        write_ex(ex_file, data, {'external_annotation': True})
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Thorasic Sympathetic Trunk"))
示例#7
0
    def test_write_tree_with_markers(self):
        xml_file = _resource_path("tree_with_markers.xml")
        neurolucida_data = read_xml(xml_file)

        ex_file = _resource_path("tree_with_markers.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: marker"))
示例#8
0
    def test_write_puncta(self):
        ex_file = _resource_path("puncta.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("puncta.xml")
        contents = read_xml(xml_file)
        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(3370, len(lines))
示例#9
0
    def test_read_puncta_with_set_property(self):
        ex_file = _resource_path("puncta_with_set_prop.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("puncta_with_set_prop.xml")
        contents = read_xml(xml_file)
        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: inner submucosal nerve plexus"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(1055, len(lines))
示例#10
0
    def test_contour_multiple_properties(self):
        ex_file = _resource_path("contour_with_multiple_set_properties.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("contour_with_multiple_set_properties.xml")
        contents = read_xml(xml_file)
        self.assertEqual(1, len(contents))

        write_ex(ex_file, contents)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: inner submucosal nerve plexus"))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Nerve fiber connecting inner submucosal nerve plexus and outer submucosal nerve plexus"))
示例#11
0
    def test_read_tree_with_anatomical_terms(self):
        xml_file = _resource_path("tree_with_anatomical_terms.xml")
        neurolucida_data = read_xml(xml_file)
        self.assertEqual(2, neurolucida_data.trees_count())

        tree = neurolucida_data.get_tree(0)

        self.assertEqual('#00FFFF', tree.colour())
        self.assertListEqual([0, 1, 1], tree.rgb())
        self.assertEqual('Dendrite', tree.type_description())
        self.assertEqual('Generated', tree.leaf())
        self.assertEqual(1, len(tree.properties()))
        self.assertEqual('Thorasic Sympathetic Trunk', tree.properties()[0].label())
        self.assertListEqual([0.0, 1.0, 1.0], tree.rgb())
示例#12
0
    def test_tree_with_trace_association(self):
        ex_file = _resource_path("tree_with_trace_association.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_trace_association.xml")
        neurolucida_data = read_xml(xml_file)

        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(0, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: http://purl.org/sig/ont/fma/fma15005"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(180, len(lines))
示例#13
0
    def test_tree_with_set_property(self):
        ex_file = _resource_path("tree_with_set_property.ex")
        if os.path.exists(ex_file):
            os.remove(ex_file)

        xml_file = _resource_path("tree_with_set_property.xml")
        neurolucida_data = read_xml(xml_file)

        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(0, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())

        write_ex(ex_file, neurolucida_data)
        self.assertTrue(os.path.exists(ex_file))

        self.assertTrue(_is_line_in_file(ex_file, " Group name: Bob"))
        self.assertTrue(_is_line_in_file(ex_file, " Group name: Dave"))
        with open(ex_file) as f:
            lines = f.readlines()
            self.assertEqual(552, len(lines))
示例#14
0
    def test_read_tree_with_markers(self):
        xml_file = _resource_path("tree_with_markers.xml")
        neurolucida_data = read_xml(xml_file)
        self.assertEqual(0, neurolucida_data.contours_count())
        self.assertEqual(2, neurolucida_data.markers_count())
        self.assertEqual(1, neurolucida_data.trees_count())

        tree = neurolucida_data.get_tree(0)
        marker = neurolucida_data.get_marker(1)

        self.assertListEqual([1.0, 0.0, 1.0], tree.rgb())

        self.assertTrue('colour' in marker)
        self.assertTrue('rgb' in marker)
        self.assertTrue('name' in marker)
        self.assertTrue('type' in marker)
        self.assertTrue('varicosity' in marker)
        self.assertTrue('data' in marker)

        self.assertEqual('Dot', marker['type'])
示例#15
0
 def test_read_vessel_xml(self):
     xml_file = _resource_path("tracing_vessels_and_markers.xml")
     contents = read_xml(xml_file)
     self.assertEqual(7, len(contents))
示例#16
0
 def test_read_multi_tree_xml(self):
     xml_file = _resource_path("multi_tree.xml")
     contents = read_xml(xml_file)
     self.assertEqual(3, len(contents))
示例#17
0
 def test_read_basic_contour_xml(self):
     xml_file = _resource_path("basic_heart_contours.xml")
     contents = read_xml(xml_file)
     self.assertEqual(1, len(contents))