-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for design matrix keyword in ert config
- Expects the format: DESIGN_MATRIX file.xlsx DESIGN_SHEET:design DEFAULT_SHEET:default where file.xlsx is an existing file. - Scaffolding for further support for reading parameter values from design matrix excel files.
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -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 | ||
design_sheet: str | ||
default_sheet: 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 .xlsx; 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, | ||
design_sheet=design_sheet, | ||
default_sheet=default_sheet, | ||
) |
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
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
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