Skip to content

Commit

Permalink
Merge pull request #120 from BlueBrain/morph-modifier-hoc2
Browse files Browse the repository at this point in the history
Refactor morph_modifier
  • Loading branch information
darshanmandge authored Mar 19, 2024
2 parents ce11578 + 7b7af2e commit 74a6c70
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bluepyemodel/access_point/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def get_model_configuration(self, skip_get_available_morph=False):
configuration.init_from_dict(parameters, self.get_morphologies())

configuration.mapping_multilocation = self.get_recipes().get("multiloc_map", None)

configuration.morph_modifiers = self.get_recipes().get("morph_modifiers", None)
return configuration

def store_targets_configuration(self, configuration):
Expand Down
37 changes: 34 additions & 3 deletions bluepyemodel/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,43 @@ def define_morphology(
morph_modifiers_hoc = None
do_replace_axon = True
else:
morph_modifiers_hoc = [None] * len(morph_modifiers)
for i, morph_modifier in enumerate(morph_modifiers):
if isinstance(morph_modifier, list):
modifier_module = importlib.import_module(morph_modifier[0])
morph_modifiers[i] = getattr(modifier_module, morph_modifier[1])
try:
modifier_module = importlib.import_module(morph_modifier[0])
morph_modifiers[i] = getattr(modifier_module, morph_modifier[1])
if len(morph_modifier) > 2:
morph_modifiers_hoc[i] = getattr(modifier_module, morph_modifier[2])
else:
morph_modifiers_hoc[i] = getattr(modifiers, morph_modifier[1] + "_hoc")
except AttributeError:
logger.warning(
"Cannot import %s or %s from %s. Please inform the hoc string in "
"morph_modifiers if you want to export the emodel to hoc.",
morph_modifier[1],
morph_modifier[1] + "_hoc",
morph_modifier[0],
)
except IndexError as exc:
raise ValueError(
"a morph_modifier should be a list of the form "
"['path_to_module', 'name_of_function', "
f"'optional_hoc_string'], got {morph_modifier}"
) from exc

elif isinstance(morph_modifier, str):
morph_modifiers[i] = getattr(modifiers, morph_modifier)
try:
morph_modifiers[i] = getattr(modifiers, morph_modifier)
morph_modifiers_hoc[i] = getattr(modifiers, morph_modifier + "_hoc")
except AttributeError:
logger.warning(
"Cannot import %s or %s from bluepyemodel.evaluation.modifiers."
"Please inform the hoc string in morph_modifiers if you want "
"to export the emodel to hoc.",
morph_modifier,
morph_modifier + "_hoc",
)
elif not callable(morph_modifier):
raise TypeError(
"A morph modifier is not callable nor a string nor a list of two str"
Expand Down
6 changes: 3 additions & 3 deletions bluepyemodel/model/neuron_model_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def __init__(
the ``./morphology`` directory for the local access point or on Nexus for the
Nexus access point.
morph_modifiers (list): List of morphology modifiers. Each modifier has to be
informed by the path the file containing the modifier and the name of the
function. E.g:
informed by the path the file containing the modifier, the name of the
function and the hoc string. E.g:
.. code-block::
morph_modifiers = [["path_to_module", "name_of_function"], ...].
morph_modifiers = [["path_to_module", "name_of_function", "hoc_string"],]
extra_mech_ids (list of 2-d tuples): extra nexus ids and types to add to
related nexus ids. Must have shape:
Expand Down

0 comments on commit 74a6c70

Please sign in to comment.