Grids with Properties¶
Python script¶
1"""Re-export 3D grids with properties."""
2
3from pathlib import Path
4
5import xtgeo
6from fmu.config import utilities as ut
7
8from fmu.dataio import ExportData
9
10CFG = ut.yaml_load("../../fmuconfig/output/global_variables.yml")
11
12OUT_DIR = Path("../output/grids")
13GRID_FILE = "gg"
14GRID_NAME = "geogrid"
15PROPS_TO_EXPORT = ["phit", "sw", "klogh", "facies"]
16
17
18def export_geogrid_geometry():
19 """Export geogrid geometry.
20
21 The geogrid must be exported first. Without exporting the geogrid first, we cannot
22 link the exported grid properties to it. The properties are linked by knowing the
23 file path the geogrid was exported to.
24 """
25
26 filename = OUT_DIR / f"{GRID_FILE}.roff"
27 grd = xtgeo.grid_from_file(filename)
28
29 export_data = ExportData(
30 config=CFG,
31 name=GRID_NAME,
32 content="depth",
33 unit="m",
34 workflow="rms structural model",
35 )
36
37 out_grid_path = export_data.export(grd)
38 print(f"Exported geogrid geometry to file {out_grid_path}")
39 return out_grid_path
40
41
42def export_geogrid_parameters(outgrid):
43 """Export grid properties associated with the geogrid.
44
45 By passing the path the geogrid was exported to we can link them to the geometry.
46 The total list of properties that will be exported are set from the variable
47 defined at the top.
48 """
49
50 for propname in PROPS_TO_EXPORT:
51 filename = OUT_DIR / f"{GRID_FILE}_{propname}.roff"
52 prop = xtgeo.gridproperty_from_file(filename)
53
54 export_data = ExportData(
55 config=CFG,
56 name=propname,
57 geometry=outgrid,
58 content="property",
59 content_metadata={"is_discrete": False},
60 workflow="rms property model",
61 )
62
63 out_path = export_data.export(prop)
64 print(f"Exported {propname} property geogrid to file {out_path}")
65
66
67def main():
68 print("\nExporting geogrids and metadata...")
69 out_grid_path = export_geogrid_geometry()
70
71 export_geogrid_parameters(out_grid_path)
72 print("Done exporting geogrids and metadata.")
73
74
75if __name__ == "__main__":
76 main()
Press + to see generated YAML file.
class: cpgrid
masterdata:
smda:
coordinate_system:
identifier: ST_WGS84_UTM37N_P32637
uuid: ad214d85-dac7-19da-e053-c918a4889309
country:
- identifier: Norway
uuid: ad214d85-8a1d-19da-e053-c918a4889309
discovery:
- short_identifier: DROGON
uuid: ad214d85-8a1d-19da-e053-c918a4889309
field:
- identifier: DROGON
uuid: 00000000-0000-0000-0000-000000000000
stratigraphic_column:
identifier: DROGON_2020
uuid: ad214d85-8a1d-19da-e053-c918a4889310
tracklog:
- datetime: '2026-06-05T10:36:51.254596Z'
event: created
user:
id: docs
sysinfo:
fmu-dataio:
version: 2.29.2.dev3+g7b3b17db7
operating_system:
hostname: build-33005878-project-703197-fmu-dataio
operating_system: Linux-7.0.0-1004-aws-x86_64-with-glibc2.35
release: 7.0.0-1004-aws
system: Linux
version: '#4-Ubuntu SMP PREEMPT Mon Apr 13 13:14:24 UTC 2026'
source: fmu
version: 0.22.0
$schema: https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.22.0/fmu_results.json
fmu:
case:
name: MyCase
user:
id: docs
uuid: de3299d8-4460-462e-a359-5b274d40164a
model:
name: ff
revision: 21.1.0.dev
context:
stage: realization
ensemble:
name: iter-0
uuid: c68ca28f-f0d5-c895-fe21-63a2d127bb9e
id: 0
iteration:
name: iter-0
uuid: c68ca28f-f0d5-c895-fe21-63a2d127bb9e
id: 0
workflow:
reference: rms structural model
realization:
id: 0
name: example_exports
uuid: fe066697-5ecf-1432-b881-5a5e7a993a67
entity:
uuid: 43f5c8fa-5f42-198f-912c-4e41be7b9e16
ert:
experiment:
id: 00000000-0000-0000-0000-000000000000
simulation_mode: test_run
ensemble:
name: iter-0
uuid: b027f225-c45d-477d-8f33-73695217ba14
id: 0
access:
asset:
name: Drogon
classification: internal
ssdl:
access_level: internal
rep_include: false
data:
content: depth
name: geogrid
alias: []
tagname: ''
stratigraphic: false
bbox:
xmin: 456063.6875
xmax: 467489.3438
ymin: 5926551.0
ymax: 5939441.0
zmin: 1554.2631
zmax: 2001.8425
format: roff
is_observation: false
is_prediction: true
layout: cornerpoint
offset: 0.0
spec:
nrow: 146
ncol: 92
nlay: 65
xshift: 0.0
yshift: 0.0
zshift: 0.0
xscale: 1.0
yscale: 1.0
zscale: 1.0
zonation:
- name: subgrid_0
min_layer_idx: 0
max_layer_idx: 18
- name: subgrid_1
min_layer_idx: 19
max_layer_idx: 47
- name: subgrid_2
min_layer_idx: 48
max_layer_idx: 61
undef_is_zero: false
unit: m
vertical_domain: depth
domain_reference: msl
file:
absolute_path: /home/docs/checkouts/readthedocs.org/user_builds/fmu-dataio/checkouts/latest/examples/example_exports/share/results/grids/geogrid.roff
relative_path: example_exports/share/results/grids/geogrid.roff
runpath_relative_path: share/results/grids/geogrid.roff
checksum_md5: 3f654dd7a2d5b267c6d9ff92db0a8c7b
size_bytes: 16540658
display:
name: geogrid
_preprocessed: false
class: cpgrid_property
masterdata:
smda:
coordinate_system:
identifier: ST_WGS84_UTM37N_P32637
uuid: ad214d85-dac7-19da-e053-c918a4889309
country:
- identifier: Norway
uuid: ad214d85-8a1d-19da-e053-c918a4889309
discovery:
- short_identifier: DROGON
uuid: ad214d85-8a1d-19da-e053-c918a4889309
field:
- identifier: DROGON
uuid: 00000000-0000-0000-0000-000000000000
stratigraphic_column:
identifier: DROGON_2020
uuid: ad214d85-8a1d-19da-e053-c918a4889310
tracklog:
- datetime: '2026-06-05T10:36:51.499698Z'
event: created
user:
id: docs
sysinfo:
fmu-dataio:
version: 2.29.2.dev3+g7b3b17db7
operating_system:
hostname: build-33005878-project-703197-fmu-dataio
operating_system: Linux-7.0.0-1004-aws-x86_64-with-glibc2.35
release: 7.0.0-1004-aws
system: Linux
version: '#4-Ubuntu SMP PREEMPT Mon Apr 13 13:14:24 UTC 2026'
source: fmu
version: 0.22.0
$schema: https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.22.0/fmu_results.json
fmu:
case:
name: MyCase
user:
id: docs
uuid: de3299d8-4460-462e-a359-5b274d40164a
model:
name: ff
revision: 21.1.0.dev
context:
stage: realization
ensemble:
name: iter-0
uuid: c68ca28f-f0d5-c895-fe21-63a2d127bb9e
id: 0
iteration:
name: iter-0
uuid: c68ca28f-f0d5-c895-fe21-63a2d127bb9e
id: 0
workflow:
reference: rms property model
realization:
id: 0
name: example_exports
uuid: fe066697-5ecf-1432-b881-5a5e7a993a67
entity:
uuid: 5b67251a-7eb1-874d-94fb-1dd2e9180758
ert:
experiment:
id: 00000000-0000-0000-0000-000000000000
simulation_mode: test_run
ensemble:
name: iter-0
uuid: b027f225-c45d-477d-8f33-73695217ba14
id: 0
access:
asset:
name: Drogon
classification: internal
ssdl:
access_level: internal
rep_include: false
data:
content: property
name: facies
alias: []
tagname: ''
stratigraphic: false
geometry:
name: geogrid
relative_path: example_exports/share/results/grids/geogrid.roff
format: roff
is_observation: false
is_prediction: true
layout: cornerpoint
offset: 0.0
spec:
nrow: 146
ncol: 92
nlay: 65
codenames:
'0': Floodplain
'1': Channel
'2': Crevasse
'5': Coal
'6': Calcite
'10': Offshore
'11': Lowershoreface
'12': Uppershoreface
value_statistics:
min: 0.0
max: 2000000000.0
mean: 500664317.6862807
std: 866408604.9172002
undef_is_zero: false
unit: ''
vertical_domain: depth
domain_reference: msl
property:
is_discrete: false
file:
absolute_path: /home/docs/checkouts/readthedocs.org/user_builds/fmu-dataio/checkouts/latest/examples/example_exports/share/results/grids/geogrid--facies.roff
relative_path: example_exports/share/results/grids/geogrid--facies.roff
runpath_relative_path: share/results/grids/geogrid--facies.roff
checksum_md5: 769985e42bcb3b21f2d501ff524a54d3
size_bytes: 3492813
display:
name: facies
_preprocessed: false