Skip to content

Commit

Permalink
Make sure single point contours have nodes added to groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed Jan 31, 2025
1 parent b0eb9ec commit 072bfce
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ When developing install the required packages for running the tests with::

Then run the tests with::

nosetests
python -m unittest discover -s tests

from the repository root directory.

To see the coverage statistics for the package run::

nosetests --with-coverage --cover-package=mbfxml2ex
coverage run --source=mbfxml2ex -m unittest discover -s tests

For a nice HTML rendering of the coverage statistics run::

nosetests --with-coverage --cover-package=mbfxml2ex --cover-html
coverage html -d cover

To view the HTML coverage output::

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
]

[project.optional-dependencies]
test = ["coverage", "nose", "packaging"]
test = ["coverage", "packaging"]

[project.scripts]
mbfxml2exconverter = "mbfxml2ex.app:main"
Expand Down
6 changes: 3 additions & 3 deletions src/mbfxml2ex/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def read_xml(file_name):
relocate_marker_elements = []
for child in root:
raw_tag = get_raw_tag(child)
if raw_tag in ["tree", "contour"] and child.find('.//{http://www.mbfbioscience.com/2007/neurolucida}marker'):
if raw_tag in ["tree", "contour"] and child.find('.//{http://www.mbfbioscience.com/2007/neurolucida}marker') is not None:
relocate_marker_elements.append({"owner": child, "ns": "http://www.mbfbioscience.com/2007/neurolucida"})
elif raw_tag in ["tree", "contour"] and child.find('.//{}marker'):
elif raw_tag in ["tree", "contour"] and child.find('.//{}marker') is not None:
relocate_marker_elements.append({"owner": child, "ns": ""})

for marker_root_element in relocate_marker_elements:
marker_element = marker_root_element["owner"].find(f'.//{{{marker_root_element["ns"]}}}marker')
marker_element_parent = marker_root_element["owner"].find(f'.//{{{marker_root_element["ns"]}}}marker/..')
while marker_element:
while marker_element is not None:
marker_element_parent.remove(marker_element)
root.append(marker_element)
marker_element = marker_root_element["owner"].find(f'.//{{{marker_root_element["ns"]}}}marker')
Expand Down
2 changes: 2 additions & 0 deletions src/mbfxml2ex/zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ def load(region, data, options):
merge_fields_with_nodes(field_module, node_identifiers, field_info)
element_ids = create_elements(field_module, connectivity, field_names=['coordinates', 'radius', 'rgb'])
create_group_elements(field_module, contour['name'], element_ids)
create_group_nodes(field_module, contour['name'], node_identifiers)

text_properties = get_text_properties(contour['properties'])
for text_property in text_properties:
create_group_elements(field_module, text_property, element_ids)
create_group_nodes(field_module, text_property, node_identifiers)

marker_groups = {}
for marker in data.get_markers():
Expand Down
30 changes: 30 additions & 0 deletions tests/resources/contour_with_only_one_point.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<mbf version="4.0" xmlns="https://www.mbfbioscience.com/filespecification"
xmlns:nl="https://www.mbfbioscience.com/filespecification"
appname="Vesselucida" appversion="2022.1.1" apprrid="SCR_016788" insrrid="SCR_004314">
<contour name="orientation anterior" color="#A349A4" closed="false" shape="Contour">
<property name="GUID"><s>00002042</s></property>
<property name="FillDensity"><n>128</n></property>
<resolution>9.0</resolution>
<property name="TraceAssociation"><s>http://uri.interlex.org/base/ilx_0737829</s></property>
<property name="Set"><s>T6L</s></property>
<point x="6803.63" y="-11815.62" z="-66570.49" d="10.00"/>
</contour>
<contour name="orientation anterior" color="#A349A4" closed="false" shape="Contour">
<property name="GUID"><s>00002043</s></property>
<property name="FillDensity"><n>128</n></property>
<resolution>9.0</resolution>
<property name="TraceAssociation"><s>http://uri.interlex.org/base/ilx_0737829</s></property>
<property name="Set"><s>T6L</s></property>
<point x="5969.44" y="-16499.25" z="-68805.63" d="10.00"/>
</contour>
<contour name="orientation anterior" color="#A349A4" closed="false" shape="Contour">
<property name="GUID"><s>00002044</s></property>
<property name="FillDensity"><n>128</n></property>
<resolution>9.0</resolution>
<property name="TraceAssociation"><s>http://uri.interlex.org/base/ilx_0737829</s></property>
<property name="Set"><s>T6L</s></property>
<point x="2601.44" y="-17048.99" z="-14266.61" d="10.00"/>
<point x="2601.44" y="-17048.99" z="-14266.61" d="10.00"/>
</contour>
</mbf>
13 changes: 13 additions & 0 deletions tests/test_mbfxml2ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ def test_contour_multiple_properties(self):
self.assertTrue(_match_line_in_file(ex_file, re.compile(" ?Group name: inner submucosal nerve plexus")))
self.assertTrue(_match_line_in_file(ex_file, re.compile(" ?Group name: Nerve fiber connecting inner submucosal nerve plexus and outer submucosal nerve plexus")))

def test_contour_with_one_point(self):
ex_file = _resource_path("contour_with_only_one_point.ex")
if os.path.exists(ex_file):
os.remove(ex_file)

xml_file = _resource_path("contour_with_only_one_point.xml")
neurolucida_data = read_xml(xml_file)
self.assertEqual(3, neurolucida_data.contours_count())
for i in range(3):
contour = neurolucida_data.get_contour(i)
self.assertEqual(1 if i != 2 else 2, len(contour['data']))
write_ex(ex_file, neurolucida_data)


class NeurolucidaXmlReadTreesAndContoursWithMarkersTestCase(unittest.TestCase):

Expand Down

0 comments on commit 072bfce

Please sign in to comment.