From 580294d9e06ad1e333aa3e28cbd7d67f1651c29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Berland?= Date: Thu, 9 Jan 2020 13:15:47 +0100 Subject: [PATCH] Resolve bug in fipreports Colons are not reliably emitted from E100. --- ecl2df/fipreports.py | 25 +++- tests/data/fipreports/TEST1.PRT | 224 ++++++++++++++++++++++++++++++++ tests/test_fipreports.py | 22 ++++ 3 files changed, 265 insertions(+), 6 deletions(-) create mode 100644 tests/data/fipreports/TEST1.PRT diff --git a/ecl2df/fipreports.py b/ecl2df/fipreports.py index 48321fd29..711ca358c 100644 --- a/ecl2df/fipreports.py +++ b/ecl2df/fipreports.py @@ -134,6 +134,11 @@ def df(prtfile, fipname="FIPNUM"): reportblockmatcher = re.compile(".+" + fipname + r"\s+REPORT\s+REGION\s+(\d+)") with open(prtfile) as prt_fh: + logging.info( + "Parsing file %s for blocks starting with %s REPORT REGION", + prtfile, + fipname, + ) for line in prt_fh: matcheddate = re.match(datematcher, line) if matcheddate: @@ -157,12 +162,20 @@ def df(prtfile, fipname="FIPNUM"): continue if in_report_block: - if line.startswith(" :") and not line.startswith(" :--"): - records.append( - [date, fipname, region_index] - + list(report_block_lineparser(line)) - ) - + interesting_strings = ["IN PLACE", "OUTFLOW", "MATERIAL"] + if not sum([string in line for string in interesting_strings]): + # Skip if we are not on an interesting line. + continue + # The colons in the report block are not reliably included (wtf!), even in the + # same PRT file. We insert them in fixed positions and hope for the best + # (if the ASCII table is actually dynamic with respect to content, this will fail) + linechars = list(line) + linechars[1] = ":" + linechars[27] = ":" + line = "".join(linechars) + records.append( + [date, fipname, region_index] + list(report_block_lineparser(line)) + ) return pd.DataFrame(data=records, columns=REGION_REPORT_COLUMNS) diff --git a/tests/data/fipreports/TEST1.PRT b/tests/data/fipreports/TEST1.PRT new file mode 100644 index 000000000..919a1060b --- /dev/null +++ b/tests/data/fipreports/TEST1.PRT @@ -0,0 +1,224 @@ +Mock PRT file for 'fipreports' testing. + +Randomly generated data + + + + $$$$$ $$$ $ $$$ $$$$ $$$ $$$$$ $ $$$ $$$ + $ $ $ $ $ $ $ $ $ $ $$ $ $ $ $ + $ $ $ $ $ $ $ $ $ $ $ $ $ + $$$$ $ $ $ $$$$ $$$ $$$$ $ $ $ $ $ + $ $ $ $ $ $ $ $ $ $ $ $ + $ $ $ $ $ $ $ $ $ $ $ $ $ $ + $$$$$ $$$ $$$$$ $$$ $ $$$ $$$$$ $$$ $$$ $$$ + + + + REPORT 53 1 JAN 2021 * RUN * RUN AT 16:02 ON 19 DEC 2019 + ************************************************************************** + + + ================================= + : FIPZON REPORT REGION 1 : + : PAV = 139.12 BARSA: + : PORV= 26089981. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :CURRENTLY IN PLACE : 9891201. 9891201.: 4179920. : 5. 74323390. 74323396. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO OTHER REGIONS : 35270. 35270.: 114929. : 0. 897217. 897217. + :OUTFLOW THROUGH WELLS : 0.: 0. : 0. + :MATERIAL BALANCE ERROR. : 0.: 0. : 0. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :ORIGINALLY IN PLACE : 19902728. 19902728.: 4262141. : 0. 74631061. 74631061. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO REGION 2 : -221115. -221115.: 45581. : -0. -4660403. -4660403. + :OUTFLOW TO REGION 3 : 256386. 256386.: -595270. : 0. 5557621. 5557621. + :OUTFLOW TO REGION 8 : 0. 0.: 664618. : 0. 0. 0. + ==================================================================================================================================== + + + ================================= + : FIPZON REPORT REGION 2 : + : PAV = 138.74 BARSA: + : PORV= 31350409. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :CURRENTLY IN PLACE : 24704298. 24704298.: 4222285. : -0. 562865855. 562865855. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO OTHER REGIONS : 146685. 146685.: 26932. : -0. 3328252. 3328252. + :OUTFLOW THROUGH WELLS : 0.: 0. : 0. + :MATERIAL BALANCE ERROR. : 0.: 0. : 0. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :ORIGINALLY IN PLACE : 23806650. 24806650.: 4228298. : 0. 565120627. 565120627. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO REGION 1 : 221115. 221115.: -45581. : 0. 4660403. 4660403. + :OUTFLOW TO REGION 3 : -74430. -74430.: 51293. : -0. -1332151. -1332151. + :OUTFLOW TO REGION 8 : 0. 0.: 21219. : 0. 0. 0. + ==================================================================================================================================== + + + + + REPORT 54 2 JAN 2021 * RUN * RUN AT 16:05 ON 19 DEC 2019 + ************************************************************************** + + + ================================================== + : FIELD TOTALS : + : PAV = 140.06 BARSA : + : PORV=1075926033329. RM3 : + :(PRESSURE IS WEIGHTED BY HYDROCARBON PORE VOLUME: + : PORE VOLUMES ARE TAKEN AT REFERENCE CONDITIONS): + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :CURRENTLY IN PLACE : 1.403570E+08 1.403570E+08: 1.055402E+12 : 2.088401E+01 3.318054E+09 3.318054E+09: + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW THROUGH WELLS : -0.: 1048791428. : 0.: + :WELL MATERIAL BAL. ERROR: 0.: 0. : 0.: + :FIELD MATERIAL BAL. ERROR: -259130.: -8078257. : -6440022.: + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :ORIGINALLY IN PLACE : 1.400978E+08 1.400978E+08: 1.056443E+12 : 0.000000E+00 3.311614E+09 3.311614E+09: + ==================================================================================================================================== + + + ================================= + : FIPNUM REPORT REGION 2 : + : PAV = 121.18 BARSA: + : PORV= 273962699. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :CURRENTLY IN PLACE : 13380718. 13380718.: 188873426. : 20. 1944538103. 1944538123.: + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO OTHER REGIONS : 80340. 80340.: 6430043. : 0. 2189119. 2189119.: + :OUTFLOW THROUGH WELLS : 0.: 0. : 0.: + :MATERIAL BALANCE ERROR. : -193024.: -5438455. : -5124345.: + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :ORIGINALLY IN PLACE : 73268034. 73268034.: 189865015. : 0. 1941602897. 1941602897.: + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + :OUTFLOW TO REGION 3 : 80340. 80340.: 4181097. : 0. 2189119. 2189119.: + :OUTFLOW TO REGION 6 : 0. 0.: 2248946. : 0. 0. 0.: + ==================================================================================================================================== + + + REPORT 54 2 JAN 2021 * RUN * RUN AT 16:05 ON 19 DEC 2019 + ************************************************************************** + + + +### LOOK, COLONS ARE MISSING IN THE NEXT TABLE. NEED TO SUPPORT THAT. + + ================================= + : FIPOWG REPORT REGION 3 : + : PAV = 140.06 BARSA: + : PORV=1075926033329. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + CURRENTLY IN PLACE 1.403570E+08 1.403570E+08: 1.055402E+12 : 2.088401E+01 3.318054E+09 3.318054E+09 + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO OTHER REGIONS -2367898. -2367898.: 1638474. : 0. -51751548. -51751548. + OUTFLOW THROUGH WELLS 0.: 1048791428. : 0. + MATERIAL BALANCE ERROR. -137989081.: -39241028. : -3266302584. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + ORIGINALLY IN PLACE 0.000000E+00 0.000000E+00: 1.056413E+12 : 0.000000E+00 0.000000E+00 0.000000E+00 + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO REGION 2 -2367898. -2367898.: 1638474. : 0. -51751548. -51751548. + ==================================================================================================================================== + + + + REPORT 54 2 JAN 2021 * RUN * RUN AT 16:05 ON 19 DEC 2019 + ************************************************************************** + + + ================================= + : FIPZON REPORT REGION 1 : + : PAV = 139.08 BARSA: + : PORV= 26089981. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + CURRENTLY IN PLACE 19891148. 19891148.: 4179893. : 5. 474322026. 474322032. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO OTHER REGIONS 35323. 35323.: 114955. : 0. 898582. 898582. + OUTFLOW THROUGH WELLS 0.: 0. : 0. + MATERIAL BALANCE ERROR. -23743.: -32708. : -589553. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + ORIGINALLY IN PLACE 19902728. 19902728.: 4262141. : 0. 474631061. 474631061. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO REGION 2 -221170. -221170.: 45586. : -0. -4661555. -4661555. + OUTFLOW TO REGION 3 256493. 256493.: -595444. : 0. 5560137. 5560137. + OUTFLOW TO REGION 8 0. 0.: 664814. : 0. 0. 0. + ==================================================================================================================================== + + + ================================= + : FIPZON REPORT REGION 2 : + : PAV = 138.72 BARSA: + : PORV= 31350409. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + CURRENTLY IN PLACE 24704248. 24704248.: 4222262. : -0. 562864596. 562864596. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO OTHER REGIONS 146736. 146736.: 26953. : -0. 3329521. 3329521. + OUTFLOW THROUGH WELLS 0.: 0. : 0. + MATERIAL BALANCE ERROR. -44334.: -20918. : -1073490. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + ORIGINALLY IN PLACE 24806650. 24806650.: 4228298. : 0. 565120627. 565120627. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO REGION 1 221170. 221170.: -45586. : 0. 4661555. 4661555. + OUTFLOW TO REGION 3 -74435. -74435.: 51315. : -0. -1332033. -1332033. + OUTFLOW TO REGION 8 0. 0.: 21224. : 0. 0. 0. + ==================================================================================================================================== + + + REPORT 55 1 JAN 2022 * RUN * RUN AT 18:00 ON 19 DEC 2019 + ************************************************************************** + + + ================================= + : FIPZON REPORT REGION 1 : + : PAV = 137.09 BARSA: + : PORV= 6089981. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + CURRENTLY IN PLACE 19890207. 19890207.: 4175770. : 4. 474289776. 474289780. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO OTHER REGIONS 36779. 36779.: 119664. : 0. 944001. 944001. + OUTFLOW THROUGH WELLS 0.: 0. : 0. + MATERIAL BALANCE ERROR. -24258.: -33293. : -602721. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + ORIGINALLY IN PLACE 19902728. 19902728.: 4262141. : 0. 474631061. 474631061. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO REGION 2 -233669. -233669.: 46693. : -0. -4920620. -4920620. + OUTFLOW TO REGION 3 270448. 270448.: -640608. : 0. 5864621. 5864621. + OUTFLOW TO REGION 8 0. 0.: 713579. : 0. 0. 0. + ==================================================================================================================================== + + + ================================= + : FIPZON REPORT REGION 2 : + : PAV = 137.07 BARSA: + : PORV= 1350409. RM3 : + :--------------- OIL SM3 ---------------:-- WAT SM3 -:--------------- GAS SM3 ---------------: + : LIQUID VAPOUR TOTAL : TOTAL : FREE DISSOLVED TOTAL : + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + CURRENTLY IN PLACE 24705984. 24305984.: 4215414. : -0. 562889578. 562889578. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO OTHER REGIONS 145873. 145873.: 34025. : -0. 3326568. 3326568. + OUTFLOW THROUGH WELLS 0.: 0. : 0. + MATERIAL BALANCE ERROR. -45207.: -21142. : -1095518. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + ORIGINALLY IN PLACE 23806650. 23806650.: 4228298. : 0. 565120627. 565120627. + :-------------------------:-------------------------------------------:----------------:-------------------------------------------: + OUTFLOW TO REGION 1 233669. 233669.: -46693. : 0. 4920620. 4920620. + OUTFLOW TO REGION 3 -87796. -87796.: 58859. : -0. -1594053. -1594053. + OUTFLOW TO REGION 8 0. 0.: 21859. : 0. 0. 0. + ==================================================================================================================================== diff --git a/tests/test_fipreports.py b/tests/test_fipreports.py index c34e8c6f7..b0001fcee 100644 --- a/tests/test_fipreports.py +++ b/tests/test_fipreports.py @@ -15,6 +15,7 @@ TESTDIR = os.path.dirname(os.path.abspath(__file__)) DATAFILE = os.path.join(TESTDIR, "data/reek/eclipse/model/2_R001_REEK-0.DATA") +MOCKPRTFILE = os.path.join(TESTDIR, "data/fipreports/TEST1.PRT") def test_fipreports2df(): @@ -27,6 +28,27 @@ def test_fipreports2df(): assert len(fipreport_df["DATATYPE"].unique()) == 5 +def test_mockprtfile(): + """ + Test (a) mocked PRT file(s) + """ + dframe = fipreports.df(MOCKPRTFILE) + assert dframe["FIPNAME"].unique() == "FIPNUM" + assert len(dframe["DATE"].unique()) == 1 + assert int(dframe.loc[0, "GIIP_GAS"]) == 20 + + dframe = fipreports.df(MOCKPRTFILE, fipname="FIPZON") + assert dframe["FIPNAME"].unique() == "FIPZON" + assert len(dframe["REGION"].unique()) == 2 + assert len(dframe["TO_REGION"].dropna().unique()) == 4 + assert len(dframe["DATE"].unique()) == 3 + assert len(dframe["DATATYPE"].unique()) == 6 + + dframe = fipreports.df(MOCKPRTFILE, fipname="FIPOWG") + assert dframe["FIPNAME"].unique() == "FIPOWG" + assert len(dframe["DATE"].unique()) == 1 + + def test_report_block_lineparser(): """ Test the line-parser, which has to infer partly which phases are present.