Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer dictionary support #222

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/explorer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.10.12"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
17 changes: 14 additions & 3 deletions src/fmu/sumo/explorer/objects/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from fmu.sumo.explorer.objects.polygons_collection import PolygonsCollection
from fmu.sumo.explorer.objects.table_collection import TableCollection
from fmu.sumo.explorer.objects.cube_collection import CubeCollection
from fmu.sumo.explorer.objects.dictionary_collection import (
DictionaryCollection,
)
from fmu.sumo.explorer._utils import Utils
from fmu.sumo.explorer.pit import Pit

Expand Down Expand Up @@ -54,12 +57,15 @@ def iterations(self) -> List[Dict]:
"query": {"term": {"_sumo.parent_object.keyword": self.uuid}},
"aggs": {
"uuid": {
"terms": {"field": "fmu.iteration.uuid.keyword", "size": 50},
"terms": {
"field": "fmu.iteration.uuid.keyword",
"size": 50,
},
"aggs": {
"name": {
"terms": {
"field": "fmu.iteration.name.keyword",
"size": 1
"field": "fmu.iteration.name.keyword",
"size": 1,
}
},
"realizations": {
Expand Down Expand Up @@ -208,3 +214,8 @@ def tables(self) -> TableCollection:
def cubes(self) -> CubeCollection:
"""List of case tables"""
return CubeCollection(self._sumo, self._uuid, pit=self._pit)

@property
def dictionaries(self) -> DictionaryCollection:
"""List of case dictionaries"""
return DictionaryCollection(self._sumo, self._uuid, pit=self._pit)
36 changes: 36 additions & 0 deletions src/fmu/sumo/explorer/objects/dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Module containing class for dictionary object"""
import json
from typing import Dict
from sumo.wrapper import SumoClient
from fmu.sumo.explorer.objects._child import Child


class Dictionary(Child):
"""Class representig a dictionary object in Sumo"""

_parsed: dict

def __init__(self, sumo: SumoClient, metadata: Dict) -> None:
"""
Args:
sumo (SumoClient): connection to Sumo
metadata (dict): dictionary metadata
"""
self._parsed = None

super().__init__(sumo, metadata)

@property
def blob(self) -> bytes:
"""Object blob"""
if self._blob is None:
res = self._sumo.get(f"/objects('{self.uuid}')/blob")
self._blob = res

return self._blob

def parse(self) -> Dict:
if self._parsed is None:
self._parsed = json.loads(self.blob.decode("utf-8"))

return self._parsed
66 changes: 66 additions & 0 deletions src/fmu/sumo/explorer/objects/dictionary_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Module containing class for colection of dictionaries """
from typing import Union, List, Dict
from sumo.wrapper import SumoClient
from fmu.sumo.explorer.objects._child_collection import ChildCollection
from fmu.sumo.explorer.pit import Pit
from fmu.sumo.explorer.objects.dictionary import Dictionary


class DictionaryCollection(ChildCollection):
"""Class for representing a collection of dictionaries objects in Sumo"""

def __init__(
self,
sumo: SumoClient,
case_uuid: str,
query: Dict = None,
pit: Pit = None,
):
"""
Args:
sumo (SumoClient): connection to Sumo
case_uuid (str): parent case uuid
query (dict): elastic query object
pit (Pit): point in time
"""
super().__init__("dictionary", sumo, case_uuid, query, pit)

def __getitem__(self, index) -> Dictionary:
doc = super().__getitem__(index)
return Dictionary(self._sumo, doc)

def filter(
self,
name: Union[str, List[str], bool] = None,
tagname: Union[str, List[str], bool] = None,
iteration: Union[str, List[str], bool] = None,
realization: Union[int, List[int], bool] = None,
aggregation: Union[str, List[str], bool] = None,
stage: Union[str, List[str], bool] = None,
uuid: Union[str, List[str], bool] = None,
) -> "DictionaryCollection":
"""Filter dictionaries

Args:
name (Union[str, List[str], bool]): polygon name
tagname (Union[str, List[str], bool]): polygon tagname
iteration (Union[int, List[int], bool]): iteration id
realization Union[int, List[int], bool]: realization id
uuid (Union[str, List[str], bool]): polygons object uuid

Returns:
DictionaryCollection: A filtered DictionaryCollection
"""
query = super()._add_filter(
name=name,
tagname=tagname,
iteration=iteration,
realization=realization,
aggregation=aggregation,
stage=stage,
uuid=uuid,
)

return DictionaryCollection(
self._sumo, self._case_uuid, query, self._pit
)
Loading