Skip to content

Commit

Permalink
Add test case for non-adaptive localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
oddvarlia committed Oct 20, 2023
1 parent d54ab46 commit deec4e2
Show file tree
Hide file tree
Showing 10 changed files with 1,102 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/jobs/localisation/example_case/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Directory for test case for non-adaptive localisation (LOCALISATION_JOB)
Main components:
ERT config file: sim_field.ert

The ERT model depends on:
scripts/sim_fields.py

ERT input:
GRID keyword: GRID.EGRID - can be generated by the script sim_fields.py
time_map.txt
localisation.wf


Other files:
randomseeds.txt - Not used by ERT, but by sim_fields.py
This file can be generated by sim_fields.py
UpscaledGrid.EGRID - Not used by ERT, but by sim_fields.py
This file can be generated by sim_fields.py


How to use the script sim_fields.py:
The main has some (global) variables turning on/off various options:
make_seed_file: To create the file randomseeds.txt
write_file_grid: To create the grid file GRID.EGRID
write_coarse_grid: To create the coarse grid file UpscaleGrid.EGRID
write_upscaled_to_file: Write upscaled field values to file for QC purpose. Not mandatory.
write_obs_pred_diff_field_file: Write field for the coarse grid containing difference of observed values minus predicted obs values.
extract_and_write_obs: Extract observations for the selected grid cells and write to ERT observation files. Generate local_config.yml

Typical workflow:
1. Generate seed file and the grid files by activating the relevant options mentioned above and run scripts/sim_fields.py
2. Create sub-directory observations and observations/obs_data
3. Edit the setting dictionaries in sim_fields.py to change the current settings if wanted.
3. Generate observation files and local_config.yml file by running scripts/sim_fields.py
4. Turn off the above mentioned options, but set write_upscaled_to_file active (and optionally write_obs_pred_diff_field_file)
5. Activate/not activate localisation in ERT config file (HOOK_WORKFLOW LOAD_WORKFLOW for localisation)
6. Now ready to run ERT.
7 changes: 7 additions & 0 deletions tests/jobs/localisation/example_case/init_files/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Directory where initial ensemble realisation is saved:
FieldParam.roff - The field parameter
Upscaled.roff - The upscaled field parameter (for QC purpose)
UpscaledObsField.roff - The upscaled field parameter used when
extracting observations (selected grid cells to be used as observables)
UpscaledConditionedCells.roff - A coarse grid parameter with all cells except the cells defined as observable
with a dummy value and the observable grid cells with the values used as observations.
1 change: 1 addition & 0 deletions tests/jobs/localisation/example_case/localisation.wf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOCALISATION_JOB local_config.yml
6 changes: 6 additions & 0 deletions tests/jobs/localisation/example_case/scripts/FM_SIM_FIELD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EXECUTABLE ./sim_fields.py

ARGLIST <ITERATION> <REALNUMBER>

STDERR sim_fields.stderr
STDOUT sim_fields.stdout
12 changes: 12 additions & 0 deletions tests/jobs/localisation/example_case/scripts/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Source code scripts:

sim_fields.py - This script is run from ERT config file as a FORWARD model.
FM_SIM_FIELD - ERT configuration of forward model SIM_FIELD
using the above mentioned script.

Scripts used in RMS project to load and visualize the realizations.
These are not needed to run the test and alternatives for visualizing the realizations exists (coviz, webviz?):
import_field_parameters.py
import_field_parameters_local.py
import_upscaled_field_parameters_local.py
import_upscaled_field_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""
Import field parameters into RMS (Must be included as python job
in RMS workflow and edited to fit your scratch directory)
"""
from pathlib import Path

import xtgeo

SCRATCH = "/scratch/fmu/olia/sim_field/"
# SCRATCH = "/scratch/fmu/olia/sim_field_local/"
CASE_NAME = "original"
# CASE_NAME = "local"


# pylint: disable=undefined-variable, bare-except
PRJ = project # noqa: 821

GRID_MODEL_NAME = "GRID"
FIELD_NAMES = [
"FieldParam",
]


def main():
"""
Import files with initial ensemble and updated fields into RMS project
"""
xtgeo.grid_from_roxar(PRJ, GRID_MODEL_NAME, PRJ.current_realisation)

path = Path(SCRATCH)
if not path.exists():
raise IOError(f"File path: {SCRATCH} does not exist. ")

real = PRJ.current_realisation
print("\n")
print(f"Realization: {real} ")
for name in FIELD_NAMES:
for iteration in [0, 3]:
print(f"Iteration: {iteration}")
if iteration == 0:
name_with_iter = name + "_" + CASE_NAME + "_" + str(iteration)
path = (
SCRATCH
+ "realization-"
+ str(real)
+ "/iter-"
+ str(iter)
+ "/init_files/"
)
file_name = path + name + ".roff"
print(f"File name: {file_name} ")

try:
property0 = xtgeo.gridproperty_from_file(file_name, "roff")
print(
f"Import property {property0.name} from file"
f" {file_name} into {name_with_iter} "
)
property0.to_roxar(
PRJ, GRID_MODEL_NAME, name_with_iter, realisation=real
)
except: # noqa: E722
print(f"Skip realization: {real} for iteration: {iteration} ")
elif iteration == 3:
name_with_iter = name + "_" + CASE_NAME + "_" + str(iteration)
path = (
SCRATCH
+ "realization-"
+ str(real)
+ "/iter-"
+ str(iteration)
+ "/"
)
file_name = path + name + ".roff"
print(f"File name: {file_name} ")

try:
property3 = xtgeo.gridproperty_from_file(file_name, "roff")
print(
f"Import property {property3.name} for iteration {iteration} "
f"from file {file_name} into {name_with_iter} "
)
property3.to_roxar(
PRJ, GRID_MODEL_NAME, name_with_iter, realisation=real
)
except: # noqa: E722
print(f"Skip realization: {real} for iteration: {iteration} ")
try:
diff_property = property0
diff_property.values = property3.values - property0.values
name_diff = name + "_" + CASE_NAME + "_diff"
print(
f"Calculate difference between iteration 3 and 0: {name_diff}"
)
diff_property.to_roxar(
PRJ, GRID_MODEL_NAME, name_diff, realisation=real
)
except: # noqa: E722
print(f"Skip difference for realisation: {real} ")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Import field parameters
"""
Import upscaled field parameters into RMS (Must be included as python job
in RMS workflow and edited to fit your scratch directory)
"""
from pathlib import Path

import xtgeo

# Set scratch file directory for the case and name of case (one short word)
SCRATCH = "/scratch/fmu/olia/sim_field/"
# SCRATCH = "/scratch/fmu/olia/sim_field_local/"
CASE_NAME = "original"
# CASE_NAME = "local"


# pylint: disable=undefined-variable, bare-except
PRJ = project # noqa: 821

GRID_MODEL_NAME = "UpscaleGrid"
FIELD_NAMES = [
"Upscaled",
]


def main():
"""
Import files with upscaled initial ensemble and updated fields into RMS
"""

xtgeo.grid_from_roxar(PRJ, GRID_MODEL_NAME, PRJ.current_realisation)

path = Path(SCRATCH)
if not path.exists():
raise IOError(f"File path: {SCRATCH} does not exist. ")

real = PRJ.current_realisation
print("\n")
print(f"Realization: {real} ")
for name in FIELD_NAMES:
for iteration in [0, 3]:
print(f"Iteration: {iteration}")
name_with_iter = name + "_" + CASE_NAME + "_" + str(iteration)
if iteration == 0:
path = (
SCRATCH
+ "realization-"
+ str(real)
+ "/iter-"
+ str(iteration)
+ "/init_files/"
)
file_name = path + name + ".roff"
print(f"File name: {file_name} ")
try:
property0 = xtgeo.gridproperty_from_file(file_name, "roff")
print(
f"Import property {property0.name} from file "
f"{file_name} into {name_with_iter} "
)
property0.to_roxar(
PRJ, GRID_MODEL_NAME, name_with_iter, realisation=real
)
except: # noqa: E722
print(f"Skip realization: {real} for iteration: {iteration} ")
elif iteration == 3:
path = (
SCRATCH
+ "realization-"
+ str(real)
+ "/iter-"
+ str(iteration)
+ "/"
)
file_name = path + name + ".roff"
print(f"File name: {file_name} ")
try:
property3 = xtgeo.gridproperty_from_file(file_name, "roff")
print(
f"Import property {property3.name} for iteration {iteration} "
f"from file {file_name} into {name_with_iter} "
)
property3.to_roxar(
PRJ, GRID_MODEL_NAME, name_with_iter, realisation=real
)
except: # noqa: E722
print(f"Skip realization: {real} for iteration: {iteration} ")
try:
diff_property = property0
diff_property.values = property3.values - property0.values
name_diff = name + "_" + CASE_NAME + "_diff"
print(
f"Calculate difference between iteration 3 and 0: {name_diff}"
)
diff_property.to_roxar(
PRJ, GRID_MODEL_NAME, name_diff, realisation=real
)
except: # noqa: E722
print(f"Skip difference for realisation: {real} ")


if __name__ == "__main__":
main()
Loading

0 comments on commit deec4e2

Please sign in to comment.