Skip to content

Commit

Permalink
Add diametrizer in vacuum synthesis
Browse files Browse the repository at this point in the history
Change-Id: I3ee112796dd081e5ab31eb79cd09f5f5cd276433
  • Loading branch information
adrien-berchet committed Oct 23, 2020
1 parent fcda863 commit 123c36a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/luigi_cfg/luigi_vacuum.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# luigi parameters
[core]
logging_conf_file = logging.conf
# [core]
# logging_conf_file = logging.conf

# global parameters
[SynthesisConfig]
Expand Down
4 changes: 4 additions & 0 deletions synthesis_workflow/tasks/vacuum_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class VacuumSynthesize(WorkflowTask):

vacuum_synth_morphology_path = luigi.Parameter(default="vacuum_synth_morphologies")
vacuum_synth_morphs_df_path = luigi.Parameter(default="vacuum_synth_morphs_df.csv")
diametrizer = luigi.ChoiceParameter(
default="external", choices=["external"] + [f"M{i}" for i in range(1, 6)]
)
n_cells = luigi.IntParameter(default=10)

def requires(self):
Expand Down Expand Up @@ -66,6 +69,7 @@ def run(self):
tmd_parameters,
tmd_distributions,
morphology_base_path,
diametrizer=self.diametrizer,
joblib_verbose=self.joblib_verbose,
nb_jobs=self.nb_jobs,
)
Expand Down
38 changes: 32 additions & 6 deletions synthesis_workflow/vacuum_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
from neurom import load_neuron
from neurom import viewer
from tns import NeuronGrower
from diameter_synthesis import build_diameters

from . import STR_TO_TYPES
from .synthesis import get_max_len
from .utils import DisableLogger


def _grow_morphology(
gid, mtype, tmd_parameters, tmd_distributions, morphology_base_path
gid,
mtype,
tmd_parameters,
tmd_distributions,
morphology_base_path,
external_diametrizer=None,
):
"""Grow single morphology for parallel computations."""

Expand All @@ -30,7 +36,7 @@ def _grow_morphology(
grower = NeuronGrower(
input_parameters=tmd_parameters,
input_distributions=tmd_distributions,
external_diametrizer=None,
external_diametrizer=external_diametrizer,
)
grower.grow()
grower.neuron.write(morphology_path)
Expand All @@ -49,17 +55,36 @@ def grow_vacuum_morphologies(
tmd_parameters,
tmd_distributions,
morphology_base_path,
diametrizer="external",
joblib_verbose=0,
nb_jobs=1,
):
"""Grow morphologies in vacuum."""
"""Grow morphologies in vacuum.
With diametrizer='external', we will use diameter-synthesis,
otherwise 'M1-M5' from TNS are allowed.
"""

global_gid = 0
vacuum_synth_morphs_df = pd.DataFrame()
for mtype in tqdm(mtypes):
# no need to realistic diameters here, using internal TNS diametrizer
tmd_parameters[mtype]["diameter_params"]["method"] = "M1"
tmd_distributions["mtypes"][mtype]["diameter"]["method"] = "M1"
tmd_parameters[mtype]["diameter_params"]["method"] = diametrizer
tmd_distributions["mtypes"][mtype]["diameter"]["method"] = diametrizer

if diametrizer == "external":

def external_diametrizer(neuron, model, neurite_type):
return build_diameters.build(
neuron,
model,
[neurite_type],
tmd_parameters[mtype][ # pylint: disable=cell-var-from-loop
"diameter_params"
],
)

else:
external_diametrizer = None

gids = range(global_gid, global_gid + n_cells)
global_gid += n_cells
Expand All @@ -70,6 +95,7 @@ def grow_vacuum_morphologies(
tmd_parameters[mtype],
tmd_distributions["mtypes"][mtype],
morphology_base_path,
external_diametrizer=external_diametrizer,
)
for gid in gids
):
Expand Down

0 comments on commit 123c36a

Please sign in to comment.