From 2883b9e632d9f3181e68335702b4b1cb1529d027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Steinkopf=20S=C3=B8hoel?= <49289030+HakonSohoel@users.noreply.github.com> Date: Thu, 3 Sep 2026 10:44:31 +0200 Subject: [PATCH] Skip RFT approximation for points outside the grid (#14277) Observations whose location falls outside the grid have well_connection_cell and well_connection_cell_center None. Attempting to calculate an approximated response for a point with coordinates None would raise a TypeError. Since responses and observations are matched on well_connection_cell, an approximated response would not be matched to any observation. Approximation is therefore skipped for such points. (cherry picked from commit 03e5ba60d0488f5826d78600064797579a5f25c6) --- src/ert/config/rft_config.py | 10 +++++++ .../ert/unit_tests/config/test_rft_config.py | 26 +++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/ert/config/rft_config.py b/src/ert/config/rft_config.py index d64c2946e4a..1c6b2ce44b1 100644 --- a/src/ert/config/rft_config.py +++ b/src/ert/config/rft_config.py @@ -538,6 +538,16 @@ def approximate_missing_rft_responses( how="anti", ) + # Only attempt to approximate missing values for observations that have a + # well connection cell since currently observations and responses are matched + # based on well connection cell. + # Responses could be approximated for observations without a + # well connection cell based on its utm coordinates, however this will require + # a fallback mechanism to match responses to observations when + # the well_connection_cell is None. + observations_with_missing_response = observations_with_missing_response.filter( + pl.col("well_connection_cell").is_not_null() + ) if observations_with_missing_response.is_empty(): return responses diff --git a/tests/ert/unit_tests/config/test_rft_config.py b/tests/ert/unit_tests/config/test_rft_config.py index 2c06938d288..c3074ab215d 100644 --- a/tests/ert/unit_tests/config/test_rft_config.py +++ b/tests/ert/unit_tests/config/test_rft_config.py @@ -1151,8 +1151,8 @@ def _rft_observation_for_approximation( east: float = 5.0, north: float = 5.0, tvd: float = 15.0, - well_connection_cell: tuple[int, int, int] = (1, 1, 3), - well_connection_cell_center: tuple[float, float, float] = (5.0, 5.0, 25.0), + well_connection_cell: tuple[int, int, int] | None = (1, 1, 3), + well_connection_cell_center: tuple[float, float, float] | None = (5.0, 5.0, 25.0), zone: str | None = "zone1", ) -> pl.DataFrame: def _make_dataframe(prop: str) -> pl.DataFrame: @@ -1324,6 +1324,16 @@ def _expected_approximated_values( "available. I.e. no zonemap file." ), ), + pytest.param( + _rft_responses_for_approximation(), + _rft_observation_for_approximation( + tvd=25.0, + well_connection_cell=None, # <= observation is outside the grid + well_connection_cell_center=None, # <= observation is outside the grid + ), + None, + id=("Test that approximation is not done when observation is outside grid"), + ), ], ) def test_rft_value_approximation( @@ -1335,9 +1345,15 @@ def test_rft_value_approximation( responses=rft_responses, observations=rft_observations ) - approximated_values = responses_with_approximations.filter( - pl.col("well_connection_cell") == [1, 1, 3] # The cell of the observation - ).collect() + # rechunk before the anti-join: polars raises a PanicException on multi-chunk + # frames when a join on Array columns yields an empty result. + # See: https://github.com/pola-rs/polars/issues/29093 + rft_responses = rft_responses.collect() + approximated_values = ( + responses_with_approximations.collect() + .rechunk() + .join(rft_responses, on=rft_responses.columns, how="anti") + ) assert dict( zip(