Skip to content

Commit

Permalink
Add class for cpgrid.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwiker committed Nov 26, 2024
1 parent 6720bc2 commit 5e6e55f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fmu/sumo/explorer/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/fmu/sumo/explorer/objects/_search_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
46 changes: 46 additions & 0 deletions src/fmu/sumo/explorer/objects/cpgrid.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5e6e55f

Please sign in to comment.