Skip to content

Commit

Permalink
Merge rft also on report_step
Browse files Browse the repository at this point in the history
  • Loading branch information
alifbe committed Oct 12, 2023
1 parent 469a6ec commit a9e1894
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/subscript/merge_rft_ertobs/merge_rft_ertobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def split_wellname_reportstep(wellname_reportstep: str) -> Tuple[str, int]:
A-5_99 gives (A-5_99, 1) # report steps more than 10 not supported.
"R_A4_1" gives (R_A4, 1)
"R_A4" gives (R_A4, 1)
"R_A_4" gives (R_A, 4) # Warning, this is probaly unintended!
"R_A_4" gives (R_A, 4) # Warning, this is probably unintended!
Args:
wellname_reportstep
Expand Down Expand Up @@ -224,7 +224,7 @@ def merge_rft_ertobs(gendatacsv: str, obsdir: str) -> pd.DataFrame:
# For each simulated well, look up
logger.info("Parsed %s observations from files in %s", str(len(obs_df)), obsdir)

return pd.merge(sim_df, obs_df, how="left", on=["well", "order"])
return pd.merge(sim_df, obs_df, how="left", on=["well", "order", "report_step"])


def main() -> None:
Expand Down
69 changes: 69 additions & 0 deletions tests/test_merge_rft_ertobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,75 @@ def test_merge_drogon_inactive(drogondata):
)


def test_merge_multiple_timesteps(tmp_path):
"""Check that multiple timesteps is handled properly"""
os.chdir(tmp_path)
Path("R_A2_1.obs").write_text("299.230 3.000", encoding="utf8")
Path("R_A2_2.obs").write_text("289.120 3.000", encoding="utf8")
df_gendata = pd.DataFrame(
columns=[
"order",
"utm_x",
"utm_y",
"measured_depth",
"true_vertical_depth",
"zone",
"pressure",
"valid_zone",
"is_active",
"i",
"j",
"k",
"well",
"time",
"report_step",
],
data=[
[
0,
460994.9,
5933813.29,
1697.9,
1648.9,
"Valysar",
297.59930419921875,
True,
True,
21,
29,
2,
"R_A2",
"2018-03-01",
1,
],
[
0,
460994.9,
5933813.29,
1697.9,
1648.9,
"Valysar",
287.19930419921875,
True,
True,
21,
29,
2,
"R_A2",
"2019-03-01",
2,
],
],
)
df_gendata.to_csv("gendata_rft.csv", index=False)
dframe = merge_rft_ertobs("gendata_rft.csv", ".")
assert not dframe.empty
assert {"pressure", "observed", "error", "well", "report_step", "time"}.issubset(
dframe.columns
)
assert len(dframe) == 2


def test_extra_obs_file(drogondata):
"""Test that we will not bail on a stray file"""
Path("rft/FOO.obs").write_text("FOBOBAR", encoding="utf8")
Expand Down

0 comments on commit a9e1894

Please sign in to comment.