Skip to content

Commit

Permalink
Clearer initialization of Sonata config
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdonline committed Oct 2, 2023
1 parent f970e8c commit ed30894
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions neurodamus/io/sonata_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Module to load configuration from a libsonata config
"""
from functools import cached_property
import json
import libsonata
import logging
Expand All @@ -19,7 +18,7 @@ class SonataConfig:
'circuits',
'_circuit_networks',
'_sim_conf',
'_internal_edge_pops',
'_bc_circuits',
)

_config_entries = (
Expand All @@ -41,7 +40,6 @@ def __init__(self, config_path):
self._sim_conf = libsonata.SimulationConfig.from_file(config_path)
self._entries = {}
self._sections = {}
self._internal_edge_pops = set()

with open(config_path) as config_fh:
self._config_json: dict = json.load(config_fh)
Expand All @@ -59,7 +57,7 @@ def __init__(self, config_path):

self.circuits = libsonata.CircuitConfig.from_file(self.network)
self._circuit_networks = json.loads(self.circuits.expanded_json)["networks"]
logging.debug(self.Circuit) # compute Circuits so that it also sets _internal_edge_pops
self._bc_circuits = self._blueconfig_circuits()

@classmethod
def _resolve(cls, entry, name, manifest: dict):
Expand Down Expand Up @@ -207,8 +205,8 @@ def Conditions(self):
conditions["randomize_Gaba_risetime"] = str(conditions["randomize_Gaba_risetime"])
return {"Conditions": conditions}

@cached_property
def Circuit(self):
def _blueconfig_circuits(self):
"""yield blue-config-style circuits"""
node_info_to_circuit = {
"nodes_file": "CellLibraryFile",
"type": "PopulationType"
Expand Down Expand Up @@ -266,8 +264,9 @@ def make_circuit(nodes_file, node_pop_name, population_info):
if not os.path.isabs(edges_file):
edges_file = os.path.join(os.path.dirname(self.network), edges_file)
edge_pop_path = edges_file + ":" + edge_pop_name
self._internal_edge_pops.add(edge_pop_path)
circuit_conf["nrnPath"] = edge_pop_path
else:
circuit_conf["nrnPath"] = False

return circuit_conf

Expand All @@ -278,6 +277,9 @@ def make_circuit(nodes_file, node_pop_name, population_info):
if pop_info.get("type") != "vasculature"
}

# Compat with BlueConfig circuit definitions
Circuit = property(lambda self: self._bc_circuits)

@property
def parsedProjections(self):
projection_type_convert = dict(
Expand All @@ -286,6 +288,7 @@ def parsedProjections(self):
synapse_astrocyte="NeuroGlial",
endfoot="GlioVascular"
)
internal_edge_pops = set(c_conf["nrnPath"] for c_conf in self._bc_circuits.values())
projections = {}

for edge_config in self._circuit_networks.get("edges") or []:
Expand All @@ -303,7 +306,7 @@ def parsedProjections(self):

# skip inner connectivity populations
edge_pop_path = edges_file + ":" + edge_pop_name
if edge_pop_path in self._internal_edge_pops:
if edge_pop_path in internal_edge_pops:
continue

projection = dict(
Expand Down

0 comments on commit ed30894

Please sign in to comment.