-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create input_distributions.py and input_parameters.py
Change-Id: I2ade7f7d5105f03f30e5a8fc3a1b1e68449039c6
- Loading branch information
Benoît Coste
committed
May 23, 2019
1 parent
b3d560c
commit d49c8c8
Showing
3 changed files
with
120 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,4 @@ | ||
''' Module to extract morphometrics and TMD-input from a set of tree-shaped cells.''' | ||
|
||
import neurom as nm | ||
import tmd | ||
from tns.extract_input.from_TMD import persistent_homology_angles | ||
from tns.extract_input.from_neurom import soma_data, trunk_neurite, number_neurites | ||
from tns.extract_input import from_diameter | ||
|
||
|
||
def default_keys(): | ||
'''Returns the important keys for the distribution extraction''' | ||
return {'soma': {}, | ||
'basal': {}, | ||
'apical': {}, | ||
'axon': {}} | ||
|
||
|
||
def distributions(filepath, neurite_types=None, threshold_sec=2, | ||
diameter_input_morph=False, feature='radial_distances'): | ||
'''Extracts the input distributions from an input population | ||
defined by a directory of swc or h5 files | ||
threshold_sec: defines the minimum accepted number of terminations | ||
diameter_input_morph: if provided it will be used for the generation | ||
of diameter model | ||
feature: defines the TMD feature that will be used to extract the | ||
persistence barcode: radial_distances, path_distances | ||
''' | ||
# Assume all neurite_types will be extracted if neurite_types is None | ||
if neurite_types is None: | ||
neurite_types = ['basal', 'apical', 'axon'] | ||
|
||
pop_tmd = tmd.io.load_population(filepath) | ||
pop_nm = nm.load_neurons(filepath) | ||
|
||
input_distributions = default_keys() | ||
input_distributions['soma'].update(soma_data(pop_nm)) | ||
|
||
# Define the neurom neurite_types | ||
neurom_types = {'basal': nm.BASAL_DENDRITE, | ||
'apical': nm.APICAL_DENDRITE, | ||
'axon': nm.AXON} | ||
|
||
def fill_input_distributions(input_distr, neurite_type): | ||
'''Helping function to avoid code duplication''' | ||
nm_type = neurom_types[neurite_type] | ||
input_distr[neurite_type].update(trunk_neurite(pop_nm, nm_type)) | ||
input_distr[neurite_type].update(number_neurites(pop_nm, nm_type)) | ||
input_distr[neurite_type].update( | ||
persistent_homology_angles(pop_tmd, | ||
threshold=threshold_sec, | ||
neurite_type=neurite_type, | ||
feature=feature)) | ||
|
||
for ntype in neurite_types: | ||
fill_input_distributions(input_distributions, ntype) | ||
|
||
# In order to create diameter model an exemplar morphology is required | ||
# This is provided by diameter_input_morph | ||
if diameter_input_morph: | ||
neu_exemplar = nm.load_neuron(diameter_input_morph) | ||
input_distributions["diameter"] = from_diameter.model(neu_exemplar) | ||
input_distributions["diameter"]["method"] = 'M5' # By default, diametrize from_tips | ||
|
||
return input_distributions | ||
|
||
|
||
def parameters(origin=(0., 0., 0.), method='trunk', neurite_types=None): | ||
'''Returns a default set of input parameters | ||
to be used as input for synthesis. | ||
''' | ||
# Assume all neurite_types will be extracted if neurite_types is None | ||
if neurite_types is None: | ||
neurite_types = ['basal', 'apical', 'axon'] | ||
|
||
# Set up required fields | ||
input_parameters = {'basal': {}, | ||
'apical': {}, | ||
'axon': {}} | ||
|
||
input_parameters["origin"] = origin | ||
|
||
if method == 'trunk': | ||
branching = 'random' | ||
elif method == 'tmd' or method == 'tmd_path': | ||
branching = 'bio_oriented' | ||
|
||
parameters_default = {"randomness": 0.15, | ||
"targeting": 0.12, | ||
"radius": 0.3, | ||
"orientation": None, | ||
"growth_method": method, | ||
"branching_method": branching, | ||
"modify": None} | ||
|
||
if 'basal' in neurite_types: | ||
input_parameters["basal"].update(parameters_default) | ||
input_parameters["basal"].update({"tree_type": 3}) | ||
|
||
if 'apical' in neurite_types: | ||
input_parameters["apical"].update(parameters_default) | ||
input_parameters["apical"].update({"apical_distance": 0.0, | ||
"tree_type": 4, | ||
"branching_method": "directional", | ||
"orientation": [(0., 1., 0.)], }) | ||
if method == 'tmd': | ||
input_parameters["apical"]["growth_method"] = 'tmd_apical' | ||
if method == 'tmd_path': | ||
input_parameters["apical"]["growth_method"] = 'tmd_apical_path' | ||
|
||
if 'axon' in neurite_types: | ||
input_parameters["axon"].update(parameters_default) | ||
input_parameters["axon"].update({"tree_type": 2, | ||
"orientation": [(0., -1., 0.)], }) | ||
|
||
input_parameters['grow_types'] = neurite_types | ||
|
||
return input_parameters | ||
from tns.extract_input.input_distributions import distributions | ||
from tns.extract_input.input_parameters import parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Input distributions""" | ||
|
||
import neurom as nm | ||
import tmd | ||
from tns.extract_input.from_TMD import persistent_homology_angles | ||
from tns.extract_input.from_neurom import soma_data, trunk_neurite, number_neurites | ||
from tns.extract_input import from_diameter | ||
|
||
|
||
def default_keys(): | ||
'''Returns the important keys for the distribution extraction''' | ||
return {'soma': {}, | ||
'basal': {}, | ||
'apical': {}, | ||
'axon': {}} | ||
|
||
|
||
def distributions(filepath, neurite_types=None, threshold_sec=2, | ||
diameter_input_morph=False, feature='radial_distances'): | ||
'''Extracts the input distributions from an input population | ||
defined by a directory of swc or h5 files | ||
threshold_sec: defines the minimum accepted number of terminations | ||
diameter_input_morph: if provided it will be used for the generation | ||
of diameter model | ||
feature: defines the TMD feature that will be used to extract the | ||
persistence barcode: radial_distances, path_distances | ||
''' | ||
# Assume all neurite_types will be extracted if neurite_types is None | ||
if neurite_types is None: | ||
neurite_types = ['basal', 'apical', 'axon'] | ||
|
||
pop_tmd = tmd.io.load_population(filepath) | ||
pop_nm = nm.load_neurons(filepath) | ||
|
||
input_distributions = default_keys() | ||
input_distributions['soma'].update(soma_data(pop_nm)) | ||
|
||
# Define the neurom neurite_types | ||
neurom_types = {'basal': nm.BASAL_DENDRITE, | ||
'apical': nm.APICAL_DENDRITE, | ||
'axon': nm.AXON} | ||
|
||
def fill_input_distributions(input_distr, neurite_type): | ||
'''Helping function to avoid code duplication''' | ||
nm_type = neurom_types[neurite_type] | ||
input_distr[neurite_type].update(trunk_neurite(pop_nm, nm_type)) | ||
input_distr[neurite_type].update(number_neurites(pop_nm, nm_type)) | ||
input_distr[neurite_type].update( | ||
persistent_homology_angles(pop_tmd, | ||
threshold=threshold_sec, | ||
neurite_type=neurite_type, | ||
feature=feature)) | ||
|
||
for ntype in neurite_types: | ||
fill_input_distributions(input_distributions, ntype) | ||
|
||
# In order to create diameter model an exemplar morphology is required | ||
# This is provided by diameter_input_morph | ||
if diameter_input_morph: | ||
neu_exemplar = nm.load_neuron(diameter_input_morph) | ||
input_distributions["diameter"] = from_diameter.model(neu_exemplar) | ||
input_distributions["diameter"]["method"] = 'M5' # By default, diametrize from_tips | ||
|
||
return input_distributions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Input parameters functions""" | ||
|
||
|
||
def parameters(origin=(0., 0., 0.), method='trunk', neurite_types=None): | ||
'''Returns a default set of input parameters | ||
to be used as input for synthesis. | ||
''' | ||
# Assume all neurite_types will be extracted if neurite_types is None | ||
if neurite_types is None: | ||
neurite_types = ['basal', 'apical', 'axon'] | ||
|
||
# Set up required fields | ||
input_parameters = {'basal': {}, | ||
'apical': {}, | ||
'axon': {}} | ||
|
||
input_parameters["origin"] = origin | ||
|
||
if method == 'trunk': | ||
branching = 'random' | ||
elif method == 'tmd' or method == 'tmd_path': | ||
branching = 'bio_oriented' | ||
|
||
parameters_default = {"randomness": 0.15, | ||
"targeting": 0.12, | ||
"radius": 0.3, | ||
"orientation": None, | ||
"growth_method": method, | ||
"branching_method": branching, | ||
"modify": None} | ||
|
||
if 'basal' in neurite_types: | ||
input_parameters["basal"].update(parameters_default) | ||
input_parameters["basal"].update({"tree_type": 3}) | ||
|
||
if 'apical' in neurite_types: | ||
input_parameters["apical"].update(parameters_default) | ||
input_parameters["apical"].update({"apical_distance": 0.0, | ||
"tree_type": 4, | ||
"branching_method": "directional", | ||
"orientation": [(0., 1., 0.)], }) | ||
if method == 'tmd': | ||
input_parameters["apical"]["growth_method"] = 'tmd_apical' | ||
if method == 'tmd_path': | ||
input_parameters["apical"]["growth_method"] = 'tmd_apical_path' | ||
|
||
if 'axon' in neurite_types: | ||
input_parameters["axon"].update(parameters_default) | ||
input_parameters["axon"].update({"tree_type": 2, | ||
"orientation": [(0., -1., 0.)], }) | ||
|
||
input_parameters['grow_types'] = neurite_types | ||
|
||
return input_parameters |