Skip to content

Commit

Permalink
Feat: Add a uniform diameter model and deprecate the 'radius' paramet…
Browse files Browse the repository at this point in the history
…er (#85)
  • Loading branch information
adrien-berchet committed Sep 21, 2023
1 parent ed9f4f0 commit c0c7720
Show file tree
Hide file tree
Showing 34 changed files with 132 additions and 47 deletions.
19 changes: 19 additions & 0 deletions neurots/generate/diametrizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ def diametrize_constant_per_neurite(neuron, neurite_type=None):
sec.diameters = mean_diam * np.ones(len(sec.diameters))


def diametrize_uniform(neuron, neurite_type=None, *, diam_params):
"""Set all diameters of a morphio-neuron to a given value.
Args:
neuron (morphio.mut.Morphology): The morphology that will be diametrized.
neurite_type (morphio.SectionType): Only the neurites of this type are diametrized.
diam_params (dict): The model parameters (should only contain a 'diameter' entry).
"""
diameter = diam_params.get(neurite_type.name, None)
if diameter is None:
return
roots = root_section_filter(neuron, neurite_type)

for root in roots:
for sec in root.iter():
sec.diameters = diameter * np.ones(len(sec.diameters))


def diametrize_smoothing(neuron, neurite_type=None):
"""Corrects the diameters of a morphio-neuron, by smoothing them within each section.
Expand All @@ -367,6 +385,7 @@ def diametrize_smoothing(neuron, neurite_type=None):


diam_methods = {
"uniform": diametrize_uniform,
"M1": diametrize_constant_per_neurite,
"M2": diametrize_constant_per_section,
"M3": diametrize_smoothing,
Expand Down
8 changes: 5 additions & 3 deletions neurots/generate/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

L = logging.getLogger("neurots")

# LAMBDA: parameter that defines the slope of exponential probability
LAMBDA = 1.0
"""Parameter that defines the slope of exponential probability."""

DEFAULT_DIAMETER = 1
"""The default diameter used to add new sections before they are diametrized later."""

growth_algorithms = {
"tmd": tmdgrower.TMDAlgo,
Expand Down Expand Up @@ -223,15 +226,14 @@ def append_section(self, section):
data = {
"parent": section.parent.id if section.parent else None,
"coord": np.vstack(section.points).tolist(),
"radius": [self.params["radius"] * 2] * len(section.points),
"type": int(SectionType(self.params["tree_type"])),
}
L.debug("appended_data=%s", json.dumps(data))

return append_fun(
PointLevel(
np.array(section.points).tolist(),
[self.params["radius"] * 2] * len(section.points),
[DEFAULT_DIAMETER] * len(section.points),
),
SectionType(self.params["tree_type"]),
)
Expand Down
17 changes: 17 additions & 0 deletions neurots/preprocess/validity_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import warnings

from neurots.preprocess.exceptions import NeuroTSValidationError
from neurots.preprocess.relevance_checkers import check_min_bar_length
from neurots.preprocess.utils import register_global_validator
Expand Down Expand Up @@ -94,3 +96,18 @@ def check_diameter_consistency(params, distrs):
"Diameters methods of parameters and distributions is inconsistent:"
+ f" {method1} != {method2}"
)


@register_global_validator()
def check_deprecated_radius(params, distrs): # pylint: disable=unused-argument
"""Check that the 'radius' parameter is not present or raise a warning."""
grow_types = params.get("grow_types", [])
for i in grow_types:
neurite_type_params = params.get(i, {})
if "radius" in neurite_type_params:
warnings.warn(
f"The 'radius' parameter (in {i}) is deprecated and will be forbidden in a future "
"version, most of the time it's not used but if you want to retrieve the same "
"results as before please use the 'uniform' diameter model.",
FutureWarning,
)
5 changes: 2 additions & 3 deletions neurots/schemas/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@
"metric",
"modify",
"orientation",
"radius",
"randomness",
"targeting",
"tree_type"
Expand Down Expand Up @@ -320,7 +319,7 @@
"properties": {
"method": {
"enum": [
"external", "default"
"external", "default", "uniform"
],
"description": "The method used to synthesize the diameters",
"type": "string"
Expand All @@ -334,7 +333,7 @@
"description": "The method used to synthesize the diameters",
"not": {
"enum": [
"external", "default"
"external", "default", "uniform"
]
},
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion tests/astrocyte/data/bio_path_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,5 @@
}
}
},
"diameter": {"method": "default"}
"diameter": {"method": "uniform"}
}
5 changes: 4 additions & 1 deletion tests/astrocyte/data/bio_path_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
"apical": {},
"origin": [0.0, 0.0, 0.0],
"grow_types": ["basal", "axon"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
10 changes: 6 additions & 4 deletions tests/astrocyte/test_grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def _parameters():
"metric": "path_distances",
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
"orientation": None,
"growth_method": "tmd_space_colonization",
"branching_method": "bio_oriented",
Expand All @@ -48,7 +47,6 @@ def _parameters():
"metric": "path_distances",
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
"target_ids": [0, 1],
"growth_method": "tmd_space_colonization_target",
"branching_method": "bio_oriented",
Expand All @@ -63,7 +61,6 @@ def _parameters():
"metric": "path_distances",
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
"orientation": [[1.0, 0.0, 0.0], [0.1, 0.1, 0.1]],
"growth_method": "tmd_space_colonization",
"branching_method": "bio_oriented",
Expand All @@ -75,7 +72,12 @@ def _parameters():
},
"origin": [0.0, 0.0, 0.0],
"grow_types": ["basal", "axon", "apical"],
"diameter_params": {"method": "default"},
"diameter_params": {
"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6,
},
}


Expand Down
2 changes: 1 addition & 1 deletion tests/data/axon_trunk_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
5 changes: 3 additions & 2 deletions tests/data/axon_trunk_parameters.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{"axon": {"randomness": 0.0,
"metric": "trunk_length",
"targeting": 0.2,
"radius": 0.3,
"num_seg": 999,
"orientation": [[0.0,
1.0,
Expand All @@ -15,4 +14,6 @@
0.0,
0.0],
"grow_types": ["axon"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"axon": 0.6
}}
4 changes: 2 additions & 2 deletions tests/data/axon_trunk_parameters_absolute.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{"axon": {"randomness": 0.0,
"metric": "trunk_length",
"targeting": 0.2,
"radius": 0.3,
"num_seg": 999,
"orientation": [[0.0,
1.0,
Expand All @@ -17,4 +16,5 @@
0.0,
0.0],
"grow_types": ["axon"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"axon": 0.6}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{"axon": {"randomness": 0.0,
"metric": "trunk_length",
"targeting": 0.2,
"radius": 0.3,
"num_seg": 999,
"orientation": {
"mode": "sample_around_primary_orientation",
Expand All @@ -19,4 +18,5 @@
0.0,
0.0],
"grow_types": ["axon"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"axon": 0.6}}
4 changes: 2 additions & 2 deletions tests/data/axon_trunk_parameters_orientation_manager.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{"axon": {"randomness": 0.0,
"metric": "trunk_length",
"targeting": 0.2,
"radius": 0.3,
"num_seg": 999,
"orientation": {
"mode": "use_predefined",
Expand All @@ -18,4 +17,5 @@
0.0,
0.0],
"grow_types": ["axon"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"axon": 0.6}}
2 changes: 1 addition & 1 deletion tests/data/bio_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
2 changes: 1 addition & 1 deletion tests/data/bio_distribution_3d_angles.json
Original file line number Diff line number Diff line change
Expand Up @@ -34940,7 +34940,7 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
},
"soma": {
"size": {
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bio_distribution_apical_point.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
5 changes: 4 additions & 1 deletion tests/data/bio_gradient_path_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@
0.0,
0.0],
"grow_types": ["basal_dendrite","apical_dendrite"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/bio_gradient_path_params_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@
0.0,
0.0],
"grow_types": ["basal_dendrite","apical_dendrite"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
6 changes: 4 additions & 2 deletions tests/data/bio_parameters_3d_angles.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
"targeting": 0.16,
"tree_type": 3
},
"diameter_params": {
"method": "default"
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6
},
"grow_types": [
"apical_dendrite",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/bio_path_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
5 changes: 4 additions & 1 deletion tests/data/bio_path_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
0.0,
0.0],
"grow_types": ["basal_dendrite", "apical_dendrite"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/bio_path_params_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
0.0,
0.0],
"grow_types": ["basal_dendrite", "apical_dendrite"],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
2 changes: 1 addition & 1 deletion tests/data/bio_rat_L5_TPC_B_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
2 changes: 1 addition & 1 deletion tests/data/bio_trunk_distribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@
}
},
"diameter": {
"method": "default"
"method": "uniform"
}
}
5 changes: 4 additions & 1 deletion tests/data/params1.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/params1_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/params2.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
6 changes: 5 additions & 1 deletion tests/data/params2_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {
"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/params3.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}
5 changes: 4 additions & 1 deletion tests/data/params3_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
"diameter_params": {"method": "uniform",
"basal_dendrite": 0.6,
"apical_dendrite": 0.6,
"axon": 0.6}}

0 comments on commit c0c7720

Please sign in to comment.