def test_rft_outside_grid_with_zone(tmp_path, caplog): """Test behaviour when points are outside the grid and we try to match with a zone (which can't be done when the point is outside the grid). """ os.chdir(tmp_path) dframe_dict = { "DATE": "2099-01-01", "WELL_NAME": "R-99", "MD": 4, "EAST": 1e10, "NORTH": 2, "TVD": 3, "PRESSURE": "100", "ERROR": 5, "ZONE": "Volon", } create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[dframe_dict]), "project": RMSMockedProject(), "gridname": "Simgrid", "zonename": "Zone", }) # The script only warns about the situation. assert "RFT points outside the grid" in caplog.text # Output files are still written with the data. GENDATA_RFT is responsible # for ignoring the observation as it will not be able to find the cell index for # it. assert (pd.read_csv("R-99.txt", sep=r"\s+", index_col=None, header=None).iloc[0].values == np.array( [1e10, 2, 4, 3, "Volon"], dtype="object")).all()
def test_zones(rftzone, tmpdir, caplog): """Test that a warning is emitted for RFT observations that in the RMS grid has ended up in a different zone than the one requested in the input""" tmpdir.chdir() dframe_dict = { "DATE": "2099-01-01", "WELL_NAME": "R-99", "MD": 1900, "EAST": 0, "NORTH": 0, "TVD": 1900, "PRESSURE": "100", "ERROR": 5, } dframe_dict.update({"ZONE": rftzone}) create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[dframe_dict]), "project": RMSMockedProject(), "gridname": "Simgrid", "zonename": "Zone", }) # The zone in the RMS grid is set to Volon in the mocked RMS project. if rftzone == "Volon": assert "Some points are in a different zone in the RMS grid" not in caplog.text else: assert "Some points are in a different zone in the RMS grid" in caplog.text
def test_main_mock_drogon(tmpdir): """Check that the code when executed on the Drogon case provides a predefined set of files (that has been manually verified)""" tmpdir.chdir() config = { "input_file": Path(__file__).parent / "rft_ertobs_data/input_table_drogon.csv", "exportdir": tmpdir, "project": RMSMockedProject(), "gridname": "Simgrid", "zonename": "Zone", "alias_file": Path(__file__).parent / "rft_ertobs_data/rms_eclipse.csv", "ecl_name": "ECLIPSE_WELL_NAME", "rms_name": "RMS_WELL_NAME", } create_rft_ertobs.main(config) expected_files_dir = Path( __file__).parent / "rft_ertobs_data" / "expected_files" for filename in (list(expected_files_dir.glob("R*obs")) + list(expected_files_dir.glob("R*.txt")) + ["well_date_rft.txt"]): assert Path(filename).is_file() pd.testing.assert_frame_equal( pd.read_csv(Path(filename).name, sep=r"\s+", index_col=None, header=None), pd.read_csv(filename, sep=r"\s+", index_col=None, header=None), check_dtype=False, ) assert Path("well_date_rft.txt").is_file()
def test_report_step_different_xyz(tmpdir): """Multiple dates for a well at different xyz. This requires a setup compatible with GENDATA_RFT in semeio and GEN_DATA in ERT. See also: https://github.com/equinor/semeio/blob/master/tests/jobs/rft/test_gendata_rft.py """ tmpdir.chdir() obs_1 = { "DATE": "2000-01-01", "WELL_NAME": "R-99", "MD": 1900, "EAST": 0, "NORTH": 0, "TVD": 1900, "PRESSURE": "100", # (here we also test that strings go well) "ERROR": 5, } obs_2 = obs_1.copy() obs_2.update({ "DATE": "2010-01-01", "PRESSURE": 90, "TVD": 1920, "MD": 1920 }) create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[obs_1, obs_2]), }) # Both points should be mentioned: pd.testing.assert_frame_equal( pd.read_csv(Path("R-99.txt"), sep=r"\s+", header=None), pd.DataFrame([[0, 0, 1900, 1900], [0, 0, 1920, 1920]]), ) # But there must be multiple observation files, and points with no data # must be padded with -1, and filename coupled with REPORT_STEP. pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_1.obs"), sep=r"\s+", header=None), pd.DataFrame([[100, 5.0], [-1, 0.0]]), ) pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_2.obs"), sep=r"\s+", header=None), pd.DataFrame([[-1, 0.0], [90, 5.0]]), ) # Check that we get REPORT_STEP 1 for the first date, and 2 for the second: pd.testing.assert_frame_equal( pd.read_csv(Path("well_date_rft.txt"), sep=r"\s+", header=None), pd.DataFrame([["R-99", 1, 1, 2000, 1], ["R-99", 1, 1, 2010, 2]]), )
def test_missing_dframe_data(data, expected_error, tmpdir): """Test error message when something is missing in the input dataframe""" tmpdir.chdir() dframe_dict = { "DATE": "2099-01-01", "WELL_NAME": "A-1", "MD": 4, "EAST": 1, "NORTH": 2, "TVD": 3, "PRESSURE": "100", "ERROR": 5, } dframe_dict.update(data) with pytest.raises(ValueError, match=expected_error): create_rft_ertobs.main( {"input_dframe": pd.DataFrame(data=[dframe_dict])})
def test_report_step_different_xyz(tmpdir): """Multiple dates for a well at different xyz""" tmpdir.chdir() obs_1 = { "DATE": "2000-01-01", "WELL_NAME": "R-99", "MD": 1900, "EAST": 0, "NORTH": 0, "TVD": 1900, "PRESSURE": "100", # (here we also test that strings go well) "ERROR": 5, } obs_2 = obs_1.copy() obs_2.update({ "DATE": "2010-01-01", "PRESSURE": 90, "TVD": 1920, "MD": 1920 }) create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[obs_1, obs_2]), }) # Both points should be mentioned: pd.testing.assert_frame_equal( pd.read_csv(Path("R-99.txt"), sep=r"\s+", header=None), pd.DataFrame([[0, 0, 1900, 1900], [0, 0, 1920, 1920]]), ) # But there must be multiple observation files, coupled with REPORT_STEP. pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_1.obs"), sep=r"\s+", header=None), pd.DataFrame([[100, 5]]), ) pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_2.obs"), sep=r"\s+", header=None), pd.DataFrame([[90, 5]]), ) # Check that we get REPORT_STEP 1 for the first date, and 2 for the second: pd.testing.assert_frame_equal( pd.read_csv(Path("well_date_rft.txt"), sep=r"\s+", header=None), pd.DataFrame([["R-99", 1, 1, 2000, 1], ["R-99", 1, 1, 2010, 2]]), )
def test_absolute_error(tmpdir): """Test that we can specify absolute_error in the config""" tmpdir.chdir() dframe_dict = { "DATE": "2099-01-01", "WELL_NAME": "A-1", "MD": 4, "EAST": 1, "NORTH": 2, "TVD": 3, "PRESSURE": "100", } create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[dframe_dict]), "absolute_error": 4 }) assert (pd.read_csv("A-1_1.obs", sep=r"\s+", index_col=None, header=None).iloc[0].values == [100, 4]).all()
def test_report_step_same_xyz(tmpdir): """For wells with RFT observations at multiple dates, the REPORT_STEP parameter must be set to something unique, the current code enumerates it from 1 and up. This test is with a measurement repeated in the same point""" tmpdir.chdir() obs_1 = { "DATE": "2000-01-01", "WELL_NAME": "R-99", "MD": 1900, "EAST": 0, "NORTH": 0, "TVD": 1900, "PRESSURE": "100", # (here we also test that strings go well) "ERROR": 5, } obs_2 = obs_1.copy() obs_2.update({"DATE": "2010-01-01", "PRESSURE": 90}) create_rft_ertobs.main({ "input_dframe": pd.DataFrame(data=[obs_1, obs_2]), }) # RFT at multiple dates but at the same point in the reservoir should only have # one point in the trajectory file: pd.testing.assert_frame_equal( pd.read_csv(Path("R-99.txt"), sep=r"\s+", header=None), pd.DataFrame([[0, 0, 1900, 1900]]), ) # But there must be multiple observation files, coupled with REPORT_STEP. print(pd.read_csv(Path("R-99_1.obs"), sep=r"\s+", header=None)) pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_1.obs"), sep=r"\s+", header=None), pd.DataFrame([[100, 5]]), ) pd.testing.assert_frame_equal( pd.read_csv(Path("R-99_2.obs"), sep=r"\s+", header=None), pd.DataFrame([[90, 5]]), ) # Check that we get REPORT_STEP 1 for the first date, and 2 for the second: pd.testing.assert_frame_equal( pd.read_csv(Path("well_date_rft.txt"), sep=r"\s+", header=None), pd.DataFrame([["R-99", 1, 1, 2000, 1], ["R-99", 1, 1, 2010, 2]]), )
def test_alternative_trajectory_name(tmpdir): """Test that we can use a different trajectory in RMS, but it has to be the same for all wells""" tmpdir.chdir() tmpdir.mkdir("exports") config = { "input_file": Path(__file__).parent / "rft_ertobs_data/input_table_drogon.csv", "exportdir": "exports", "project": RMSMockedProject(), "gridname": "Simgrid", "zonename": "Zone", "trajectory_name": "Imported trajectory", } create_rft_ertobs.main(config) assert not pd.read_csv(Path("exports") / "rft_ertobs.csv").empty # Check that we fail when the trajectory is wrongly named: config["trajectory_name"] = "fooo" with pytest.raises(KeyError): create_rft_ertobs.main(config)
def test_main_no_rms(tmpdir): """Test that if we have a full CSV file with all values we don't need the RMS project""" tmpdir.chdir() input_dframe = pd.DataFrame(data=[{ "DATE": "2099-01-01", "WELL_NAME": "A-1", "MD": 4, "EAST": 1, "NORTH": 2, "TVD": 3, "PRESSURE": 100, "ERROR": 5, }]) config = {"input_dframe": input_dframe} create_rft_ertobs.main(config) assert (pd.read_csv("A-1.txt", sep=r"\s+", index_col=None, header=None).iloc[0].values == [1, 2, 4, 3]).all() assert (pd.read_csv("A-1_1.obs", sep=r"\s+", index_col=None, header=None).iloc[0].values == [100, 5]).all() assert Path("well_date_rft.txt").read_text().strip() == "A-1 01 01 2099 1"
def test_rft_outside_grid(tmp_path, caplog): """Test behaviour when points are outside the grid.""" os.chdir(tmp_path) dframe_dict = { "DATE": "2099-01-01", "WELL_NAME": "R-99", "MD": 4, "EAST": 1e10, "NORTH": 2, "TVD": 3, "PRESSURE": "100", "ERROR": 5, "ZONE": "Volon", # Presence of this give a warning when grid is not supplied } create_rft_ertobs.main({"input_dframe": pd.DataFrame(data=[dframe_dict])}) assert "Cannot verify zones when no RMS project is provided" in caplog.text # No problems in this script. # These data points will be ignored later with GENDATA_RFT. assert (pd.read_csv("R-99.txt", sep=r"\s+", index_col=None, header=None).iloc[0].values == np.array( [1e10, 2, 4, 3, "Volon"], dtype="object")).all()