From beca1f7d26043d3e1e11275ca00de15e7815f38e Mon Sep 17 00:00:00 2001 From: Frithjof Gressmann Date: Thu, 22 Feb 2024 00:06:41 -0600 Subject: [PATCH] Add Config.from_json method --- src/miv_simulator/config.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/miv_simulator/config.py b/src/miv_simulator/config.py index 430c10b..2ed7227 100644 --- a/src/miv_simulator/config.py +++ b/src/miv_simulator/config.py @@ -318,12 +318,23 @@ def __init__(self, data: Dict) -> None: # compatibility self.get("Cell Types.STIM", {}).setdefault("synapses", {}) + @property + def data(self) -> Dict: + return self._data + @classmethod def from_yaml(cls, filepath: str) -> "Config": from miv_simulator.utils import from_yaml return cls(from_yaml(filepath)) + @classmethod + def from_json(cls, filepath: str) -> "Config": + import json + + with open(filepath, "r") as f: + return cls(json.load(f)) + def get(self, path: str, default=sentinel, splitter: str = "."): d = self._data for key in path.split(splitter):