diff --git a/src/fmu/sumo/explorer/objects/__init__.py b/src/fmu/sumo/explorer/objects/__init__.py index 1b12706..33cd686 100644 --- a/src/fmu/sumo/explorer/objects/__init__.py +++ b/src/fmu/sumo/explorer/objects/__init__.py @@ -10,6 +10,7 @@ from fmu.sumo.explorer.objects.surface import Surface from fmu.sumo.explorer.objects.polygons import Polygons from fmu.sumo.explorer.objects.table import Table +from fmu.sumo.explorer.objects.cpgrid import CPGrid from fmu.sumo.explorer.objects.cpgrid_property import CPGridProperty from fmu.sumo.explorer.objects.iteration import Iteration from fmu.sumo.explorer.objects.iterations import Iterations diff --git a/src/fmu/sumo/explorer/objects/_search_context.py b/src/fmu/sumo/explorer/objects/_search_context.py index ee1c6d9..c46326f 100644 --- a/src/fmu/sumo/explorer/objects/_search_context.py +++ b/src/fmu/sumo/explorer/objects/_search_context.py @@ -324,6 +324,7 @@ def _to_sumo(self, obj, blob=None): "polygons": objects.Polygons, "surface": objects.Surface, "table": objects.Table, + "cpgrid": objects.CPGrid, "cpgrid_property": objects.CPGridProperty }.get(cls) if constructor is None: @@ -959,6 +960,14 @@ def polygons(self): def dictionaries(self): return self._context_for_class("dictionary") + @property + def grids(self): + return self._context_for_class("cpgrid") + + @property + def grid_properties(self): + return self._context_for_class("cpgrid_property") + def _get_object_by_class_and_uuid(self, cls, uuid): obj = self.get_object(uuid) if obj.metadata["class"] != cls: diff --git a/src/fmu/sumo/explorer/objects/cpgrid.py b/src/fmu/sumo/explorer/objects/cpgrid.py new file mode 100644 index 0000000..f0c0363 --- /dev/null +++ b/src/fmu/sumo/explorer/objects/cpgrid.py @@ -0,0 +1,46 @@ +"""Module containing class for cpgrid""" + +from typing import Dict +from sumo.wrapper import SumoClient +from fmu.sumo.explorer.objects._child import Child + +class CPGrid(Child): + """Class representing a cpgrid object in Sumo.""" + + def __init__(self, sumo: SumoClient, metadata: Dict, blob=None) -> None: + """ + Args: + sumo (SumoClient): connection to Sumo + metadata (dict): dictionary metadata + blob: data object + """ + super().__init__(sumo, metadata, blob) + + def to_cpgrid(self): + """Get cpgrid object as a Grid + Returns: + Grid: A Grid object + """ + try: + from xtgeo import grid_from_file + except ModuleNotFoundError: + raise RuntimeError("Unable to import xtgeo; probably not installed.") + try: + return grid_from_file(self.blob) + except TypeError as err: + raise TypeError(f"Unknown format: {self.format}") from type_err + + async def to_cpgrid_async(self): + """Get cpgrid object as a Grid + Returns: + Grid: A Grid object + """ + try: + from xtgeo import grid_from_file + except ModuleNotFoundError: + raise RuntimeError("Unable to import xtgeo; probably not installed.") + + try: + return grid_from_file(await self.blob_async) + except TypeError as err: + raise TypeError(f"Unknown format: {self.format}") from type_err