Skip to content

Commit

Permalink
Add class for cpgrid_property.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwiker committed Nov 26, 2024
1 parent 70bd4f8 commit 6720bc2
Show file tree
Hide file tree
Showing 3 changed files with 48 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_property import CPGridProperty
from fmu.sumo.explorer.objects.iteration import Iteration
from fmu.sumo.explorer.objects.iterations import Iterations
from fmu.sumo.explorer.objects.realization import Realization
Expand Down
1 change: 1 addition & 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_property": objects.CPGridProperty
}.get(cls)
if constructor is None:
warnings.warn(f"No constructor for class {cls}")
Expand Down
46 changes: 46 additions & 0 deletions src/fmu/sumo/explorer/objects/cpgrid_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Module containing class for cpgrid_property"""

from typing import Dict
from sumo.wrapper import SumoClient
from fmu.sumo.explorer.objects._child import Child

class CPGridProperty(Child):
"""Class representing a cpgrid_property 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_property(self):
"""Get cpgrid_property object as a GridProperty
Returns:
GridProperty: A GridProperty object
"""
try:
from xtgeo import gridproperty_from_file
except ModuleNotFoundError:
raise RuntimeError("Unable to import xtgeo; probably not installed.")
try:
return gridproperty_from_file(self.blob)
except TypeError as err:
raise TypeError(f"Unknown format: {self.format}") from type_err

async def to_cpgrid_property_async(self):
"""Get cpgrid_property object as a GridProperty
Returns:
GridProperty: A GridProperty object
"""
try:
from xtgeo import gridproperty_from_file
except ModuleNotFoundError:
raise RuntimeError("Unable to import xtgeo; probably not installed.")

try:
return gridproperty_from_file(await self.blob_async)
except TypeError as err:
raise TypeError(f"Unknown format: {self.format}") from type_err

0 comments on commit 6720bc2

Please sign in to comment.