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

3d trunk angles #49

Merged
merged 85 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
54b8d98
Feat: New trunk angle implementation (squashed)
arnaudon Oct 6, 2021
121c015
Test: Fix function comparison
arnaudon May 3, 2022
b158d1b
Update neurots/generate/soma.py
arnaudon May 12, 2022
15c8560
Update neurots/extract_input/from_neurom.py
arnaudon May 12, 2022
2dfd926
Update neurots/extract_input/from_neurom.py
arnaudon May 12, 2022
bc469f3
Update neurots/extract_input/from_neurom.py
arnaudon May 12, 2022
bec41a6
Update neurots/extract_input/input_parameters.py
arnaudon May 12, 2022
6c10d37
Update neurots/extract_input/input_parameters.py
arnaudon May 12, 2022
69aa946
Update neurots/generate/orientations.py
arnaudon May 12, 2022
4152c5b
Better raise
arnaudon May 12, 2022
0c969ec
Small fix
arnaudon May 13, 2022
113f99f
small fix
arnaudon Sep 12, 2022
53c285d
improved version
arnaudon Sep 12, 2022
15ede59
more
arnaudon Sep 13, 2022
634ed09
put back legacy
arnaudon Sep 14, 2022
4aeaf14
improve KeyError message
arnaudon Sep 14, 2022
4a2ab22
fix more comm
arnaudon Sep 14, 2022
e8feceb
put back use_predefined
arnaudon Sep 14, 2022
9b27d0c
clean extract
arnaudon Sep 14, 2022
205ba4c
clean grow trunk
arnaudon Sep 14, 2022
d129521
more cleanup
arnaudon Sep 14, 2022
dbc7509
more
arnaudon Sep 14, 2022
c49b327
more
arnaudon Sep 14, 2022
04f62c0
more clenaup
arnaudon Sep 14, 2022
3d2d6bf
small fix
arnaudon Sep 14, 2022
b810cfb
fix doc + show private docstrings
arnaudon Sep 14, 2022
d926b05
Adrien's updates
arnaudon Sep 14, 2022
f1e93aa
typo
arnaudon Sep 14, 2022
e5f3ac8
elef comments
arnaudon Sep 19, 2022
586d36c
remove trunk_vectors
arnaudon Sep 22, 2022
aa7dfb3
copy parameters
arnaudon Sep 23, 2022
5abf9af
fix
arnaudon Sep 23, 2022
d31a921
format
arnaudon Sep 23, 2022
ef5e20a
fix tests
arnaudon Sep 23, 2022
44ec39e
simplify fit_3d
arnaudon Sep 23, 2022
a1701ae
allow external pia_direction
arnaudon Sep 23, 2022
fd43c93
default in distr
arnaudon Sep 26, 2022
0f3ccb8
fix tests
arnaudon Sep 26, 2022
f10caf3
improve cov
arnaudon Sep 26, 2022
259e1cd
missing test files
arnaudon Sep 26, 2022
2a8140c
format
arnaudon Sep 26, 2022
c4c52fd
add cov
arnaudon Sep 26, 2022
fd5534f
ci
arnaudon Sep 26, 2022
3b7d528
lint
arnaudon Sep 26, 2022
1a35fd4
relax test assert
arnaudon Sep 26, 2022
e3a09cd
use preprocessing
arnaudon Feb 8, 2023
794f706
adrien comments
arnaudon Feb 9, 2023
95ec5f9
simplify extract_params
arnaudon Feb 10, 2023
2df3622
Update neurots/preprocess/validity_checkers.py
arnaudon Feb 10, 2023
4d431aa
Update neurots/generate/orientations.py
arnaudon Feb 10, 2023
215f7e5
Update neurots/generate/orientations.py
arnaudon Feb 10, 2023
d9ef13c
Update neurots/schemas/parameters.json
arnaudon Feb 10, 2023
9777bda
Apply suggestions from code review
arnaudon Feb 10, 2023
eda2860
adrien comments
arnaudon Feb 10, 2023
e5fa8b9
remove sort_neurite
arnaudon Feb 13, 2023
1987286
fix CI
arnaudon Feb 13, 2023
40feeba
bump numpy
arnaudon Feb 13, 2023
26a1a82
bump numpy
arnaudon Feb 13, 2023
8c87ecc
fix CI
arnaudon Feb 13, 2023
8e97847
slight cov reduction
arnaudon Feb 13, 2023
4063930
fix pre-commit
arnaudon Feb 13, 2023
437836e
fix pre-commit
arnaudon Feb 13, 2023
d00105e
assert fix
arnaudon Feb 13, 2023
29f66ae
fix
arnaudon Feb 13, 2023
97829b6
fix assert
arnaudon Feb 13, 2023
150b718
increase cov
arnaudon Feb 13, 2023
19f87ec
fix hook
arnaudon Feb 13, 2023
0fa6f3f
daaaah
arnaudon Feb 13, 2023
48b4645
format
arnaudon Feb 13, 2023
7669c4e
Merge branch 'main' into trunk_angles_rebase
adrien-berchet Feb 16, 2023
486060f
fix check_3d
arnaudon Feb 16, 2023
ad8e4fc
fixt
arnaudon Feb 16, 2023
9ed97ed
improve cov
arnaudon Feb 16, 2023
e773c58
improve cov
arnaudon Feb 16, 2023
7b02853
Update neurots/schemas/parameters.json
arnaudon Mar 3, 2023
ceb1092
fix schema
arnaudon Mar 3, 2023
047c51b
Fix description and indent in schema
adrien-berchet Mar 3, 2023
5cff823
use mean/std instead of tuple
arnaudon Mar 3, 2023
e2b96c4
merge
arnaudon Mar 3, 2023
891d126
fix test file
arnaudon Mar 3, 2023
7f72220
fix
arnaudon Mar 3, 2023
cbd9178
bump numpy
arnaudon Mar 3, 2023
b6aedaf
lint
arnaudon Mar 3, 2023
8deae28
improve schema
arnaudon Mar 3, 2023
c18688a
fix docstring
arnaudon Mar 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ disable=
fixme,
invalid-name,
len-as-condition,
no-else-return
no-else-return,
broad-exception-raised

[FORMAT]
# Regexp for a line that is allowed to be longer than the limit.
Expand Down
7 changes: 2 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@

# autodoc settings
autodoc_typehints = "signature"
autodoc_default_options = {
"members": True,
"show-inheritance": True,
}

autodoc_default_options = {"members": True, "show-inheritance": True, "private-members": True}
arnaudon marked this conversation as resolved.
Show resolved Hide resolved
default_role = "py:obj"
intersphinx_mapping = {
"morphio": ("https://morphio.readthedocs.io/en/latest/", None),
"neurom": ("https://neurom.readthedocs.io/en/stable/", None),
Expand Down
4 changes: 2 additions & 2 deletions neurots/astrocyte/grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ def __init__(
input_parameters,
input_distributions,
context,
skip_preprocessing=True,
external_diametrizer=None,
skip_validation=False,
arnaudon marked this conversation as resolved.
Show resolved Hide resolved
rng_or_seed=np.random,
):
super().__init__(
input_parameters,
input_distributions,
context=SpaceColonizationContext(context),
external_diametrizer=external_diametrizer,
skip_validation=skip_validation,
skip_preprocessing=skip_preprocessing,
rng_or_seed=rng_or_seed,
)

Expand Down
1 change: 0 additions & 1 deletion neurots/astrocyte/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _initialize_algorithm(self):
params=self.params,
start_point=self.point,
context=self.context,
skip_validation=self.skip_validation,
random_generator=self._rng,
)

Expand Down
91 changes: 89 additions & 2 deletions neurots/extract_input/from_neurom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import neurom as nm
import numpy as np
from neurom import stats
from neurom.features.morphology import trunk_vectors

from neurots.utils import PIA_DIRECTION


def transform_distr(opt_distr):
Expand Down Expand Up @@ -99,7 +102,67 @@ def soma_data(pop):
return {"size": transform_distr(ss)}


def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
def trunk_neurite_3d_angles(pop, neurite_type, bins):
"""Extract 3d trunk angle data.

We extract non-projected, or 3d angles between the pia/apical and any neurite trunk.

If no apical dendrite is present, the entry `apical_3d_angles` will be absent.

Args:
pop (neurom.core.population.Population): The given population.
neurite_type (neurom.core.types.NeuriteType): Consider only the neurites of this type.
bins (int or list[int] or str, optional): The bins to use (this parameter is passed to
:func:`numpy.histogram`).

Returns:
dict: A dictionary with the following structure:

.. code-block:: bash

{
"trunk": {
"pia_3d_angles": {
"data": {
"bins": <bin values>,
"weights": <weights>
}
},
"apical_3d_angles": {
"data": {
"bins": <bin values>,
"weights": <weights>
}
}
}
}
"""
pia_3d_angles = []
apical_3d_angles = []
for morph in pop.morphologies:
vecs = trunk_vectors(morph, neurite_type=neurite_type)
pia_3d_angles += [nm.morphmath.angle_between_vectors(PIA_DIRECTION, vec) for vec in vecs]
if neurite_type.name != "apical_dendrite":
apical_ref_vec = trunk_vectors(morph, neurite_type=nm.APICAL_DENDRITE)
if len(apical_ref_vec) > 0:
apical_3d_angles += [
nm.morphmath.angle_between_vectors(apical_ref_vec[0], vec) for vec in vecs
]

def _get_hist(data):
eleftherioszisis marked this conversation as resolved.
Show resolved Hide resolved
"""Return density histogram with bin centers."""
densities, _bins = np.histogram(data, bins=bins, density=True)
return densities, 0.5 * (_bins[1:] + _bins[:-1])

weights, _bins = _get_hist(pia_3d_angles)
data = {"pia_3d_angles": {"data": {"bins": _bins.tolist(), "weights": weights.tolist()}}}
if len(apical_3d_angles) > 0:
weights, _bins = _get_hist(apical_3d_angles)
data["apical_3d_angles"] = {"data": {"bins": _bins.tolist(), "weights": weights.tolist()}}
return {"trunk": data}
arnaudon marked this conversation as resolved.
Show resolved Hide resolved


def trunk_neurite_simple(pop, neurite_type, bins):
"""Extract the trunk data for a specific tree type.

Args:
Expand All @@ -122,7 +185,7 @@ def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
}
},
"azimuth": {
"inuform": {
"uniform": {
"min": <min value>,
"max": <max value>
}
Expand Down Expand Up @@ -168,6 +231,30 @@ def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
}


def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
"""Extract the trunk data for a specific tree type.

See docstring of :func:`trunk_neurite_simple` and :func:`trunk_neurite_3d_angles`
for more details on the extracted angles.

Args:
pop (neurom.core.population.Population): The given population.
neurite_type (neurom.core.types.NeuriteType): Consider only the neurites of this type.
bins (int or list[int] or str, optional): The bins to use (this parameter is passed to
:func:`numpy.histogram`).
method (str): Method to use, either `simple` or `3d_angles`.

Returns:
dict: A dictionary with the trunk data.
"""
trunk_data = trunk_neurite_simple(pop, neurite_type=neurite_type, bins=bins)
# adds 3d_angle related distributions
trunk_data["trunk"].update(
trunk_neurite_3d_angles(pop, neurite_type=neurite_type, bins=bins)["trunk"]
)
return trunk_data


def number_neurites(pop, neurite_type=nm.BASAL_DENDRITE):
"""Extract the number of trees for a specific tree type from a given population.

Expand Down
4 changes: 2 additions & 2 deletions neurots/extract_input/input_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def distributions(
else:
type_feature = feature.get(neurite_type, "path_distances")
nm_type = getattr(NeuriteType, neurite_type)

input_distributions[neurite_type] = _append_dicts(
trunk_neurite(pop_nm, nm_type),
number_neurites(pop_nm, nm_type),
trunk_neurite(pop_nm, nm_type), number_neurites(pop_nm, nm_type)
)
if type_feature in ["path_distances", "radial_distances"]:
_append_dicts(
Expand Down
2 changes: 1 addition & 1 deletion neurots/extract_input/input_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parameters(
neurite_types=None,
feature="path_distances",
diameter_parameters=None,
):
): # pylint: disable=too-many-branches
"""Returns a default set of input parameters to be used as input for synthesis.

Args:
Expand Down
6 changes: 0 additions & 6 deletions neurots/generate/algorithms/tmdgrower.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from neurots.generate.algorithms.common import section_data
from neurots.morphmath import sample
from neurots.morphmath.utils import norm
from neurots.preprocess.relevance_checkers import check_min_bar_length

L = logging.getLogger(__name__)

Expand All @@ -40,7 +39,6 @@ class TMDAlgo(AbstractAlgo):
params (dict): The parameters required for growth. It should include the
``branching_method`` selected from: ``|bio_oriented, symmetric, directional]``.
start_point (list[float]): The first point of the trunk.
skip_validation (bool): If set to ``False``, the parameters and distributions and
the "min_bar_length" parameter are validated.
context (Any): An object containing contextual information.
random_generator (numpy.random.Generator): The random number generator to use.
Expand All @@ -51,7 +49,6 @@ def __init__(
input_data,
params,
start_point,
skip_validation=False,
context=None,
random_generator=np.random,
**_,
Expand All @@ -64,9 +61,6 @@ def __init__(
self.apical_section = None
self.apical_point_distance_from_soma = 0.0
self.persistence_length = self.barcode.get_persistence_length()
# Validate parameters and distributions
if not skip_validation:
check_min_bar_length(params, input_data, start_point, context)

def select_persistence(self, input_data, random_generator=np.random):
"""Select the persistence.
Expand Down
Loading