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-12T11:12:09.822351Z'
  event: created
  user:
    id: docs
  sysinfo:
    fmu-dataio:
      version: 0.1.dev50+gea56c3632
    operating_system:
      hostname: build-33110835-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.23.0
$schema: https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.23.0/fmu_results.json
fmu:
  case:
    name: MyCase
    user:
      id: docs
    uuid: 12bd72dd-f693-44c0-8424-0728311476dd
  model:
    name: ff
    revision: 21.1.0.dev
  context:
    stage: realization
  ensemble:
    name: iter-0
    uuid: 68849707-5e49-646f-b8c8-f1dc03981644
    id: 0
  iteration:
    name: iter-0
    uuid: 68849707-5e49-646f-b8c8-f1dc03981644
    id: 0
  workflow:
    reference: rms structural model
  realization:
    id: 0
    name: example_exports
    uuid: fc56794e-87ac-c7b5-fdc8-f4ca5be6e752
  entity:
    uuid: 5c7bf082-799c-474e-8fca-7d6844a09e92
  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/stable/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: bb20a56a4b2dfbf8f26092b20b829b0d
  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-12T11:12:10.025464Z'
  event: created
  user:
    id: docs
  sysinfo:
    fmu-dataio:
      version: 0.1.dev50+gea56c3632
    operating_system:
      hostname: build-33110835-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.23.0
$schema: https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.23.0/fmu_results.json
fmu:
  case:
    name: MyCase
    user:
      id: docs
    uuid: 12bd72dd-f693-44c0-8424-0728311476dd
  model:
    name: ff
    revision: 21.1.0.dev
  context:
    stage: realization
  ensemble:
    name: iter-0
    uuid: 68849707-5e49-646f-b8c8-f1dc03981644
    id: 0
  iteration:
    name: iter-0
    uuid: 68849707-5e49-646f-b8c8-f1dc03981644
    id: 0
  workflow:
    reference: rms property model
  realization:
    id: 0
    name: example_exports
    uuid: fc56794e-87ac-c7b5-fdc8-f4ca5be6e752
  entity:
    uuid: ddc267cc-37d9-28fe-802a-0c67364de75e
  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/stable/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: 7715910acb789d525716a3c174007fab
  size_bytes: 3492813
display:
  name: facies
_preprocessed: false