-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2ac082
commit 4264041
Showing
1 changed file
with
43 additions
and
2 deletions.
There are no files selected for viewing
45 changes: 43 additions & 2 deletions
45
antarest/study/storage/rawstudy/model/filesystem/root/output/simulation/mode/mcall/grid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,53 @@ | ||
import typing as t | ||
|
||
import pandas as pd | ||
|
||
from antarest.core.model import JSON | ||
from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig | ||
from antarest.study.storage.rawstudy.model.filesystem.context import ContextServer | ||
from antarest.study.storage.rawstudy.model.filesystem.folder_node import FolderNode | ||
from antarest.study.storage.rawstudy.model.filesystem.inode import TREE | ||
from antarest.study.storage.rawstudy.model.filesystem.raw_file_node import RawFileNode | ||
from antarest.study.storage.rawstudy.model.filesystem.lazy_node import LazyNode | ||
|
||
|
||
class OutputSimulationModeMcAllGrid(FolderNode): | ||
def build(self) -> TREE: | ||
files = [d.stem for d in self.config.path.iterdir()] | ||
children: TREE = {} | ||
for file in files: | ||
children[file] = RawFileNode(self.context, self.config.next_file(f"{file}.txt")) | ||
children[file] = OutputSynthesis(self.context, self.config.next_file(f"{file}.txt")) | ||
return children | ||
|
||
|
||
class OutputSynthesis(LazyNode[JSON, bytes, bytes]): | ||
def __init__(self, context: ContextServer, config: FileStudyTreeConfig): | ||
super().__init__(context, config) | ||
|
||
def load( | ||
self, | ||
url: t.Optional[t.List[str]] = None, | ||
depth: int = -1, | ||
expanded: bool = False, | ||
formatted: bool = True, | ||
) -> JSON: | ||
file_path = self.config.path | ||
df = pd.read_csv(file_path, sep="\t") | ||
return t.cast(JSON, df.to_dict(orient="split")) | ||
|
||
def dump(self, data: bytes, url: t.Optional[t.List[str]] = None) -> None: | ||
self.config.path.parent.mkdir(exist_ok=True, parents=True) | ||
self.config.path.write_bytes(data) | ||
|
||
def check_errors(self, data: str, url: t.Optional[t.List[str]] = None, raising: bool = False) -> t.List[str]: | ||
if not self.config.path.exists(): | ||
msg = f"{self.config.path} not exist" | ||
if raising: | ||
raise ValueError(msg) | ||
return [msg] | ||
return [] | ||
|
||
def normalize(self) -> None: | ||
pass # no external store in this node | ||
|
||
def denormalize(self) -> None: | ||
pass # no external store in this node |