Skip to content

Commit

Permalink
Adjust/fix interface with fmu-dataio
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Nov 22, 2022
1 parent 95d99c6 commit f27016c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy
pyyaml
xtgeo
fmu-dataio>=1.0.0
fmu-dataio>=1.3.0
xtgeoviz
11 changes: 9 additions & 2 deletions src/xtgeoapp_grd3dmaps/avghc/_export_via_fmudataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ def export_avg_map_dataio(surf, nametuple, config):

mdata = metadata[nameid]
name = mdata.get("name", "unknown_name")
attribute = mdata.get("content", "unknown_attribute")
attribute = mdata.get("attribute", "unknown_attribute")
unit = mdata.get("unit", None)
tt1 = mdata.get("t1", None)
tt2 = mdata.get("t2", None)
if tt1 and tt1 not in nameid:
tt1 = None
if tt2 and tt2 not in nameid:
tt2 = None

globaltag = mdata.get("globaltag", "")
globaltag = globaltag + "_" if globaltag else ""
Expand All @@ -45,7 +49,10 @@ def export_avg_map_dataio(surf, nametuple, config):
if tt1:
tdata = [[tt1, "monitor"]]
if tt2:
tdata.append([tt2, "base"])
if tdata:
tdata.append([tt2, "base"])
else:
tdata = [[tt2, "base"]]

edata = dataio.ExportData(
name=zoneinfo,
Expand Down
39 changes: 34 additions & 5 deletions tests/test_scripts/test_grid3d_average_map_dataio1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
dates: !include_from tests/yaml/global_config3a.yml::global.DATES
diffdates: !include_from tests/yaml/global_config3a.yml::global.DIFFDATES
metadata:
content: saturation
attribute: saturation
unit: fraction
- name: PRESSURE
source: $eclroot.UNRST
dates: !include_from tests/yaml/global_config3a.yml::global.DATES
diffdates: !include_from tests/yaml/global_config3a.yml::global.DIFFDATES
metadata:
content: pressure
attribute: pressure
unit: bar
zonation:
Expand Down Expand Up @@ -69,16 +69,36 @@
output:
tag: avgdataio1a # the tag will added to file name as extra info
# Note: using the 'magical' fmu-dataio as argument!
mapfolder: fmu-dataio
mapfolder: MODE
"""
SOURCEPATH = Path(__file__).absolute().parent.parent.parent


def test_average_map_dataio1a_legacy(datatree):
"""Test AVG with YAML config example 3a as legacy example"""

tmp = datatree / "tmp_legacy"
tmp.mkdir(parents=True, exist_ok=True)

content = YAMLCONTENT.replace("MODE", str(tmp))

cfg = datatree / "avgdataio1a_legacy.yml"
cfg.write_text(content)

grid3d_average_map.main(
["--config", "avgdataio1a_legacy.yml", "--dump", "dump_config.yml"]
)
out = tmp / "myzone1--avgdataio1a_average_swat--20010101_19991201.gri"
assert out.is_file()


def test_average_map_dataio1a_add2docs(datatree):
"""Test AVG with YAML config example 3a piped through dataio"""

content = YAMLCONTENT.replace("MODE", "fmu-dataio")

cfg = datatree / "avgdataio1a.yml"
cfg.write_text(YAMLCONTENT)
cfg.write_text(content)

os.environ["FMU_GLOBAL_CONFIG"] = str(
datatree / "tests" / "data" / "reek" / "global_variables.yml"
Expand All @@ -105,7 +125,16 @@ def test_average_map_dataio1a_add2docs(datatree):
print(json.dumps(metadata, indent=4))

assert metadata["data"]["spec"]["ncol"] == 200
assert metadata["data"]["content"]["property"]["attribute"] == "saturation"
assert metadata["data"]["property"]["attribute"] == "saturation"

legacy = (
datatree
/ "tmp_legacy"
/ "myzone1--avgdataio1a_average_swat--20010101_19991201.gri"
)
if legacy.is_file():
surf2 = xtgeo.surface_from_file(legacy)
assert surf2.generate_hash() == surf.generate_hash()

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
2 changes: 1 addition & 1 deletion tests/test_scripts/test_grid3d_hc_thickness_dataio1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_hc_thickness_1a_add2docs(datatree):
print(json.dumps(metadata, indent=4))

assert metadata["data"]["spec"]["ncol"] == 146
assert metadata["data"]["content"]["property"]["attribute"] == "oilthickness"
assert metadata["data"]["property"]["attribute"] == "oilthickness"

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")
3 changes: 2 additions & 1 deletion tests/test_scripts/test_grid3d_hc_thickness_dataio1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_hc_thickness_1b_add2docs(datatree):
print(json.dumps(metadata, indent=4))

assert metadata["data"]["spec"]["ncol"] == 161
assert metadata["data"]["content"]["property"]["attribute"] == "oilthickness"
assert metadata["data"]["content"] == "property"
assert metadata["data"]["property"]["attribute"] == "oilthickness"

# for auto documentation
shutil.copy2(cfg, SOURCEPATH / "docs" / "test_to_docs")

0 comments on commit f27016c

Please sign in to comment.