Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_morphology(path).sections throws error #1097

Open
eleftherioszisis opened this issue Jan 26, 2024 · 3 comments
Open

load_morphology(path).sections throws error #1097

eleftherioszisis opened this issue Jan 26, 2024 · 3 comments

Comments

@eleftherioszisis
Copy link
Collaborator

eleftherioszisis commented Jan 26, 2024

path = "tests/data/valid_set/Neuron.swc"

# this works as expected
m = load_morphology(path)
m.sections[0]

# these work as expected
load_morphology(path).points
load_morphology(path).neurites
load_morphology(path).soma.center
load_morphology(path).section(0)

# this fails
load_morphology(path).sections

Out[16]: ---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
File ~/Projects/BBP/NEUROM/venv310/lib/python3.10/site-packages/IPython/core/formatters.py:707, in PlainTextFormatter.__call__(self, obj)
    700 stream = StringIO()
    701 printer = pretty.RepresentationPrinter(stream, self.verbose,
    702     self.max_width, self.newline,
    703     max_seq_length=self.max_seq_length,
    704     singleton_pprinters=self.singleton_printers,
    705     type_pprinters=self.type_printers,
    706     deferred_pprinters=self.deferred_printers)
--> 707 printer.pretty(obj)
    708 printer.flush()
    709 return stream.getvalue()

File ~/Projects/BBP/NEUROM/venv310/lib/python3.10/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj)
    407                         return meth(obj, self, cycle)
    408                 if cls is not object \
    409                         and callable(cls.__dict__.get('__repr__')):
--> 410                     return _repr_pprint(obj, self, cycle)
    412     return _default_pprint(obj, self, cycle)
    413 finally:

File ~/Projects/BBP/NEUROM/venv310/lib/python3.10/site-packages/IPython/lib/pretty.py:778, in _repr_pprint(obj, p, cycle)
    776 """A pprint that just redirects to the normal repr function."""
    777 # Find newlines and replace them with p.break_()
--> 778 output = repr(obj)
    779 lines = output.splitlines()
    780 with p.group():

File ~/Projects/BBP/NEUROM/NeuroM/neurom/core/morphology.py:199, in Section.__repr__(self)
    197 def __repr__(self):
    198     """Text representation."""
--> 199     parent_id = None if self.parent is None else self.parent.id
    200     return (f'Section(id={self.id}, type={self.type}, n_points={len(self.points)})'
    201             f'<parent: Section(id={parent_id}), nchildren: {len(self.children)}>')

File ~/Projects/BBP/NEUROM/NeuroM/neurom/core/morphology.py:59, in Section.parent(self)
     56 @property
     57 def parent(self):
     58     """Returns the parent section if non root section else None."""
---> 59     if self.morphio_section.is_root:
     60         return None
     61     return Section(self.morphio_section.parent)

RuntimeError: Section does not belong to a morphology, impossible operation
@eleftherioszisis eleftherioszisis changed the title load_morphology(path).sections[0] throws error load_morphology(path).sections throws error Jan 26, 2024
@adrien-berchet
Copy link
Member

This happens when the morphology is garbage collected before the section. Maybe we can just catch the RuntimeError and consider that the section has no parent/child when it fails? Though it may not really be what one expects when writting load_morphology(path).sections

@eleftherioszisis
Copy link
Collaborator Author

It is indeed related to that and it is certainly an unwanted behavior. load_morphology(path).sections shouldn't fail like that. I'll check what we can do about it.

@eleftherioszisis
Copy link
Collaborator Author

eleftherioszisis commented Jun 11, 2024

With NeuroM v4 this error is not encountered anymore because by default load_morphology returns a readonly morphio Morphology which works correctly.
However, with load_morphology(path, mutable=True).sections the same error persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants