From 606236897d638f86f4affc3bc73c0f4927c3c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20C=2E=20Riven=C3=A6s?= Date: Thu, 12 Oct 2023 12:40:57 +0200 Subject: [PATCH] Fix a bug related to dataio output with diffdates --- src/xtgeoapp_grd3dmaps/avghc/_configparser.py | 27 +++++++++++-------- .../avghc/_export_via_fmudataio.py | 1 + .../avghc/grid3d_average_map.py | 1 + .../test_grid3d_average_map_dataio1a.py | 5 ++++ tests/yaml/global_config3a.yml | 3 +++ 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/xtgeoapp_grd3dmaps/avghc/_configparser.py b/src/xtgeoapp_grd3dmaps/avghc/_configparser.py index c6dbd05..a16fc07 100644 --- a/src/xtgeoapp_grd3dmaps/avghc/_configparser.py +++ b/src/xtgeoapp_grd3dmaps/avghc/_configparser.py @@ -6,6 +6,7 @@ import yaml from xtgeo.common import XTGeoDialog + from xtgeoapp_grd3dmaps.avghc._loader import ConstructorError, YamlXLoader xtg = XTGeoDialog() @@ -79,7 +80,6 @@ def parse_args(args, appname, appdescr): ) if appname == "grid3d_hc_thickness": - parser.add_argument( "-d", "--dates", @@ -149,12 +149,12 @@ def prepare_metadata(config): look like this: "metadata": { - "SWAT--19991201": { # identifier name in this package + "SWAT--19991201-20010101": { # identifier name in this package "name": "SWAT", # generic property name "nameinfo" # e.g. "oilthickness" "source": "$eclroot.UNRST", # info - "t1": "20010101", # timedata entry 1 - "t2": "19991201", # timedata entry 2 + "t1": "19991201", # timedata entry 1 + "t2": "20010101", # timedata entry 2 "content": "saturation", # content info for sumo "unit": "fraction", # unit info "globaltag": "avg2c" # a global tag from output.tag @@ -274,7 +274,6 @@ def propformatting(config): newdates.append(entry.strftime("%Y%m%d")) else: newdates.append(entry) - fetched_metadata.update({"t1": entry}) if "diffdates" in prop: for entry in prop["diffdates"]: @@ -285,8 +284,6 @@ def propformatting(config): if isinstance(dd2, datetime.date): dd2 = dd2.strftime("%Y%m%d") newdates.append(dd1 + "-" + dd2) - fetched_metadata.update({"t1": dd1}) - fetched_metadata.update({"t2": dd2}) # get the addional metadata privded by user input under properties: if "metadata" in prop: @@ -294,11 +291,19 @@ def propformatting(config): namekey = prop["name"] namekeys = [] + datekeys = {} if newdates: for mydate in newdates: namekey = prop["name"] + "--" + mydate newconfig["input"][namekey] = prop["source"] namekeys.append(namekey) + if len(mydate) == 8: + datekeys[namekey] = {"t1": mydate} + else: + dd1 = mydate[:8] + dd2 = mydate[9:] + datekeys[namekey] = {"t1": dd1, "t2": dd2} + else: newconfig["input"][namekey] = prop["source"] namekeys.append(namekey) @@ -307,7 +312,9 @@ def propformatting(config): fetched_metadata.update({"globaltag": config["output"]["tag"]}) for nkey in namekeys: - newconfig["metadata"][nkey] = fetched_metadata + newconfig["metadata"][nkey] = copy.deepcopy(fetched_metadata) + if nkey in datekeys: + newconfig["metadata"][nkey].update(datekeys[nkey]) del newconfig["input"]["properties"] @@ -363,7 +370,6 @@ def yconfig_override(config, args, appname): newconfig["output"]["legacydateformat"] = args.legacydateformat if appname == "grid3d_hc_thickness": - if args.dates: newconfig["input"]["dates"] = args.dates @@ -440,7 +446,6 @@ def yconfig_set_defaults(config, appname): newconfig["computesettings"]["tuning"]["coarsen"] = 1 if appname == "grid3d_hc_thickness": - if "dates" not in newconfig["input"]: if newconfig["computesettings"]["mode"] in "rock": xtg.say('No date give, probably OK since "rock" mode)') @@ -500,7 +505,6 @@ def yconfig_addons(config, appname): newconfig = copy.deepcopy(config) if config["zonation"]["yamlfile"] is not None: - # re-use yconfig: zconfig = yconfig(config["zonation"]["yamlfile"]) if "zranges" in zconfig: @@ -531,3 +535,4 @@ def yconfig_metadata_hc(config): newconfig["metadata"]["globaltag"] = config["output"].get("tag", "") return newconfig + return newconfig diff --git a/src/xtgeoapp_grd3dmaps/avghc/_export_via_fmudataio.py b/src/xtgeoapp_grd3dmaps/avghc/_export_via_fmudataio.py index 9497830..57fa65b 100644 --- a/src/xtgeoapp_grd3dmaps/avghc/_export_via_fmudataio.py +++ b/src/xtgeoapp_grd3dmaps/avghc/_export_via_fmudataio.py @@ -74,6 +74,7 @@ def export_avg_map_dataio(surf, nametuple, config): metadata = config["metadata"] if nameid not in metadata: + logger.info("Dataio: Nameid missing %s", nametuple) raise ValueError( f"Seems that 'metadata' for {nameid} is missing! Cf. documentation" ) diff --git a/src/xtgeoapp_grd3dmaps/avghc/grid3d_average_map.py b/src/xtgeoapp_grd3dmaps/avghc/grid3d_average_map.py index 4346d8b..3116a9f 100644 --- a/src/xtgeoapp_grd3dmaps/avghc/grid3d_average_map.py +++ b/src/xtgeoapp_grd3dmaps/avghc/grid3d_average_map.py @@ -51,6 +51,7 @@ def do_parse_args(args): def yamlconfig(inputfile, args): """Read from YAML file and modify/override""" + config = _configparser.yconfig(inputfile) config = _configparser.prepare_metadata(config) config = _configparser.propformatting(config) diff --git a/tests/test_scripts/test_grid3d_average_map_dataio1a.py b/tests/test_scripts/test_grid3d_average_map_dataio1a.py index 5391ce9..33ea7ae 100644 --- a/tests/test_scripts/test_grid3d_average_map_dataio1a.py +++ b/tests/test_scripts/test_grid3d_average_map_dataio1a.py @@ -132,6 +132,11 @@ def test_average_map_dataio1a(datatree, avgdataio1aconfig): ) assert surf.values.mean() == pytest.approx(0.035489, rel=0.01) + surf = xtgeo.surface_from_file( + res / "myzone1--avgdataio1a_average_swat--20030101_20010101.gri" + ) + assert surf.values.mean() == pytest.approx(0.113534, rel=0.01) + # read metadatafile with open( res / ".myzone1--avgdataio1a_average_swat--20010101_19991201.gri.yml", diff --git a/tests/yaml/global_config3a.yml b/tests/yaml/global_config3a.yml index 7221890..9251b30 100644 --- a/tests/yaml/global_config3a.yml +++ b/tests/yaml/global_config3a.yml @@ -3,6 +3,9 @@ global: DATES: &mydates - 1999-12-01 - 2001-01-01 + - 2003-01-01 DIFFDATES: &mydiffdates - [2001-01-01, 1999-12-01] + - [2003-01-01, 2001-01-01] + - [2003-01-01, 1999-12-01]