-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add ert simulation mode to object metadata
The simulation mode should allow contextual inference about the type of ensemble this data is derived from.
- Loading branch information
Showing
13 changed files
with
286 additions
and
46 deletions.
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
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
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,34 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import xtgeo | ||
|
||
import fmu.dataio as dataio | ||
from fmu.config import utilities as ut | ||
|
||
|
||
def main() -> None: | ||
snakeoil_path = Path(sys.argv[1]) | ||
CFG = ut.yaml_load(snakeoil_path / "fmuconfig/output/global_variables.yml") | ||
surf = xtgeo.surface_from_file( | ||
snakeoil_path / "ert/output/maps/props/poro_average.gri" | ||
) | ||
dataio.ExportData( | ||
config=CFG, | ||
name="all", | ||
unit="fraction", | ||
vertical_domain="depth", | ||
domain_reference="msl", | ||
content="property", | ||
timedata=None, | ||
is_prediction=True, | ||
is_observation=False, | ||
tagname="average_poro", | ||
workflow="rms property model", | ||
).export(surf) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,35 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
|
||
def add_create_case_workflow(filepath: Path | str) -> None: | ||
with open(filepath, "a", encoding="utf-8") as f: | ||
f.writelines( | ||
[ | ||
"LOAD_WORKFLOW ../bin/workflows/xhook_create_case_metadata\n" | ||
"HOOK_WORKFLOW xhook_create_case_metadata PRE_SIMULATION\n" | ||
] | ||
) | ||
|
||
|
||
def add_copy_preprocessed_workflow(filepath: Path | str) -> None: | ||
with open(filepath, "a", encoding="utf-8") as f: | ||
f.writelines( | ||
[ | ||
"LOAD_WORKFLOW ../bin/workflows/xhook_copy_preprocessed_data\n" | ||
"HOOK_WORKFLOW xhook_copy_preprocessed_data PRE_SIMULATION\n" | ||
] | ||
) | ||
|
||
|
||
def add_export_a_surface_forward_model( | ||
snakeoil_path: Path, filepath: Path | str | ||
) -> None: | ||
with open(filepath, "a", encoding="utf-8") as f: | ||
f.writelines( | ||
[ | ||
"INSTALL_JOB EXPORT_A_SURFACE ../bin/jobs/EXPORT_A_SURFACE\n" | ||
f"FORWARD_MODEL EXPORT_A_SURFACE(<SNAKEOIL_PATH>={snakeoil_path})\n" | ||
] | ||
) |
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,62 @@ | ||
import getpass | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import ert.__main__ | ||
import pytest | ||
import yaml | ||
|
||
from fmu.dataio._model import Root | ||
from fmu.dataio._model.enums import ErtSimulationMode | ||
|
||
from .ert_config_utils import ( | ||
add_create_case_workflow, | ||
add_export_a_surface_forward_model, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def snakeoil_export_surface( | ||
fmu_snakeoil_project: Path, monkeypatch: Any, mocker: Any | ||
) -> Path: | ||
monkeypatch.chdir(fmu_snakeoil_project / "ert/model") | ||
add_create_case_workflow("snakeoil.ert") | ||
add_export_a_surface_forward_model(fmu_snakeoil_project, "snakeoil.ert") | ||
|
||
mocker.patch( | ||
"sys.argv", ["ert", "test_run", "snakeoil.ert", "--disable-monitoring"] | ||
) | ||
ert.__main__.main() | ||
return fmu_snakeoil_project | ||
|
||
|
||
def test_simple_export_case_metadata(snakeoil_export_surface: Path) -> None: | ||
fmu_case_yml = ( | ||
snakeoil_export_surface / "scratch/user/snakeoil/share/metadata/fmu_case.yml" | ||
) | ||
assert fmu_case_yml.exists() | ||
|
||
with open(fmu_case_yml, encoding="utf-8") as f: | ||
fmu_case = yaml.safe_load(f) | ||
|
||
assert fmu_case["fmu"]["case"]["name"] == "snakeoil" | ||
assert fmu_case["fmu"]["case"]["user"]["id"] == "user" | ||
assert fmu_case["source"] == "fmu" | ||
assert len(fmu_case["tracklog"]) == 1 | ||
assert fmu_case["tracklog"][0]["user"]["id"] == getpass.getuser() | ||
|
||
|
||
def test_simple_export_ert_environment_variables(snakeoil_export_surface: Path) -> None: | ||
avg_poro_yml = Path( | ||
snakeoil_export_surface | ||
/ "scratch/user/snakeoil/realization-0/iter-0" | ||
/ "share/results/maps/.all--average_poro.gri.yml" | ||
) | ||
assert avg_poro_yml.exists() | ||
|
||
with open(avg_poro_yml, encoding="utf-8") as f: | ||
avg_poro_metadata = yaml.safe_load(f) | ||
|
||
avg_poro = Root.model_validate(avg_poro_metadata) # asserts valid | ||
assert avg_poro.root.fmu.ert.simulation_mode == ErtSimulationMode.test_run | ||
assert avg_poro.root.fmu.ert.experiment.id is not None |
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
Oops, something went wrong.