Skip to content

Commit

Permalink
Add pytest for qc data for scalingfactor for SURFACE
Browse files Browse the repository at this point in the history
  • Loading branch information
oddvarlia committed Jan 4, 2024
1 parent fdea077 commit c289b19
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
55 changes: 16 additions & 39 deletions semeio/workflows/localisation/local_script_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
)
Expand Down Expand Up @@ -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]
Expand Down
30 changes: 30 additions & 0 deletions tests/workflows/localisation/reference_scaling_for_surface.irap
Original file line number Diff line number Diff line change
@@ -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
26 changes: 19 additions & 7 deletions tests/workflows/localisation/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# pylint: disable=missing-module-docstring
import itertools
import shutil
from pathlib import Path

import numpy as np
import pytest
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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",
},
},
Expand All @@ -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")
Expand Down Expand Up @@ -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": [
{
Expand Down

0 comments on commit c289b19

Please sign in to comment.