From 82ef3783f986a27fb21ae28a5d680e5384f2639f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Tue, 30 Aug 2022 10:25:46 +0200 Subject: [PATCH] Forward label from observations dataframes to mismatch dfs (#221) --- src/fmu/ensemble/observations.py | 5 +++++ tests/test_observations.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/fmu/ensemble/observations.py b/src/fmu/ensemble/observations.py index 26568dcd..c2615d89 100644 --- a/src/fmu/ensemble/observations.py +++ b/src/fmu/ensemble/observations.py @@ -232,6 +232,7 @@ def _realization_mismatch(self, real): The returned dataframe contains the columns: * OBSTYPE - category/type of the observation * OBSKEY - name of the observation key + * LABEL - if an observation has it * DATE - only where relevant. * OBSINDEX - where an enumeration is relevant * MISMATCH - signed difference between value and result @@ -272,6 +273,7 @@ def _realization_mismatch(self, real): OBSKEY=str(obsunit["localpath"]) + "/" + str(obsunit["key"]), + LABEL=obsunit.get("label", ""), MISMATCH=mismatch, L1=abs(mismatch), L2=abs(mismatch) ** 2, @@ -296,6 +298,7 @@ def _realization_mismatch(self, real): dict( OBSTYPE=obstype, OBSKEY=str(obsunit["key"]), + LABEL=obsunit.get("label", ""), MISMATCH=mismatch, L1=abs(mismatch), SIMVALUE=sim_value, @@ -353,6 +356,7 @@ def _realization_mismatch(self, real): dict( OBSTYPE="smryh", OBSKEY=obsunit["key"], + LABEL=obsunit.get("label", ""), MISMATCH=sim_hist["mismatch"].sum(), MEASERROR=measerror, L1=sim_hist["mismatch"].abs().sum(), @@ -383,6 +387,7 @@ def _realization_mismatch(self, real): OBSKEY=obsunit["key"], DATE=unit["date"], MEASERROR=unit["error"], + LABEL=unit.get("label", ""), MISMATCH=mismatch, OBSVALUE=unit["value"], SIMVALUE=sim_value, diff --git a/tests/test_observations.py b/tests/test_observations.py index 8c64fab0..2702062a 100644 --- a/tests/test_observations.py +++ b/tests/test_observations.py @@ -73,6 +73,7 @@ def test_real_mismatch(): assert "OBSTYPE" in realmis.columns assert "OBSKEY" in realmis.columns assert "DATE" not in realmis.columns # date is not relevant + assert "LABEL" in realmis.columns assert "MISMATCH" in realmis.columns assert "L1" in realmis.columns assert "L2" in realmis.columns @@ -80,6 +81,7 @@ def test_real_mismatch(): # Check actually computed values, there should only be one row with data: assert realmis.loc[0, "OBSTYPE"] == "txt" assert realmis.loc[0, "OBSKEY"] == "parameters.txt/FWL" + assert set(realmis["LABEL"]) == {""} assert realmis.loc[0, "MISMATCH"] == -2 assert realmis.loc[0, "SIGN"] == -1 assert realmis.loc[0, "L1"] == 2 @@ -227,6 +229,34 @@ def test_smry(): # print(vmismatch) +def test_smry_labels(): + testdir = os.path.dirname(os.path.abspath(__file__)) + real = ScratchRealization( + testdir + "/data/testensemble-reek001/" + "realization-0/iter-0/" + ) + real.load_smry() + obs_pr = Observations( + { + "smry": [ + { + "key": "WBP4:OP_1", + "comment": "Pressure observations well OP_1", + "observations": [ + { + "value": 250, + "error": 1, + "date": datetime.date(2001, 1, 1), + "label": "WBP4_OP_1_01", + } + ], + } + ] + } + ) + mismatch = obs_pr.mismatch(real) + assert mismatch["LABEL"].values == ["WBP4_OP_1_01"] + + def test_errormessages(): """Test that we give ~sensible error messages when the observation input is unparseable"""