def test_prtvol2csv_regions_typemix(tmpdir, mocker): """Test merging in region data, getting data from yaml""" prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" yamlexample = { "region2fipnum": { "RegionA": [1, 4, 6], 8: [2, 5], } } tmpdir.chdir() Path("regions.yml").write_text(yaml.dump(yamlexample)) mocker.patch( "sys.argv", ["prtvol2csv", str(prtfile), "--yaml", "regions.yml"]) mocker.patch( "sys.argv", ["prtvol2csv", str(prtfile), "--yaml", "regions.yml"]) with pytest.warns(FutureWarning, match="Output directories"): prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_fipnum.csv") assert not dframe.empty assert "REGION" in dframe assert "ZONE" not in dframe assert "RegionA" in dframe["REGION"].values assert "8" in dframe["REGION"].values assert len(dframe) == 6
def test_prtvol2csv_noresvol(tmpdir, mocker): """Test when FIPRESV is not included Perform the test by just fiddling with the test PRT file """ prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" tmpdir.chdir() prtlines = Path(prtfile).read_text().replace("RESERVOIR VOLUMES", "foobar volumes") Path("MODIFIED.PRT").write_text(prtlines) mocker.patch("sys.argv", ["prtvol2csv", "MODIFIED.PRT"]) with pytest.warns(FutureWarning, match="Output directories"): prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_fipnum.csv") assert not dframe.empty assert len(dframe) == 6 assert "PORV_TOTAL" not in dframe
def test_prtvol2csv_noresvol(tmpdir): """Test when FIPRESV is not included Perform the test by just fiddling with the test PRT file """ prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" tmpdir.chdir() prtlines = open(prtfile).read().replace("RESERVOIR VOLUMES", "foobar volumes") with open("MODIFIED.PRT", "w") as mod_fh: mod_fh.write(prtlines) sys.argv = ["prtvol2csv", "MODIFIED.PRT"] prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_fipnum.csv") assert not dframe.empty assert len(dframe) == 6 assert "PORV_TOTAL" not in dframe
def test_prtvol2csv_regions(tmp_path, mocker): """Test region support, getting data from yaml. The functionality of writing CSV data grouped by regions will be removed later from prtvol2csv. """ prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" yamlexample = { "region2fipnum": { "RegionA": [1, 4, 6], "RegionB": [2, 5], "Totals": [1, 2, 3, 4, 5, 6], }, "zone2fipnum": {"Upper": [1, 2], "Mid": [3, 4], "Lower": [5, 6]}, } expected_fip_reg_dframe = pd.DataFrame( [ {"FIPNUM": 1, "REGION": "RegionA", "ZONE": "Upper"}, {"FIPNUM": 2, "REGION": "RegionB", "ZONE": "Upper"}, {"FIPNUM": 3, "REGION": np.nan, "ZONE": "Mid"}, {"FIPNUM": 4, "REGION": "RegionA", "ZONE": "Mid"}, {"FIPNUM": 5, "REGION": "RegionB", "ZONE": "Lower"}, {"FIPNUM": 6, "REGION": "RegionA", "ZONE": "Lower"}, ] ) os.chdir(tmp_path) Path("regions.yml").write_text(yaml.dump(yamlexample), encoding="utf8") mocker.patch("sys.argv", ["prtvol2csv", str(prtfile), "--yaml", "regions.yml"]) with pytest.warns(FutureWarning): prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_fipnum.csv") print("Computed:") print(dframe) pd.testing.assert_frame_equal( dframe[["FIPNUM", "REGION", "ZONE"]], expected_fip_reg_dframe )
def test_prtvol2csv_regions_typemix(tmpdir): """Test region support, getting data from yaml""" prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" yamlexample = { "region2fipnum": { "RegionA": [1, 4, 6], 8: [2, 5], } } tmpdir.chdir() Path("regions.yml").write_text(yaml.dump(yamlexample)) sys.argv = ["prtvol2csv", str(prtfile), "--regions", "regions.yml"] prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_region.csv") assert not dframe.empty assert "REGION" in dframe assert "ZONE" not in dframe assert "RegionA" in dframe["REGION"].values assert "8" in dframe["REGION"].values assert len(dframe) == 2
def test_prtvol2csv_webvizyaml(tmp_path, mocker): """Test region2fipnum-map in webviz-yaml-format""" os.chdir(tmp_path) prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" webvizmap = { "FIPNUM": { "groups": { "REGION": {"RegionA": [1, 3, 5], "RegionB": [2, 4, 6]}, "ZONE": { "Upper": [1, 2], "Middle": [3, 4], "Lower": [5, 6], }, } } } Path("regions.yml").write_text(yaml.dump(webvizmap), encoding="utf8") mocker.patch( "sys.argv", ["prtvol2csv", str(prtfile), "--yaml", "regions.yml", "--dir", "."], ) prtvol2csv.main() dframe = pd.read_csv("simulator_volume_fipnum.csv") pd.testing.assert_frame_equal( dframe[["FIPNUM", "REGION", "ZONE"]], pd.DataFrame( [ {"FIPNUM": 1, "REGION": "RegionA", "ZONE": "Upper"}, {"FIPNUM": 2, "REGION": "RegionB", "ZONE": "Upper"}, {"FIPNUM": 3, "REGION": "RegionA", "ZONE": "Middle"}, {"FIPNUM": 4, "REGION": "RegionB", "ZONE": "Middle"}, {"FIPNUM": 5, "REGION": "RegionA", "ZONE": "Lower"}, {"FIPNUM": 6, "REGION": "RegionB", "ZONE": "Lower"}, ] ), )
def test_prtvol2csv(tmpdir, mocker): """Test invocation from command line""" prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" tmpdir.chdir() with pytest.warns(FutureWarning, match="Output directories"): mocker.patch("sys.argv", ["prtvol2csv", "--debug", str(prtfile)]) prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_fipnum.csv") expected = pd.DataFrame.from_dict({ "FIPNUM": { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6 }, "STOIIP_OIL": { 0: 10656981.0, 1: 0.0, 2: 10720095.0, 3: 0.0, 4: 6976894.0, 5: 0.0, }, "ASSOCIATEDOIL_GAS": { 0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0 }, "STOIIP_TOTAL": { 0: 10656981.0, 1: 0.0, 2: 10720095.0, 3: 0.0, 4: 6976894.0, 5: 0.0, }, "WIIP_TOTAL": { 0: 59957809.0, 1: 77110073.0, 2: 56914143.0, 3: 72699051.0, 4: 37834559.0, 5: 38919965.0, }, "GIIP_GAS": { 0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0 }, "ASSOCIATEDGAS_OIL": { 0: 1960884420.0, 1: 0.0, 2: 1972497390.0, 3: 0.0, 4: 1283748490.0, 5: 0.0, }, "GIIP_TOTAL": { 0: 1960884420.0, 1: 0.0, 2: 1972497390.0, 3: 0.0, 4: 1283748490.0, 5: 0.0, }, "PORV_TOTAL": { 0: 78802733.0, 1: 79481140.0, 2: 75757104.0, 3: 74929403.0, 4: 50120783.0, 5: 40111683.0, }, "HCPV_OIL": { 0: 17000359.0, 1: 0.0, 2: 17096867.0, 3: 0.0, 4: 11127443.0, 5: 0.0, }, "WATPV_TOTAL": { 0: 61802374.0, 1: 79481140.0, 2: 58660238.0, 3: 74929403.0, 4: 38993340.0, 5: 40111683.0, }, "HCPV_GAS": { 0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0, 5: 0.0 }, "HCPV_TOTAL": { 0: 17000359.0, 1: 0.0, 2: 17096867.0, 3: 0.0, 4: 11127443.0, 5: 0.0, }, }) pd.testing.assert_frame_equal(dframe, expected)
def test_prtvol2csv_regions(tmpdir): """Test region support, getting data from yaml. The functionality of writing CSV data grouped by regions will be removed later from prtvol2csv. """ prtfile = TESTDATADIR / "2_R001_REEK-0.PRT" yamlexample = { "region2fipnum": { "RegionA": [1, 4, 6], "RegionB": [2, 5], "Totals": [1, 2, 3, 4, 5, 6], }, "zone2fipnum": { "Upper": [1, 2], "Mid": [3, 4], "Lower": [5, 6] }, } expected_dframe = pd.DataFrame.from_dict({ "REGION": { 0: "RegionA", 1: "RegionB", 2: "Totals" }, "STOIIP_OIL": { 0: 10656981.0, 1: 6976894.0, 2: 28353970.0 }, "ASSOCIATEDOIL_GAS": { 0: 0.0, 1: 0.0, 2: 0.0 }, "STOIIP_TOTAL": { 0: 10656981.0, 1: 6976894.0, 2: 28353970.0 }, "WATER_TOTAL": { 0: 171576825.0, 1: 114944632.0, 2: 343435600.0 }, "GIIP_GAS": { 0: 0.0, 1: 0.0, 2: 0.0 }, "ASSOCIATEDGAS_OIL": { 0: 1960884420.0, 1: 1283748490.0, 2: 5217130300.0 }, "GIIP_TOTAL": { 0: 1960884420.0, 1: 1283748490.0, 2: 5217130300.0 }, "PORV_TOTAL": { 0: 193843819.0, 1: 129601923.0, 2: 399202846.0 }, "HCPV_OIL": { 0: 17000359.0, 1: 11127443.0, 2: 45224669.0 }, "WATER_PORV": { 0: 176843460.0, 1: 118474480.0, 2: 353978178.0 }, "HCPV_GAS": { 0: 0.0, 1: 0.0, 2: 0.0 }, "HCPV_TOTAL": { 0: 17000359.0, 1: 11127443.0, 2: 45224669.0 }, "FIPNUM": { 0: "1 4 6", 1: "2 5", 2: "1 2 3 4 5 6" }, }) tmpdir.chdir() with open("regions.yml", "w") as reg_fh: reg_fh.write(yaml.dump(yamlexample)) result = subprocess.run( ["prtvol2csv", str(prtfile), "--regions", "regions.yml"], check=True, capture_output=True, ) output = result.stdout.decode() + result.stderr.decode() assert "FutureWarning" in output prtvol2csv.main() dframe = pd.read_csv("share/results/volumes/simulator_volume_region.csv") print("Computed:") print(dframe) print("Reference") print(expected_dframe) pd.testing.assert_frame_equal(dframe, expected_dframe)