Skip to content

Commit

Permalink
Add unique index to label in fmuobs when converting from ResInsight f…
Browse files Browse the repository at this point in the history
…ormat to be ERT compatible (#636)
  • Loading branch information
asnyv authored Dec 7, 2023
1 parent d0f04a1 commit 2142fc5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/subscript/fmuobs/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ def resinsight_df2df(ri_dframe: pd.DataFrame) -> pd.DataFrame:

dframe = ri_dframe.copy()
dframe.rename({"VECTOR": "KEY"}, axis="columns", inplace=True)
dframe["LABEL"] = dframe["KEY"].astype(str) # + "-" + dframe["DATE"].astype(str)
dframe["LABEL"] = (
dframe["KEY"].astype(str)
+ "-"
+ (dframe.groupby("KEY").cumcount() + 1).astype(str)
)
dframe["CLASS"] = "SUMMARY_OBSERVATION"
if "DATE" in dframe:
dframe["DATE"] = pd.to_datetime(dframe["DATE"])
Expand Down
1 change: 1 addition & 0 deletions tests/testdata_fmuobs/ert-doc.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CLASS,LABEL,VALUE,ERROR,DATE,KEY,RESTART,DAYS,OBS,FIELD,I,J,K,SOURCE,DATA,OBS_FILE,INDEX_LIST,ERROR_MODE,ERROR_MIN,SEGMENT,START,STOP
SUMMARY_OBSERVATION,SEP_TEST_2005,100.0,5.0,2005-08-21,GOPR:BRENT,,,,,,,,,,,,,,,,
SUMMARY_OBSERVATION,SEP_TEST_2006,100.0,5.0,2006-08-21,GOPR:BRENT,,,,,,,,,,,,,,,,
SUMMARY_OBSERVATION,SEP_TEST_RST_2005,100.0,5.0,,GOPR:BRENT,42.0,,,,,,,,,,,,,,,
SUMMARY_OBSERVATION,SEP_TEST_2008,213.0,10.0,,GOPR:NESS,,911.0,,,,,,,,,,,,,,
BLOCK_OBSERVATION,RFT_2006,100.0,5.0,2006-10-22,,,,P1,PRESSURE,1.0,1.0,1.0,,,,,,,,,
Expand Down
10 changes: 9 additions & 1 deletion tests/testdata_fmuobs/ert-doc.obs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- These observation data are copied from the ERT docs,
-- These observation data are mainly copied from the ERT docs,
-- https://github.com/equinor/ert/blob/master/docs/rst/manual/reference/configuration/observations.rst

SUMMARY_OBSERVATION SEP_TEST_2005
Expand All @@ -8,6 +8,14 @@
DATE = 21/08/2005;
KEY = GOPR:BRENT;
};
-- Duplicate key, but unique label and date.
SUMMARY_OBSERVATION SEP_TEST_2006
{
VALUE = 100.0;
ERROR = 5;
DATE = 21/08/2006;
KEY = GOPR:BRENT;
};

-- Giving the observation time in terms of restart number.
SUMMARY_OBSERVATION SEP_TEST_RST_2005
Expand Down
4 changes: 4 additions & 0 deletions tests/testdata_fmuobs/ert-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ smry:
error: 5.0
label: SEP_TEST_2005
value: 100.0
- date: '2006-08-21'
error: 5.0
label: SEP_TEST_2006
value: 100.0
- error: 5.0
label: SEP_TEST_RST_2005
restart: 42.0
Expand Down
1 change: 1 addition & 0 deletions tests/testdata_fmuobs/ri-obs.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DATE;VECTOR;VALUE;ERROR
2005-08-21;GOPR:BRENT;100.0;5.0
2006-08-21;GOPR:BRENT;100.0;5.0

0 comments on commit 2142fc5

Please sign in to comment.