Skip to content

Commit

Permalink
Make SearchContext._to_sumo return something useful even for object t…
Browse files Browse the repository at this point in the history
…ype that do not have their own class. Implement new property template_path as a prototype for something that might end up being part of the schema.
  • Loading branch information
Raymond Wiker authored and rwiker committed Nov 18, 2024
1 parent 4bcd8fe commit 70bd4f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/fmu/sumo/explorer/objects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Sumo cases and child objects"""

from fmu.sumo.explorer.objects._search_context import SearchContext
from fmu.sumo.explorer.objects._child import Child
from fmu.sumo.explorer.objects._metrics import Metrics
from fmu.sumo.explorer.objects.case import Case
from fmu.sumo.explorer.objects.cases import Cases
Expand Down
5 changes: 5 additions & 0 deletions src/fmu/sumo/explorer/objects/_child.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,10 @@ def interval(self) -> str:

return None

@property
def template_path(self):
return "/".join(["{realization}", "{iteration}"] +
self.relative_path.split("/")[2:])


Child.map_properties(Child, _prop_desc)
9 changes: 8 additions & 1 deletion src/fmu/sumo/explorer/objects/_search_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
import httpx
import deprecation
import warnings
from typing import List, Dict, Tuple
from datetime import datetime
from io import BytesIO
Expand Down Expand Up @@ -324,7 +325,9 @@ def _to_sumo(self, obj, blob=None):
"surface": objects.Surface,
"table": objects.Table,
}.get(cls)
assert constructor is not None
if constructor is None:
warnings.warn(f"No constructor for class {cls}")
constructor = objects.Child
return constructor(self._sumo, obj, blob)

def __len__(self):
Expand Down Expand Up @@ -818,6 +821,10 @@ def realizations(self):
"""Realizations from current selection."""
return objects.Realizations(self)

@property
def template_paths(sc):
return set([obj.template_path for obj in sc])

@property
def metrics(self):
"""Metrics for current search context."""
Expand Down

0 comments on commit 70bd4f8

Please sign in to comment.