From c289b1922e6b6a1bb049271dbbe34d2a2baaf137 Mon Sep 17 00:00:00 2001 From: "Oddvar Lia (ST MSU GEO)" Date: Tue, 2 Jan 2024 14:27:22 +0100 Subject: [PATCH] Add pytest for qc data for scalingfactor for SURFACE --- .../localisation/local_script_lib.py | 55 ++++++------------- .../reference_scaling_for_surface.irap | 30 ++++++++++ .../localisation/test_integration.py | 26 ++++++--- 3 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 tests/workflows/localisation/reference_scaling_for_surface.irap diff --git a/semeio/workflows/localisation/local_script_lib.py b/semeio/workflows/localisation/local_script_lib.py index 3faae5143..a6da7373d 100644 --- a/semeio/workflows/localisation/local_script_lib.py +++ b/semeio/workflows/localisation/local_script_lib.py @@ -316,7 +316,7 @@ def write_qc_parameter_field( field_scale: bool, grid: Grid, param_for_field: ma.MaskedArray, - log_level=LogLevel.OFF, + log_level: LogLevel = LogLevel.OFF, ) -> Tuple[str, int]: # pylint: disable=too-many-arguments if param_for_field is None or field_scale is None: @@ -1078,15 +1078,6 @@ def add_ministeps( param_for_field, user_config.log_level, ) - - # write_qc_parameter_field( - # node_name, - # corr_spec.name, - # corr_spec.field_scale, - # grid_for_field, - # param_for_field, - # user_config.log_level, - # ) update_step["row_scaling_parameters"].append( [node_name, row_scaling] ) @@ -1185,35 +1176,21 @@ def add_ministeps( f"Scaling method: {corr_spec.surface_scale.method} " "is not implemented" ) - # Inactivate this temporarily untill pytest for this is ready - can_write_qc_data_for_surface = False - if ( - user_config.write_scaling_factors - and can_write_qc_data_for_surface - ): - # ScalingValues.write_qc_parameter_surface( - # write_qc_parameter_surface( - # node_name, - # corr_spec.name, - # corr_spec.surface_scale, - # corr_spec.surface_scale.surface_file, - # param_for_surface, - # user_config.log_level, - # ) - ( - corr_name_using_surface, - number_of_scaling_parameter_of_type_surface, - ) = write_qc_parameter_surface( - # pylint: disable=too-many-locals - node_name, - corr_name_using_surface, - corr_spec.name, - number_of_scaling_parameter_of_type_surface, - corr_spec.surface_scale, - corr_spec.surface_scale.surface_file, - param_for_surface, - user_config.log_level, - ) + + ( + corr_name_using_surface, + number_of_scaling_parameter_of_type_surface, + ) = write_qc_parameter_surface( + # pylint: disable=too-many-locals + node_name, + corr_name_using_surface, + corr_spec.name, + number_of_scaling_parameter_of_type_surface, + corr_spec.surface_scale, + corr_spec.surface_scale.surface_file, + param_for_surface, + user_config.log_level, + ) update_step["row_scaling_parameters"].append( [node_name, row_scaling] diff --git a/tests/workflows/localisation/reference_scaling_for_surface.irap b/tests/workflows/localisation/reference_scaling_for_surface.irap new file mode 100644 index 000000000..fba1f4334 --- /dev/null +++ b/tests/workflows/localisation/reference_scaling_for_surface.irap @@ -0,0 +1,30 @@ +-996 +10 + 50.0000 + 50.0000 + 0.0000 + 450.0000 + 0.0000 + 450.0000 +10 + 0.0000 + 0.0000 + 0.0000 +0 0 0 0 0 0 0 + 0.2967 0.3606 0.3772 0.3396 0.2632 0.1755 + 0.1008 0.0498 0.0212 0.0078 0.3606 0.4795 + 0.5488 0.5406 0.4584 0.3345 0.2101 0.1136 + 0.0529 0.0212 0.3772 0.5488 0.6873 0.7408 + 0.6873 0.5488 0.3772 0.2231 0.1136 0.0498 + 0.3396 0.5406 0.7408 0.8737 0.8869 0.7749 + 0.5827 0.3772 0.2101 0.1008 0.2632 0.4584 + 0.6873 0.8869 0.9851 0.9418 0.7749 0.5488 + 0.3345 0.1755 0.1755 0.3345 0.5488 0.7749 + 0.9418 0.9851 0.8869 0.6873 0.4584 0.2632 + 0.1008 0.2101 0.3772 0.5827 0.7749 0.8869 + 0.8737 0.7408 0.5406 0.3396 0.0498 0.1136 + 0.2231 0.3772 0.5488 0.6873 0.7408 0.6873 + 0.5488 0.3772 0.0212 0.0529 0.1136 0.2101 + 0.3345 0.4584 0.5406 0.5488 0.4795 0.3606 + 0.0078 0.0212 0.0498 0.1008 0.1755 0.2632 + 0.3396 0.3772 0.3606 0.2967 diff --git a/tests/workflows/localisation/test_integration.py b/tests/workflows/localisation/test_integration.py index f08d06be6..340a38cb4 100644 --- a/tests/workflows/localisation/test_integration.py +++ b/tests/workflows/localisation/test_integration.py @@ -1,4 +1,7 @@ +# pylint: disable=missing-module-docstring import itertools +import shutil +from pathlib import Path import numpy as np import pytest @@ -7,10 +10,10 @@ from ert import LibresFacade from ert.storage import open_storage from xtgeo.surface.regular_surface import RegularSurface - +from resdata.geometry import Surface from semeio.workflows.localisation.local_config_script import LocalisationConfigJob -# pylint: disable=invalid-name +# pylint: disable=invalid-name, missing-function-docstring @pytest.mark.parametrize( @@ -85,6 +88,7 @@ def test_localisation_surf(): xori = 0.0 yori = 0.0 values = np.zeros(nrow * ncol) + print("Write files:") for n in range(nreal): filename = "surf" + str(n) + ".txt" delta = 0.1 @@ -102,6 +106,7 @@ def test_localisation_surf(): rotation=rotation, values=values, ) + print(f" {filename} ") surface.to_file(filename, fformat="irap_ascii") ert = LibresFacade.from_config_file("poly.ert") @@ -119,10 +124,10 @@ def test_localisation_surf(): }, "surface_scale": { "method": "gaussian_decay", - "main_range": 1700, - "perp_range": 850, - "azimuth": 200, - "ref_point": [250, 250], + "main_range": 500, + "perp_range": 250, + "azimuth": 45, + "ref_point": [225, 225], "surface_file": "surf0.txt", }, }, @@ -140,6 +145,13 @@ def test_localisation_surf(): ), "local_config.yaml", ) + # Check that QC output for scaling factor is equal to the reference case + filename = "CORR1_PARAM_SURF_A_map.irap" + reference_filename = "reference_scaling_for_surface.irap" + shutil.copy(Path(__file__).parent / reference_filename, reference_filename) + qc_object = Surface(filename) + qc_reference_object = Surface(reference_filename) + assert qc_object == qc_reference_object @pytest.mark.usefixtures("setup_poly_ert") @@ -180,7 +192,7 @@ def test_localisation_surf_const(): ert = LibresFacade.from_config_file("poly.ert") config = { - "write_scaling_factors": True, + "write_scaling_factors": False, "log_level": 3, "correlations": [ {