From def119ec7a22b5cf02ca7a9bb44dcf0696cc21f9 Mon Sep 17 00:00:00 2001 From: "Oddvar Lia (ST MSU GEO)" Date: Sun, 29 Oct 2023 14:14:06 +0100 Subject: [PATCH] modified output of scaling function for QC purpose --- .../localisation/local_script_lib.py | 67 +++++++++++++------ 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/semeio/workflows/localisation/local_script_lib.py b/semeio/workflows/localisation/local_script_lib.py index 74544e009..d4d6b5829 100644 --- a/semeio/workflows/localisation/local_script_lib.py +++ b/semeio/workflows/localisation/local_script_lib.py @@ -17,6 +17,8 @@ from ecl.util.geometry import Surface from ert.analysis.row_scaling import RowScaling from ert.config import Field, GenDataConfig, GenKwConfig, SurfaceConfig +from ert.field_utils import save_field +from ert.field_utils.field_file_format import FieldFileFormat from numpy import ma from semeio.workflows.localisation.localisation_debug_settings import ( @@ -932,35 +934,56 @@ def write_qc_parameter( grid, param_for_field, log_level=LogLevel.OFF, + file_format=FieldFileFormat.GRDECL, ): # pylint: disable=too-many-arguments + if param_for_field is None or field_scale is None: return - scaling_values = np.reshape( - param_for_field, (grid.getNX(), grid.getNY(), grid.getNZ()), "F" + # Write scaling parameter once per corr_name + if corr_name == cls.corr_name: + return + + cls.corr_name = corr_name + + # Need a parameter name <= 8 character long for GRDECL format + scaling_kw_name = "S_" + str(cls.scaling_param_number) + file_name_without_suffix = ( + cls.corr_name + "_" + node_name + "_" + scaling_kw_name ) - # Write scaling parameter once per corr_name - if corr_name != cls.corr_name: - cls.corr_name = corr_name - # Need a parameter name <= 8 character long - scaling_kw_name = "S_" + str(cls.scaling_param_number) - scaling_kw = grid.create_kw(scaling_values, scaling_kw_name, False) - filename = ( - cls.corr_name + "_" + node_name + "_" + scaling_kw_name + ".GRDECL" - ) - print( - "Write calculated scaling factor with name: " - f"{scaling_kw_name} to file: {filename}" - ) - debug_print( - f"Write calculated scaling factor with name: " - f"{scaling_kw_name} to file: {filename}", - LogLevel.LEVEL3, - log_level, + if file_format.upper() == FieldFileFormat.GRDECL: + scaling_values = np.reshape( + param_for_field, (grid.getNX(), grid.getNY(), grid.getNZ()), "F" ) + + scaling_kw = grid.create_kw(scaling_values, scaling_kw_name, False) + filename = file_name_without_suffix + ".GRDECL" + with cwrap.open(filename, "w") as file: grid.write_grdecl(scaling_kw, file) - # Increase parameter number to define unique parameter name - cls.scaling_param_number = cls.scaling_param_number + 1 + # For testing + name = scaling_kw_name + "_use_save_field" + save_field(scaling_values, name, filename, FieldFileFormat.GRDECL) + + elif file_format.upper() == FieldFileFormat.ROFF: + scaling_values = np.reshape( + param_for_field, (grid.getNX(), grid.getNY(), grid.getNZ()), "C" + ) + filename = file_name_without_suffix + ".roff" + save_field(scaling_values, scaling_kw_name, filename, FieldFileFormat.ROFF) + + print( + "Write calculated scaling factor with name: " + f"{scaling_kw_name} to file: {filename}" + ) + debug_print( + f"Write calculated scaling factor with name: " + f"{scaling_kw_name} to file: {filename}", + LogLevel.LEVEL3, + log_level, + ) + + # Increase parameter number to define unique parameter name + cls.scaling_param_number = cls.scaling_param_number + 1