|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +from typing import TYPE_CHECKING, Any, Final |
| 5 | + |
| 6 | +import fmu.dataio as dio |
| 7 | +from fmu.dataio._logging import null_logger |
| 8 | +from fmu.dataio._models.fmu_results import standard_result |
| 9 | +from fmu.dataio._models.fmu_results.enums import Classification, StandardResultName |
| 10 | +from fmu.dataio.export._decorators import experimental |
| 11 | +from fmu.dataio.export._export_result import ExportResult, ExportResultItem |
| 12 | +from fmu.dataio.export.rms._utils import ( |
| 13 | + get_horizons_in_folder, |
| 14 | + get_rms_project_units, |
| 15 | + load_global_config, |
| 16 | +) |
| 17 | + |
| 18 | +if TYPE_CHECKING: |
| 19 | + import xtgeo |
| 20 | + |
| 21 | +_logger: Final = null_logger(__name__) |
| 22 | + |
| 23 | + |
| 24 | +class _ExportStructureDepthSurfaces: |
| 25 | + def __init__( |
| 26 | + self, |
| 27 | + project: Any, |
| 28 | + horizon_folder: str, |
| 29 | + ): |
| 30 | + _logger.debug("Process data, establish state prior to export.") |
| 31 | + self._config = load_global_config() |
| 32 | + self._surfaces = get_horizons_in_folder(project, horizon_folder) |
| 33 | + self._unit = "m" if get_rms_project_units(project) == "metric" else "ft" |
| 34 | + |
| 35 | + _logger.debug("Process data... DONE") |
| 36 | + |
| 37 | + @property |
| 38 | + def _standard_result(self) -> standard_result.SructureDepthSurfaceStandardResult: |
| 39 | + """Product type for the exported data.""" |
| 40 | + return standard_result.SructureDepthSurfaceStandardResult( |
| 41 | + name=StandardResultName.structure_depth_surface |
| 42 | + ) |
| 43 | + |
| 44 | + @property |
| 45 | + def _classification(self) -> Classification: |
| 46 | + """Get default classification.""" |
| 47 | + return Classification.internal |
| 48 | + |
| 49 | + def _export_surface(self, surf: xtgeo.RegularSurface) -> ExportResultItem: |
| 50 | + edata = dio.ExportData( |
| 51 | + config=self._config, |
| 52 | + content="depth", |
| 53 | + unit=self._unit, |
| 54 | + vertical_domain="depth", |
| 55 | + domain_reference="msl", |
| 56 | + subfolder="structure_depth_surfaces", |
| 57 | + is_prediction=True, |
| 58 | + name=surf.name, |
| 59 | + classification=self._classification, |
| 60 | + rep_include=True, |
| 61 | + ) |
| 62 | + |
| 63 | + absolute_export_path = edata._export_with_standard_result( |
| 64 | + surf, standard_result=self._standard_result |
| 65 | + ) |
| 66 | + _logger.debug("Surface exported to: %s", absolute_export_path) |
| 67 | + |
| 68 | + return ExportResultItem( |
| 69 | + absolute_path=Path(absolute_export_path), |
| 70 | + ) |
| 71 | + |
| 72 | + def _export_surfaces(self) -> ExportResult: |
| 73 | + """Do the actual surface export using dataio setup.""" |
| 74 | + return ExportResult( |
| 75 | + items=[self._export_surface(surf) for surf in self._surfaces] |
| 76 | + ) |
| 77 | + |
| 78 | + def _validate_surfaces(self) -> None: |
| 79 | + """Surface validations.""" |
| 80 | + # TODO: Add check that the surfaces are consistent, i.e. a stratigraphic |
| 81 | + # deeper surface should never have shallower values than the one above |
| 82 | + # also check that the surfaces have a stratigraphy entry. |
| 83 | + |
| 84 | + def export(self) -> ExportResult: |
| 85 | + """Export the depth as a standard_result.""" |
| 86 | + return self._export_surfaces() |
| 87 | + |
| 88 | + |
| 89 | +@experimental |
| 90 | +def export_structure_depth_surfaces( |
| 91 | + project: Any, |
| 92 | + horizon_folder: str, |
| 93 | +) -> ExportResult: |
| 94 | + """Simplified interface when exporting modelled depth surfaces from RMS. |
| 95 | +
|
| 96 | + Args: |
| 97 | + project: The 'magic' project variable in RMS. |
| 98 | + horizon_folder: Name of horizon folder in RMS. |
| 99 | + Note: |
| 100 | + This function is experimental and may change in future versions. |
| 101 | +
|
| 102 | + Examples: |
| 103 | + Example usage in an RMS script:: |
| 104 | +
|
| 105 | + from fmu.dataio.export.rms import export_structure_depth_surfaces |
| 106 | +
|
| 107 | + export_results = export_structure_depth_surfaces(project, "DS_extracted") |
| 108 | +
|
| 109 | + for result in export_results.items: |
| 110 | + print(f"Output surfaces to {result.absolute_path}") |
| 111 | +
|
| 112 | + """ |
| 113 | + |
| 114 | + return _ExportStructureDepthSurfaces(project, horizon_folder).export() |
0 commit comments