Skip to content

Commit

Permalink
Refactored sub-functions out of create_study_local for readability …
Browse files Browse the repository at this point in the history
…and a small refactor of the generation of correlation defaults.
  • Loading branch information
Sigurd-Borge committed Oct 4, 2024
1 parent b6f6332 commit d09d1eb
Showing 1 changed file with 36 additions and 46 deletions.
82 changes: 36 additions & 46 deletions src/antares/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ def create_study_api(
return Study(study_name, version, ServiceFactory(api_config, study_id), study_settings)


def _verify_study_already_exists(study_directory: Path) -> None:
if os.path.exists(study_directory):
raise FileExistsError(f"Study {study_directory} already exists.")


def create_study_local(
study_name: str, version: str, local_config: LocalConfiguration, settings: Optional[StudySettings] = None
) -> "Study":
Expand All @@ -95,47 +90,6 @@ def create_study_local(
FileExistsError if the study already exists in the given location
"""

def _create_directory_structure(study_path: Path) -> None:
subdirectories = [
"input/hydro/allocation",
"input/hydro/common/capacity",
"input/hydro/series",
"input/links",
"input/load/series",
"input/misc-gen",
"input/reserves",
"input/solar/series",
"input/thermal/clusters",
"input/thermal/prepro",
"input/thermal/series",
"input/wind/series",
"layers",
"output",
"settings/resources",
"settings/simulations",
"user",
]
for subdirectory in subdirectories:
(study_path / subdirectory).mkdir(parents=True, exist_ok=True)

def _correlation_defaults() -> dict[str, dict[str, str]]:
return {
"general": {"mode": "annual"},
"annual": {},
"0": {},
"1": {},
"2": {},
"3": {},
"4": {},
"5": {},
"6": {},
"7": {},
"8": {},
"9": {},
"10": {},
"11": {},
}

study_directory = local_config.local_path / study_name

_verify_study_already_exists(study_directory)
Expand Down Expand Up @@ -288,3 +242,39 @@ def delete_binding_constraint(self, constraint: BindingConstraint) -> None:

def delete(self, children: bool = False) -> None:
self._study_service.delete(children)


def _verify_study_already_exists(study_directory: Path) -> None:
if os.path.exists(study_directory):
raise FileExistsError(f"Study {study_directory} already exists.")


def _create_directory_structure(study_path: Path) -> None:
subdirectories = [
"input/hydro/allocation",
"input/hydro/common/capacity",
"input/hydro/series",
"input/links",
"input/load/series",
"input/misc-gen",
"input/reserves",
"input/solar/series",
"input/thermal/clusters",
"input/thermal/prepro",
"input/thermal/series",
"input/wind/series",
"layers",
"output",
"settings/resources",
"settings/simulations",
"user",
]
for subdirectory in subdirectories:
(study_path / subdirectory).mkdir(parents=True, exist_ok=True)


def _correlation_defaults() -> dict[str, dict[str, str]]:
return {
"general": {"mode": "annual"},
"annual": {},
} | {f"{num}": {} for num in range(12)}

0 comments on commit d09d1eb

Please sign in to comment.