forked from equinor/fmu-dataio
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
219 additions
and
4 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,32 @@ | ||
#!/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: | ||
abs_path = Path(sys.argv[1]) | ||
CFG = ut.yaml_load(abs_path / "fmuconfig/output/global_variables.yml") | ||
surf = xtgeo.surface_from_file(abs_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,68 @@ | ||
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 | ||
|
||
|
||
def _add_export_a_surface(snakeoil_path: Path, ert_config: str) -> None: | ||
with open(ert_config, "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" | ||
"INSTALL_JOB EXPORT_A_SURFACE ../bin/jobs/EXPORT_A_SURFACE\n" | ||
f"FORWARD_MODEL EXPORT_A_SURFACE(<SNAKEOIL_PATH>={snakeoil_path})\n" | ||
] | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def snakeoil_export_surface( | ||
fmu_snakeoil_project: Path, monkeypatch: Any, mocker: Any | ||
) -> Path: | ||
monkeypatch.chdir(fmu_snakeoil_project / "ert/model") | ||
_add_export_a_surface(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