diff --git a/src/ert/config/analysis_config.py b/src/ert/config/analysis_config.py index b14cc3968e6..a2afdf9ad6f 100644 --- a/src/ert/config/analysis_config.py +++ b/src/ert/config/analysis_config.py @@ -10,20 +10,19 @@ from pydantic import ValidationError from .analysis_module import ESSettings, IESSettings +from .design_matrix import DesignMatrix from .parsing import ( AnalysisMode, ConfigDict, ConfigKeys, ConfigValidationError, ConfigWarning, - ErrorInfo, ) logger = logging.getLogger(__name__) DEFAULT_ANALYSIS_MODE = AnalysisMode.ENSEMBLE_SMOOTHER ObservationGroups = List[str] -from ._option_dict import option_dict @dataclass @@ -33,47 +32,6 @@ class UpdateSettings: auto_scale_observations: List[ObservationGroups] = field(default_factory=list) -@dataclass -class DesignMatrixArgs: - xls_filename: Path - designsheet: str - defaultsheet: str - - @classmethod - def from_config_list(cls, config_list: List[str]) -> "DesignMatrixArgs": - filename = Path(config_list[0]) - options = option_dict(config_list, 1) - design_sheet = options.get("DESIGN_SHEET") - default_sheet = options.get("DEFAULT_SHEET") - errors = [] - if filename.suffix not in { - ".xlsx", - ".xls", - }: - errors.append( - ErrorInfo( - f"DESIGN_MATRIX must be of format .xls or .xslx; is {filename}" - ).set_context(config_list) - ) - if design_sheet is None: - errors.append( - ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list) - ) - if default_sheet is None: - errors.append( - ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list) - ) - if errors: - raise ConfigValidationError.from_collected(errors) - assert design_sheet is not None - assert default_sheet is not None - return cls( - xls_filename=filename, - designsheet=design_sheet, - defaultsheet=default_sheet, - ) - - @dataclass class AnalysisConfig: max_runtime: Optional[int] = None @@ -83,7 +41,7 @@ class AnalysisConfig: ies_module: IESSettings = field(default_factory=IESSettings) observation_settings: UpdateSettings = field(default_factory=UpdateSettings) num_iterations: int = 1 - design_matrix_args: Optional[DesignMatrixArgs] = None + design_matrix_args: Optional[DesignMatrix] = None @no_type_check @classmethod @@ -236,9 +194,7 @@ def from_dict(cls, config_dict: ConfigDict) -> "AnalysisConfig": observation_settings=obs_settings, es_module=es_settings, ies_module=ies_settings, - design_matrix_args=DesignMatrixArgs.from_config_list( - design_matrix_config_list - ) + design_matrix_args=DesignMatrix.from_config_list(design_matrix_config_list) if design_matrix_config_list is not None else None, ) diff --git a/src/ert/config/design_matrix.py b/src/ert/config/design_matrix.py new file mode 100644 index 00000000000..2760f42c415 --- /dev/null +++ b/src/ert/config/design_matrix.py @@ -0,0 +1,52 @@ +from __future__ import annotations + +from dataclasses import dataclass +from pathlib import Path +from typing import List + +from ._option_dict import option_dict +from .parsing import ( + ConfigValidationError, + ErrorInfo, +) + + +@dataclass +class DesignMatrix: + xls_filename: Path + designsheet: str + defaultsheet: str + + @classmethod + def from_config_list(cls, config_list: List[str]) -> "DesignMatrix": + filename = Path(config_list[0]) + options = option_dict(config_list, 1) + design_sheet = options.get("DESIGN_SHEET") + default_sheet = options.get("DEFAULT_SHEET") + errors = [] + if filename.suffix not in { + ".xlsx", + ".xls", + }: + errors.append( + ErrorInfo( + f"DESIGN_MATRIX must be of format .xls or .xslx; is {filename}" + ).set_context(config_list) + ) + if design_sheet is None: + errors.append( + ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list) + ) + if default_sheet is None: + errors.append( + ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list) + ) + if errors: + raise ConfigValidationError.from_collected(errors) + assert design_sheet is not None + assert default_sheet is not None + return cls( + xls_filename=filename, + designsheet=design_sheet, + defaultsheet=default_sheet, + )