Skip to content

Commit

Permalink
Merge pull request #245 from Deltares/feature/241-get-rid-of-analysis…
Browse files Browse the repository at this point in the history
…-config-difference-between-with-and-without-network

chore: get rid of analysis config difference between with and without network
  • Loading branch information
ArdtK authored Nov 16, 2023
2 parents a1f334b + 2b4ba58 commit c80d6aa
Show file tree
Hide file tree
Showing 44 changed files with 343 additions and 1,136 deletions.
File renamed without changes.
20 changes: 7 additions & 13 deletions ra2ce/analyses/analysis_config_data/analysis_config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from ra2ce.common.configuration.config_data_protocol import ConfigDataProtocol
from ra2ce.graph.network_config_data.network_config_data import (
NetworkConfigData,
NetworkSection,
OriginsDestinationsSection,
)

Expand Down Expand Up @@ -137,14 +137,12 @@ class AnalysisConfigData(ConfigDataProtocol):
static_path: Optional[Path] = None
project: ProjectSection = field(default_factory=lambda: ProjectSection())
analyses: list[AnalysisSectionBase] = field(default_factory=list)
files: Optional[dict[str, Path]] = field(default_factory=dict)
files: dict[str, Path] = field(default_factory=dict)
origins_destinations: Optional[OriginsDestinationsSection] = field(
default_factory=lambda: OriginsDestinationsSection()
)
network: Optional[NetworkConfigData] = field(
default_factory=lambda: NetworkConfigData()
)
hazard_names: Optional[list[str]] = field(default_factory=list)
network: NetworkSection = field(default_factory=lambda: NetworkSection())
hazard_names: list[str] = field(default_factory=list)

@property
def direct(self) -> list[AnalysisSectionDirect]:
Expand All @@ -170,10 +168,6 @@ def indirect(self) -> list[AnalysisSectionIndirect]:
filter(lambda x: isinstance(x, AnalysisSectionIndirect), self.analyses)
)


class AnalysisConfigDataWithNetwork(AnalysisConfigData):
pass


class AnalysisConfigDataWithoutNetwork(AnalysisConfigData):
pass
@staticmethod
def get_data_output(ini_file: Path) -> Path:
return ini_file.parent.joinpath("output")
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@
IndirectAnalysisNameList,
ProjectSection,
)
from ra2ce.analyses.analysis_config_wrapper.analysis_config_wrapper_base import (
AnalysisConfigWrapperBase,
)
from ra2ce.common.configuration.ini_configuration_reader_protocol import (
ConfigDataReaderProtocol,
)


class AnalysisConfigReaderBase(ConfigDataReaderProtocol):
class AnalysisConfigDataReader(ConfigDataReaderProtocol):
"""
Reads the analysis configuration file analyses.ini.
Takes network_data as optional input. If not provided, it will read the network configuration
from the network.ini in the output folder.
"""

_parser: ConfigParser

def __init__(self) -> None:
Expand All @@ -58,18 +61,17 @@ def read(self, ini_file: Path) -> AnalysisConfigData:
self._remove_none_values()

_parent_dir = ini_file.parent

_config_data = AnalysisConfigData(
root_path=_parent_dir.parent,
input_path=_parent_dir.joinpath("input"),
static_path=_parent_dir.joinpath("static"),
output_path=_parent_dir.joinpath("output"),
**self._get_sections(),
)
_config_data.root_path = AnalysisConfigWrapperBase.get_network_root_dir(
ini_file
)
_config_data.project.name = _parent_dir.name

self._copy_output_files(ini_file, _config_data)

return _config_data

def _remove_none_values(self) -> None:
Expand Down Expand Up @@ -200,7 +202,7 @@ def _get_analysis_section_direct(self, section_name: str) -> AnalysisSectionDire
"evaluation_period",
fallback=_section.evaluation_period,
)
_section.return_pinterest_rateeriod = self._parser.getfloat(
_section.interest_rate = self._parser.getfloat(
section_name,
"interest_rate",
fallback=_section.interest_rate,
Expand Down Expand Up @@ -252,9 +254,7 @@ def get_analysis_sections(self) -> list[AnalysisSectionBase]:
def _copy_output_files(
self, from_path: Path, config_data: AnalysisConfigData
) -> None:
_output_dir = config_data.root_path.joinpath(config_data.project.name).joinpath(
"output"
)
_output_dir = config_data.root_path.joinpath(config_data.project.name, "output")
config_data.output_path = _output_dir
if not _output_dir.exists():
_output_dir.mkdir(parents=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
"""


import math
from pathlib import Path
from typing import Any

from ra2ce.analyses.analysis_config_data.analysis_config_data import (
AnalysisConfigDataWithoutNetwork,
IndirectAnalysisNameList,
AnalysisConfigData,
DirectAnalysisNameList,
IndirectAnalysisNameList,
)
from ra2ce.common.validation.ra2ce_validator_protocol import Ra2ceIoValidator
from ra2ce.common.validation.validation_report import ValidationReport
Expand All @@ -40,8 +38,8 @@
}


class AnalysisConfigDataValidatorWithoutNetwork(Ra2ceIoValidator):
def __init__(self, config_data: AnalysisConfigDataWithoutNetwork) -> None:
class AnalysisConfigDataValidator(Ra2ceIoValidator):
def __init__(self, config_data: AnalysisConfigData) -> None:
self._config = config_data

def _validate_header(self, header: Any) -> ValidationReport:
Expand Down Expand Up @@ -69,7 +67,13 @@ def _validate_headers(self, required_headers: list[str]) -> ValidationReport:
_available_keys = self._config.__dict__.keys()

def _check_header(header: str) -> None:
if header not in _available_keys:
"""
Check if the section is provided and non-empty
Args:
header (str): section name
"""
if header not in _available_keys or not getattr(self._config, header):
_report.error(
f"Property [ {header} ] is not configured. Add property [ {header} ] to the *.ini file. "
)
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion ra2ce/analyses/analysis_config_data/readers/__init__.py

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c80d6aa

Please sign in to comment.