diff --git a/tests/jobs/localisation/example_case/scripts/common_functions.py b/tests/jobs/localisation/example_case/scripts/common_functions.py index 03a0f4fef..d47b501a6 100644 --- a/tests/jobs/localisation/example_case/scripts/common_functions.py +++ b/tests/jobs/localisation/example_case/scripts/common_functions.py @@ -29,7 +29,7 @@ class GridSize: # xsize: float = 7500.0 # ysize: float = 7500.0 zsize: float = 50.0 - use_eclipse_grid_index_origo: bool = False + use_eclipse_grid_index_origo: bool = True @dataclass @@ -46,8 +46,9 @@ class Field: # pylint: disable=too-many-instance-attributes name: str = "FIELDPARAM" algorithm: str = "gstools" - initial_file_name: str = "init_files/FieldParam.roff" - updated_file_name: str = "FieldParam.roff" + file_format: str = "GRDECL" + initial_file_name: str = "init_files/FieldParam.grdecl" + updated_file_name: str = "FieldParam.grdecl" seed_file: str = "randomseeds.txt" variogram: str = "exponential" correlation_range: Tuple[float] = (3000.0, 1000.0, 2.0) @@ -90,7 +91,7 @@ class Observation: directory: str = "observations" file_name: str = "observations.obs" data_dir: str = "obs_data" - param_file_name: str = "init_files/UpscaledObsField.roff" + param_file_name: str = "init_files/UpscaledObsField.grdecl" rel_error: float = 0.10 min_abs_error: float = 0.01 # selected_grid_cells: Tuple[Tuple[int]] = ((5, 10, 1), (10, 5, 1)) @@ -135,7 +136,7 @@ class Settings: settings = Settings() -def generate_field_and_upscale(real_number): +def generate_field_and_upscale(real_number, grid): seed_file_name = settings.field.seed_file relative_std = settings.field.trend_relstd use_trend = settings.field.trend_use @@ -155,7 +156,7 @@ def generate_field_and_upscale(real_number): field3D = residual_field # Write field parameter for fine scale grid - field_object = export_field(field3D) + field_object = export_field(field3D, grid) field_values = field_object.values # Calculate upscaled values for selected coarse grid cells @@ -388,6 +389,12 @@ def simulate_field(start_seed): print(f"Simulate field with size: nx={nx},ny={ny} ") field1D = sim.simulate(variogram, nx, dx, ny, dy, nz, dz) field = field1D.reshape((nx, ny, nz), order="F") + if settings.grid_size.use_eclipse_grid_index_origo: + field_result = np.zeros((nx, ny, nz), dtype=np.float32) + j_indices = -np.arange(ny) + ny - 1 + field_result[:, j_indices, :] = field[:, :, :] + return field_result + return field @@ -459,34 +466,60 @@ def simulate_field_using_gstools(start_seed): return field -def export_field(field3D): +def read_grid(): + file_format = settings.field.file_format + filename = settings.field.grid_file_name + if file_format.upper() == "EGRID": + grid = xtgeo.grid_from_file(filename, fformat="egrid") + elif file_format.upper() == "ROFF": + grid = xtgeo.grid_from_file(filename, fformat="roff") + else: + raise IOError(f"Unknown grid file format: {file_format}") + return grid + + +def export_field(field3D, grid): """ Export initial realization of field to roff format """ - nx, ny, nz = settings.field.grid_dimension + # nx, ny, nz = settings.field.grid_dimension field_name = settings.field.name field_file_name = settings.field.initial_file_name + file_format = settings.field.file_format.upper() field_object = xtgeo.grid3d.GridProperty( - ncol=nx, nrow=ny, nlay=nz, values=field3D, discrete=False, name=field_name + grid, values=field3D, discrete=False, name=field_name ) print(f"Write field file: {field_file_name} ") - field_object.to_file(field_file_name, fformat="roff") + if file_format == "GRDECL": + field_object.to_file(field_file_name, fformat="grdecl", dtype="float32") + elif file_format == "ROFF": + field_object.to_file(field_file_name, fformat="roff") + else: + raise IOError(f"Unknown file format for fields: {file_format} ") return field_object -def read_field_from_file(): +def read_field_from_file(grid): """ Read field from roff formatted file and return xtgeo property object """ input_file_name = settings.field.updated_file_name name = settings.field.name - field_object = xtgeo.gridproperty_from_file( - input_file_name, fformat="roff", name=name - ) + file_format = settings.field.file_format.upper() + if file_format == "GRDECL": + field_object = xtgeo.grid3d.GridProperty( + input_file_name, fformat="grdecl", grid=grid, name=name + ) + elif file_format == "ROFF": + field_object = xtgeo.gridproperty_from_file( + input_file_name, fformat="roff", name=name + ) + else: + raise IOError(f"Unknown file format for fields: {file_format} ") return field_object diff --git a/tests/jobs/localisation/example_case/scripts/init_test_case.py b/tests/jobs/localisation/example_case/scripts/init_test_case.py index 573345360..9ee3ac761 100755 --- a/tests/jobs/localisation/example_case/scripts/init_test_case.py +++ b/tests/jobs/localisation/example_case/scripts/init_test_case.py @@ -238,7 +238,7 @@ def main(): generate_seed_file() # Create grid for the field parameter - create_grid() + grid = create_grid() # Create coarse grid to be used in QC of upscaled field parameter create_upscaled_grid() @@ -251,7 +251,7 @@ def main(): # Simulate field (with trend) real_number = 0 - upscaled_values = generate_field_and_upscale(real_number) + upscaled_values = generate_field_and_upscale(real_number, grid) # Create observations by extracting from existing upscaled field write_gen_obs(upscaled_values) diff --git a/tests/jobs/localisation/example_case/scripts/sim_fields.py b/tests/jobs/localisation/example_case/scripts/sim_fields.py index 4f65d6683..7a38b2a2c 100755 --- a/tests/jobs/localisation/example_case/scripts/sim_fields.py +++ b/tests/jobs/localisation/example_case/scripts/sim_fields.py @@ -12,6 +12,7 @@ get_cell_indices, get_nobs, read_field_from_file, + read_grid, read_obs_field_from_file, read_upscaled_field_from_file, settings, @@ -83,14 +84,15 @@ def main(iteration, real_number): # NOTE: Both the fine scale grid with simulated field values # and the coarse grid with upscaled values must have Eclipse grid index origin + grid = read_grid() if iteration == 0: print(f"Generate new field parameter realization:{real_number} ") # Simulate field (with trend) - upscaled_values = generate_field_and_upscale(real_number) + upscaled_values = generate_field_and_upscale(real_number, grid) else: print(f"Import updated field parameter realization: {real_number} ") - field_object = read_field_from_file() + field_object = read_field_from_file(grid) field_values = field_object.values # Calculate upscaled values for selected coarse grid cells