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

Feat: Add a uniform diameter model and deprecate the 'radius' parameter #85

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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:
arnaudon marked this conversation as resolved.
Show resolved Hide resolved
return

Check warning on line 368 in neurots/generate/diametrizer.py

View check run for this annotation

Codecov / codecov/patch

neurots/generate/diametrizer.py#L368

Added line #L368 was not covered by tests
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 @@


diam_methods = {
"uniform": diametrize_uniform,
"M1": diametrize_constant_per_neurite,
"M2": diametrize_constant_per_section,
"M3": diametrize_smoothing,
Expand Down
3 changes: 1 addition & 2 deletions neurots/generate/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,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),
[1] * 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}}
5 changes: 4 additions & 1 deletion tests/data/params4.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/params4_orientation_manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,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}}