BlueBrain / MorphIO

A python and C++ library for reading and writing neuronal morphologies
https://morphio.readthedocs.io
Apache License 2.0
26 stars 22 forks source link

Three-point soma cylinder radius offset check is too strict wrt precision. #492

Closed eleftherioszisis closed 4 months ago

eleftherioszisis commented 4 months ago

It seems that the check for the three-point soma cylinder is too strict with its epsilon:

from morphio import Morphology

contents = """
1 1 5789.674999999998 1322.85 2846.65 5.165118027 -1
2 1 5789.674999999998 1317.6848819729996 2846.65 5.165118027 1
3 1 5789.674999999998 1328.015118027 2846.65 5.165118027 1
"""
m = Morphology(contents, "swc")

emits:

$STRING$:0:warning
Warning: the soma does not conform the three point soma spec
The only valid neuro-morpho soma is:
1 1 x   y   z r -1
2 1 x (y-r) z r  1
3 1 x (y+r) z r  1

Got:
1 1 5789.67 1322.85 2846.65 5.16512 -1
2 1 5789.674805 1317.684937 (exp. 1317.684814) 2846.649902 5.165118 1
3 1 5789.674805 1328.015137 2846.649902 5.165118 1

Using the values from the swc:

1322.85 - 5.165118027 = 1317.6848819729998

However, the point written in SWC is 1317.6848819729996.

This was encountered by @ssssarah with the SEU morphologies. Given that they raise exceptions on warnings to ensure there are no artifacts, this currently raises although the morphology is correct.

mgeplf commented 4 months ago

Why aren't the r values the same?

mgeplf commented 4 months ago

Hmm, was reading the emits, that's weird. I will have a look.

mgeplf commented 4 months ago

Hmm, was reading the emits, that's weird. I will have a look.

The difference in r was actually a clue; switching to the double build of MorphIO and the test passes. It looks like we lose too much precision reading in those values as float32s rather than float64.

I don't really want to switch MorphIO wheels to the float64 build, because of the extra memory usage. Another option is to make the readers initially use doubles, and narrow the values when keeping the internal tree, but that would probably cause problems when round tripping. I think the best is to make it a relative tolerance - I will have to give it more thought.

mgeplf commented 4 months ago

This should be fixed with #494. I'm going to close this, please reopen if there are more cases like this.