From 1173f4291ad4f7fe3755e9e2fa7cb4ed1877bc8a Mon Sep 17 00:00:00 2001 From: Raymond Wiker Date: Mon, 18 Nov 2024 08:02:58 +0100 Subject: [PATCH] Make SearchContext._to_sumo return something useful even for object type 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. --- src/fmu/sumo/explorer/objects/__init__.py | 1 + src/fmu/sumo/explorer/objects/_child.py | 5 +++++ src/fmu/sumo/explorer/objects/_search_context.py | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fmu/sumo/explorer/objects/__init__.py b/src/fmu/sumo/explorer/objects/__init__.py index abc610f8..42c32626 100644 --- a/src/fmu/sumo/explorer/objects/__init__.py +++ b/src/fmu/sumo/explorer/objects/__init__.py @@ -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 diff --git a/src/fmu/sumo/explorer/objects/_child.py b/src/fmu/sumo/explorer/objects/_child.py index 1055d374..8327ae73 100644 --- a/src/fmu/sumo/explorer/objects/_child.py +++ b/src/fmu/sumo/explorer/objects/_child.py @@ -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) diff --git a/src/fmu/sumo/explorer/objects/_search_context.py b/src/fmu/sumo/explorer/objects/_search_context.py index 26c20b86..fb749263 100644 --- a/src/fmu/sumo/explorer/objects/_search_context.py +++ b/src/fmu/sumo/explorer/objects/_search_context.py @@ -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 @@ -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): @@ -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."""