Skip to content

Commit

Permalink
Add Config.from_json method
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed Feb 22, 2024
1 parent 1e1efcd commit beca1f7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/miv_simulator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit beca1f7

Please sign in to comment.