Skip to content

Commit 5785e03

Browse files
committed
MAINT: Replace TSurfData with xtgeo.TriangulatedSurface
1 parent 5c2efeb commit 5785e03

16 files changed

Lines changed: 145 additions & 1745 deletions

File tree

docs/src/custom_exports/usage.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ documentation](https://xtgeo.readthedocs.io).
7979

8080
- [xtgeo.RegularSurface](https://xtgeo.readthedocs.io/en/stable/datamodels.html#surface-regularsurface).
8181
Exported as `.gri` files.
82+
- xtgeo.TriangularSurface. Exported as `.ts` files.
8283
- [xtgeo.Polygons](https://xtgeo.readthedocs.io/en/stable/datamodels.html#xyz-data-points-and-polygons).
8384
Exported as `.csv` files by default.
8485
- [xtgeo.Points](https://xtgeo.readthedocs.io/en/stable/datamodels.html#xyz-data-points-and-polygons)
@@ -123,14 +124,6 @@ have a particular format that is understood by fmu-dataio.
123124

124125
FaultRoom surfaces are exported as JSON files.
125126

126-
#### GOCAD Surface/TSURF Files
127-
128-
These are triangle-based surfaces. Within FMU, TSURF files can be created and
129-
exported within RMS. The `TSurfData` class is currently stored in fmu-dataio
130-
but will eventually exist as an xtgeo type.
131-
132-
TSURF files are exported as `.ts` TSURF files.
133-
134127
#### Something Missing?
135128

136129
If you have a particular data type you would like to export with fmu-dataio,

src/fmu/dataio/_export/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .serialize import export_object
2121

2222
if TYPE_CHECKING:
23-
from fmu.dataio.types import ExportableData
23+
from fmu.dataio._metadata import ObjectData
2424

2525
from ._export_config import ExportConfig
2626

@@ -69,7 +69,7 @@ def _update_manifest_if_needed(export_config: ExportConfig, outfile: Path) -> No
6969
update_export_manifest(outfile, casepath=export_config.runcontext.casepath)
7070

7171

72-
def _write_object(file: Path, objdata: ExportableData) -> None:
72+
def _write_object(file: Path, objdata: ObjectData) -> None:
7373
"""Write an object to a file, creating parent directories as needed."""
7474
file.parent.mkdir(parents=True, exist_ok=True)
7575
export_object(objdata, file)

src/fmu/dataio/_export/serialize.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
import xtgeo
2020

2121
from fmu.dataio._logging import null_logger
22-
from fmu.dataio._readers import tsurf as tsurf_reader
22+
from fmu.dataio._metadata._object._xtgeo import PointsData, PolygonsData
2323
from fmu.dataio._readers.faultroom import FaultRoomSurface
24-
from fmu.dataio._readers.tsurf import TSurfData
2524
from fmu.dataio._utils import md5sum
2625
from fmu.datamodels.fmu_results.enums import FileFormat
2726

2827
if TYPE_CHECKING:
29-
from fmu.dataio._metadata.objectdata._base import ObjectData
28+
from fmu.dataio._metadata import ObjectData
3029

3130
logger: Final = null_logger(__name__)
3231

@@ -42,6 +41,9 @@ def export_object(objdata: ObjectData, file: Path | BytesIO) -> None:
4241
if isinstance(obj, xtgeo.RegularSurface):
4342
obj.to_file(file, fformat="irap_binary")
4443

44+
elif isinstance(obj, xtgeo.TriangulatedSurface):
45+
obj.to_file(file, fformat="tsurf")
46+
4547
elif isinstance(obj, (xtgeo.Polygons, xtgeo.Points)):
4648
_export_tabular_xtgeo(objdata, file)
4749

@@ -64,9 +66,6 @@ def export_object(objdata: ObjectData, file: Path | BytesIO) -> None:
6466
elif isinstance(obj, FaultRoomSurface):
6567
_export_json(json.dumps(obj.storage, indent=4), file)
6668

67-
elif isinstance(obj, TSurfData):
68-
tsurf_reader.write_tsurf_to_file(obj, file)
69-
7069
elif isinstance(obj, dict):
7170
_export_json(json.dumps(obj), file)
7271

@@ -78,6 +77,8 @@ def export_object(objdata: ObjectData, file: Path | BytesIO) -> None:
7877

7978
def _export_tabular_xtgeo(objdata: ObjectData, file: Path | BytesIO) -> None:
8079
"""Export xtgeo Polygons or Points, respecting the configured format."""
80+
assert isinstance(objdata, (PolygonsData, PointsData)) # for mypy
81+
8182
fmt = objdata.fmt
8283

8384
if fmt == FileFormat.parquet:

src/fmu/dataio/_metadata/_object/_triangulated_surface.py

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/fmu/dataio/_metadata/_object/_xtgeo.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PointSpecification,
2424
PolygonsSpecification,
2525
SurfaceSpecification,
26+
TriangulatedSurfaceSpecification,
2627
ZoneDefinition,
2728
)
2829

@@ -171,6 +172,63 @@ def get_spec(self) -> SurfaceSpecification:
171172
)
172173

173174

175+
class TriangulatedSurfaceData(ObjectData):
176+
"""Provider for triangulated surface data."""
177+
178+
obj: xtgeo.TriangulatedSurface
179+
180+
@property
181+
def classname(self) -> ObjectMetadataClass:
182+
return ObjectMetadataClass.surface
183+
184+
@property
185+
def efolder(self) -> str:
186+
return self.export_config.forcefolder or ExportFolder.maps.value
187+
188+
@property
189+
def extension(self) -> str:
190+
return FileExtension.tsurf.value
191+
192+
@property
193+
def fmt(self) -> FileFormat:
194+
return FileFormat.tsurf
195+
196+
@property
197+
def layout(self) -> Layout:
198+
return Layout.triangulated
199+
200+
@property
201+
def table_index(self) -> None:
202+
"""Return the table index."""
203+
204+
def get_geometry(self) -> None:
205+
"""Derive data.geometry for TriangulatedSurface."""
206+
207+
def get_bbox(self) -> BoundingBox3D:
208+
"""Derive data.bbox for TriangulatedSurface."""
209+
logger.info("Get bounding box for TriangulatedSurface")
210+
211+
bbox = self.obj.bounding_box
212+
return BoundingBox3D(
213+
xmin=bbox.min_x,
214+
xmax=bbox.max_x,
215+
ymin=bbox.min_y,
216+
ymax=bbox.max_y,
217+
zmin=bbox.min_z,
218+
zmax=bbox.max_z,
219+
)
220+
221+
def get_spec(self) -> TriangulatedSurfaceSpecification:
222+
"""Derive data.spec for TriangulatedSurface"""
223+
logger.info("Get spec for TriangulatedSurface")
224+
225+
required = self.obj.metadata.required
226+
return TriangulatedSurfaceSpecification(
227+
num_vertices=required["num_vertices"],
228+
num_triangles=required["num_triangles"],
229+
)
230+
231+
174232
class PolygonsData(ObjectData):
175233
obj: xtgeo.Polygons
176234

src/fmu/dataio/_metadata/_object/core.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,19 @@
1616
from fmu.dataio._export import ExportConfig
1717
from fmu.dataio._logging import null_logger
1818
from fmu.dataio._readers.faultroom import FaultRoomSurface
19-
from fmu.dataio._readers.tsurf import TSurfData
2019
from fmu.datamodels.fmu_results.enums import FileFormat, Layout, ObjectMetadataClass
2120

22-
from ._base import (
23-
ObjectData,
24-
)
21+
from ._base import ObjectData
2522
from ._faultroom import FaultRoomSurfaceData
2623
from ._tables import ArrowTableData, DataFrameData
27-
from ._triangulated_surface import TriangulatedSurfaceData
2824
from ._xtgeo import (
2925
CPGridData,
3026
CPGridPropertyData,
3127
CubeData,
3228
PointsData,
3329
PolygonsData,
3430
RegularSurfaceData,
31+
TriangulatedSurfaceData,
3532
)
3633

3734
if TYPE_CHECKING:
@@ -54,6 +51,8 @@ def create_object_data(obj: ExportableData, export_config: ExportConfig) -> Obje
5451
"""
5552
if isinstance(obj, xtgeo.RegularSurface):
5653
return RegularSurfaceData(obj, export_config)
54+
if isinstance(obj, xtgeo.TriangulatedSurface):
55+
return TriangulatedSurfaceData(obj, export_config)
5756
if isinstance(obj, xtgeo.Polygons):
5857
return PolygonsData(obj, export_config)
5958
if isinstance(obj, xtgeo.Points):
@@ -68,8 +67,6 @@ def create_object_data(obj: ExportableData, export_config: ExportConfig) -> Obje
6867
return DataFrameData(obj, export_config)
6968
if isinstance(obj, FaultRoomSurface):
7069
return FaultRoomSurfaceData(obj, export_config)
71-
if isinstance(obj, TSurfData):
72-
return TriangulatedSurfaceData(obj, export_config)
7370
if isinstance(obj, dict):
7471
return DictionaryData(obj, export_config)
7572
if isinstance(obj, pa.Table):

0 commit comments

Comments
 (0)