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

Mismatching behavior between segment and section taper rates #1004

Closed
eleftherioszisis opened this issue Mar 16, 2022 · 1 comment · Fixed by #1005
Closed

Mismatching behavior between segment and section taper rates #1004

eleftherioszisis opened this issue Mar 16, 2022 · 1 comment · Fixed by #1005
Assignees
Labels

Comments

@eleftherioszisis
Copy link
Contributor

eleftherioszisis commented Mar 16, 2022

Segment taper rates calculate the absolute slope of the segment diameters:

def segment_taper_rates(neurite):
"""Diameters taper rates of the segments.
The taper rate is defined as the absolute radii differences divided by length of the section
"""
def _seg_taper_rates(sec):
"""Vectorized taper rates."""
pts = sec.points[:, COLS.XYZR]
diff = np.diff(pts, axis=0)
distance = np.linalg.norm(diff[:, COLS.XYZ], axis=1)
return np.divide(2 * np.abs(diff[:, COLS.R]), distance)
return _map_segments(_seg_taper_rates, neurite)

np.abs(diff[:, COLS.R])

whereas the section taper rates calculate the signed slope from the linear fit to the diameters:

def section_taper_rates(neurite):
"""Diameter taper rates of the sections from root to tip.
Taper rate is defined here as the linear fit along a section.
It is expected to be negative for morphologies.
"""
def _sec_taper_rate(sec):
"""Taper rate from fit along a section."""
path_distances = np.cumsum(interval_lengths(sec.points, prepend_zero=True))
return np.polynomial.polynomial.polyfit(path_distances, 2 * sec.points[:, COLS.R], 1)[1]
return _map_sections(_sec_taper_rate, neurite)

Is this to be expected? I would expect that in both cases the signed slope would be desired.

from io import StringIO

import numpy as np
from numpy import testing as npt

from neurom.features import neurite
from neurom import load_morphology

neu = load_morphology(StringIO(u"""((CellBody) (0 0 0 2))
                                    ((Dendrite)
                                     (0 0 0 2)
                                     (1 0 0 1)
                                     (2 0 0 0))"""), reader='asc')


npt.assert_almost_equal(neurite.section_taper_rates(neu.neurites[0]), [-1])
npt.assert_almost_equal(neurite.segment_taper_rates(neu.neurites[0]), [-1., -1])

The second test fails with [1, 1]

@lidakanari @arnaudon @adrien-berchet

@eleftherioszisis eleftherioszisis self-assigned this Mar 16, 2022
@arnaudon
Copy link
Contributor

arnaudon commented Mar 17, 2022

You're right, abs should not be. I think I added section taper rate for diameter synthesis a while ago, probably I didn't pay attention to the segment one, which is very noise in general

@arnaudon arnaudon reopened this Mar 17, 2022
@eleftherioszisis eleftherioszisis changed the title Missmatching behavior between segment and section taper rates Mismatching behavior between segment and section taper rates Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants