Skip to content

Commit c174caf

Browse files
authored
Added new keyword to define geomodel name (#801)
* Added new keyword to define geomodel name * update after review
1 parent f19cbac commit c174caf

3 files changed

Lines changed: 71 additions & 17 deletions

File tree

src/subscript/field_statistics/field_statistics.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
The script reads ensembles of realizations from scratch disk from
3838
<RUN_PATH> directory::
3939
40-
share/results/grids/geogrid--<propertyname>.roff.
40+
share/results/grids/<geogridname>--<propertyname>.roff.
4141
4242
Optionally also temporary field parameters coming from APS or petrophysical
4343
field parameters can be used to calculate mean and standard deviations.
@@ -172,9 +172,13 @@
172172
173173
# Specify which geogrid fields to use
174174
# Geogrid fields are typically found in:
175-
# <RUN_PATH>/share/results/grids/geogrid--<property-name>.roff
175+
# <RUN_PATH>/share/results/grids/<geogridname>--<property-name>.roff
176176
# Optional keyword
177177
geogrid_fields:
178+
# Prefix (name of geogrid) to be used for field parameters related to the
179+
# geogrid.
180+
geogrid_name: "geogrid"
181+
178182
# Selected set of zone names to use in calculations of statistics.
179183
# Must be one or more of the defined zones.
180184
# Require at least one zone to be selected.
@@ -201,7 +205,7 @@
201205
# For each zone specify which discrete parameter to use to calculate
202206
# facies probability estimates.
203207
# Possible names are those found in the
204-
# share/results/grids/geogrid--<name>.roff
208+
# share/results/grids/<geogridname>--<name>.roff
205209
# files that are of discrete type.
206210
# This key can be omitted or some of the lines specifying parameters
207211
# for a zone if you don't want to use it.
@@ -213,7 +217,7 @@
213217
# For each zone specify which continuous parameter to use to
214218
# calculate estimate of mean and stdev over ensemble.
215219
# Possible names are those found in the
216-
# share/results/grids/geogrid--<name>.roff
220+
# share/results/grids/<geogridname>--<name>.roff
217221
# files that are of continuous type
218222
# This key can be omitted or some of the lines specifying
219223
# parameters for a zone if you don't want to use it.
@@ -608,17 +612,20 @@ def read_ensemble_realization(
608612
iter_number,
609613
property_param_name,
610614
zone_code_names,
615+
geogrid_name,
611616
):
612617
realization_path = Path(f"realization-{realization_number}/iter-{iter_number}")
613-
grid_path = Path("share/results/grids/geogrid.roff")
618+
grid_path = Path("share/results/grids/" + geogrid_name + ".roff")
614619
file_path_grid = Path(ensemble_path) / realization_path / grid_path
615620
if file_path_grid.exists():
616621
grid = xtgeo.grid_from_file(file_path_grid, fformat="roff")
617622
subgrids = grid.subgrids if grid.subgrids else None
618623
else:
619624
return None, None, None
620625

621-
property_path = Path(f"share/results/grids/geogrid--{property_param_name}.roff")
626+
property_path = Path(
627+
"share/results/grids/" + geogrid_name + f"--{property_param_name}.roff"
628+
)
622629
file_path_property = Path(ensemble_path) / realization_path / property_path
623630
property_param = xtgeo.gridproperty_from_file(file_path_property, fformat="roff")
624631

@@ -635,9 +642,10 @@ def read_geogrid_realization(
635642
realization_number,
636643
iter_number,
637644
zone_code_names,
645+
geogrid_name,
638646
):
639647
realization_path = Path(f"realization-{realization_number}/iter-{iter_number}")
640-
grid_path = Path("share/results/grids/geogrid.roff")
648+
grid_path = Path("share/results/grids/" + geogrid_name + ".roff")
641649
file_path_grid = Path(ensemble_path) / realization_path / grid_path
642650
if file_path_grid.exists():
643651
grid = xtgeo.grid_from_file(file_path_grid, fformat="roff")
@@ -778,6 +786,7 @@ def write_mean_stdev_nactive(
778786
result_path,
779787
ens_path,
780788
zone_code_names,
789+
geogrid_name,
781790
copy_to_geogrid_realization=False,
782791
):
783792
output_path = result_path
@@ -826,7 +835,11 @@ def write_mean_stdev_nactive(
826835
# Use realization number 0
827836
real_number = 0
828837
geogrid_dimensions, geogrid_subgrids = read_geogrid_realization(
829-
ens_path, real_number, iter_number, zone_code_names
838+
ens_path,
839+
real_number,
840+
iter_number,
841+
zone_code_names,
842+
geogrid_name,
830843
)
831844

832845
ertbox_to_geogrid_statistics(
@@ -839,6 +852,7 @@ def write_mean_stdev_nactive(
839852
ertbox_dims,
840853
conformity,
841854
ens_path,
855+
geogrid_name,
842856
param_name=param_name,
843857
)
844858

@@ -852,6 +866,7 @@ def write_mean_stdev_nactive(
852866
ertbox_dims,
853867
conformity,
854868
ens_path,
869+
geogrid_name,
855870
param_name=param_name,
856871
)
857872

@@ -875,13 +890,14 @@ def ertbox_to_geogrid_statistics(
875890
ertbox_dimensions,
876891
zone_conformity,
877892
ens_path,
893+
geogrid_name,
878894
param_name=None,
879895
facies_name=None,
880896
):
881897
if param_name:
882-
geogrid_stat_name = f"geogrid--{statistics_name}_{param_name}"
898+
geogrid_stat_name = f"{geogrid_name}--{statistics_name}_{param_name}"
883899
if facies_name:
884-
geogrid_stat_name = f"geogrid--{statistics_name}_{facies_name}"
900+
geogrid_stat_name = f"{geogrid_name}--{statistics_name}_{facies_name}"
885901
assert (param_name is not None) or (facies_name is not None)
886902
geogrid_stat_file_name = (
887903
ens_path
@@ -930,6 +946,7 @@ def write_fraction_nactive(
930946
result_path,
931947
ens_path,
932948
zone_code_names,
949+
geogrid_name,
933950
ncount_active_values=None,
934951
copy_to_geogrid_realization=False,
935952
):
@@ -979,7 +996,11 @@ def write_fraction_nactive(
979996
# Use realization number 0
980997
real_number = 0
981998
geogrid_dimensions, geogrid_subgrids = read_geogrid_realization(
982-
ens_path, real_number, iter_number, zone_code_names
999+
ens_path,
1000+
real_number,
1001+
iter_number,
1002+
zone_code_names,
1003+
geogrid_name,
9831004
)
9841005
ertbox_to_geogrid_statistics(
9851006
"prob",
@@ -991,6 +1012,7 @@ def write_fraction_nactive(
9911012
ertbox_dimensions,
9921013
conformity,
9931014
ens_path,
1015+
geogrid_name,
9941016
facies_name=facies_name,
9951017
)
9961018

@@ -1042,6 +1064,14 @@ def get_specifications(input_dict, ertbox_size, ert_config_path):
10421064
use_geogrid_fields = True
10431065
geogrid_fields_dict = input_dict["geogrid_fields"]
10441066

1067+
key = "geogrid_name"
1068+
if key in geogrid_fields_dict:
1069+
geogrid_name = geogrid_fields_dict[key]
1070+
geogrid_name = geogrid_name.strip()
1071+
else:
1072+
# Set default
1073+
geogrid_name = "geogrid"
1074+
10451075
key = "zone_code_names"
10461076
if key in geogrid_fields_dict:
10471077
zone_code_names = geogrid_fields_dict[key]
@@ -1119,6 +1149,7 @@ def get_specifications(input_dict, ertbox_size, ert_config_path):
11191149
zone_names_used,
11201150
zone_conformity,
11211151
zone_code_names,
1152+
geogrid_name,
11221153
param_name_dict,
11231154
disc_param_name_dict,
11241155
init_path,
@@ -1254,6 +1285,7 @@ def calc_stats(
12541285
zone_names,
12551286
zone_conformity,
12561287
zone_code_names,
1288+
geogrid_name,
12571289
param_name_dict,
12581290
disc_param_name_dict,
12591291
_,
@@ -1290,6 +1322,7 @@ def calc_stats(
12901322
iter_number,
12911323
param_name,
12921324
zone_code_names,
1325+
geogrid_name,
12931326
)
12941327
)
12951328
if grid_dimensions is None:
@@ -1342,6 +1375,7 @@ def calc_stats(
13421375
result_path,
13431376
ens_path,
13441377
zone_code_names,
1378+
geogrid_name,
13451379
copy_to_geogrid_realization=copy_to_geogrid_realization,
13461380
)
13471381
has_written_nactive = True
@@ -1377,6 +1411,7 @@ def calc_stats(
13771411
iter_number,
13781412
param_name,
13791413
zone_code_names,
1414+
geogrid_name,
13801415
)
13811416
)
13821417

@@ -1439,6 +1474,7 @@ def calc_stats(
14391474
result_path,
14401475
ens_path,
14411476
zone_code_names,
1477+
geogrid_name,
14421478
ncount_active_values=sum_active,
14431479
copy_to_geogrid_realization=copy_to_geogrid_realization,
14441480
)
@@ -1453,6 +1489,7 @@ def calc_stats(
14531489
result_path,
14541490
ens_path,
14551491
zone_code_names,
1492+
geogrid_name,
14561493
copy_to_geogrid_realization=copy_to_geogrid_realization,
14571494
)
14581495
txt4 = f" Sum facies volume fraction: {sum_fraction}"

tests/test_field_statistics.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"iterations": [0, 3],
3636
"use_population_stdev": False,
3737
"geogrid_fields": {
38+
"geogrid_name": "my_geogrid",
3839
"use_zones": ["A", "B", "C"],
3940
"zone_code_names": {
4041
1: "A",
@@ -74,7 +75,7 @@ def make_box_grid(dimensions, grid_name, result_path):
7475
grid.to_file(filename_egrid, fformat="egrid")
7576

7677

77-
def make_file_names(ensemble_path, iter_number, real_number, param_name):
78+
def make_file_names(ensemble_path, iter_number, real_number, param_name, geogrid_name):
7879
filedir = ensemble_path / Path("realization-" + str(real_number))
7980
if not filedir.exists():
8081
filedir.mkdir()
@@ -90,9 +91,9 @@ def make_file_names(ensemble_path, iter_number, real_number, param_name):
9091
filedir = filedir / Path("grids")
9192
if not filedir.exists():
9293
filedir.mkdir()
93-
filename = filedir / Path("geogrid--" + param_name + ".roff")
94-
filename_active = filedir / Path("geogrid--active.roff")
95-
filename_grid = filedir / Path("geogrid.roff")
94+
filename = filedir / Path(f"{geogrid_name}--" + param_name + ".roff")
95+
filename_active = filedir / Path(f"{geogrid_name}--active.roff")
96+
filename_grid = filedir / Path(f"{geogrid_name}.roff")
9697
return filename, filename_active, filename_grid
9798

9899

@@ -110,6 +111,7 @@ def make_ensemble_test_data(
110111

111112
iteration_list = [0, 3]
112113
zone_code_names = config_dict["geogrid_fields"]["zone_code_names"]
114+
geogrid_name = config_dict["geogrid_fields"]["geogrid_name"]
113115
discrete_param_name_per_zone = config_dict["geogrid_fields"][
114116
"discrete_property_param_per_zone"
115117
]
@@ -138,7 +140,11 @@ def make_ensemble_test_data(
138140
(nx, ny, 3 * nz_ertbox), dtype=np.float32
139141
)
140142
filename, filename_active, filename_grid = make_file_names(
141-
ensemble_path, iter_number, real_number, param_name
143+
ensemble_path,
144+
iter_number,
145+
real_number,
146+
param_name,
147+
geogrid_name,
142148
)
143149
values = assign_values_continuous_param(
144150
nz_ertbox,
@@ -195,7 +201,11 @@ def make_ensemble_test_data(
195201
(nx, ny, 3 * nz_ertbox), dtype=np.uint8
196202
)
197203
filename, filename_active, filename_grid = make_file_names(
198-
ensemble_path, iter_number, real_number, param_name
204+
ensemble_path,
205+
iter_number,
206+
real_number,
207+
param_name,
208+
geogrid_name,
199209
)
200210

201211
values, code_names = assign_values_discrete_param(
@@ -683,6 +693,7 @@ def test_check_use_zones_errors(zone_code_names, zone_names, expected_error):
683693
"nreal": 10,
684694
"iterations": [0, 3],
685695
"geogrid_fields": {
696+
"geogrid_name": "my_geogrid",
686697
"use_zones": ["A", "B", "C"],
687698
"zone_code_names": {
688699
1: "A",
@@ -713,6 +724,7 @@ def test_check_use_zones_errors(zone_code_names, zone_names, expected_error):
713724
"nreal": 10,
714725
"iterations": [0],
715726
"geogrid_fields": {
727+
"geogrid_name": "geogrid",
716728
"zone_code_names": {
717729
1: "A",
718730
2: "B",
@@ -736,6 +748,7 @@ def test_check_use_zones_errors(zone_code_names, zone_names, expected_error):
736748
"nreal": 10,
737749
"iterations": [0],
738750
"geogrid_fields": {
751+
"geogrid_name": "geogrid",
739752
"zone_code_names": {
740753
1: "A",
741754
2: "B",
@@ -761,6 +774,7 @@ def test_check_use_zones_errors(zone_code_names, zone_names, expected_error):
761774
"nreal": 10,
762775
"iterations": [0],
763776
"geogrid_fields": {
777+
"geogrid_name": "geogrid",
764778
"zone_code_names": {
765779
1: "A",
766780
2: "B",
@@ -785,6 +799,7 @@ def test_check_use_zones_errors(zone_code_names, zone_names, expected_error):
785799
"nreal": 10,
786800
"iterations": [0],
787801
"geogrid_fields": {
802+
"geogrid_name": "geogrid",
788803
"zone_code_names": {
789804
1: "A",
790805
2: "B",
@@ -884,6 +899,7 @@ def test_get_specification(
884899
zone_names,
885900
zone_conformity,
886901
zone_code_names,
902+
geogrid_name,
887903
param_name_dict,
888904
disc_param_name_dict,
889905
_,

tests/testdata_field_statistics/config_example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ field_stat:
22
nreal: 10
33
iterations: [0, 3]
44
geogrid_fields:
5+
geogrid_name: "my_geogrid"
56
use_zones: ["A", "B", "C"]
67
zone_code_names:
78
1: "A"

0 commit comments

Comments
 (0)