Skip to content

Commit

Permalink
Forward label from observations dataframes to mismatch dfs (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
berland authored Aug 30, 2022
1 parent 097240f commit 82ef378
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/fmu/ensemble/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ 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

# 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
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 82ef378

Please sign in to comment.