fmu-sumo 2.3.7__py3-none-any.whl → 2.3.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,11 @@ from typing import Dict
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._document import Document
8
- from fmu.sumo.explorer.objects._search_context import SearchContext
7
+ from ._document import Document
8
+ from ._search_context import SearchContext
9
9
 
10
10
 
11
- def _make_overview_query(id):
11
+ def _make_overview_query(id) -> Dict:
12
12
  return {
13
13
  "query": {"term": {"fmu.case.uuid.keyword": id}},
14
14
  "aggs": {
@@ -52,7 +52,7 @@ class Case(Document, SearchContext):
52
52
  self._iterations = None
53
53
 
54
54
  @property
55
- def overview(self):
55
+ def overview(self) -> Dict:
56
56
  """Overview of case contents."""
57
57
 
58
58
  def extract_bucket_keys(bucket, name):
@@ -1,6 +1,6 @@
1
1
  """Module for searchcontext for collection of cases."""
2
2
 
3
- from fmu.sumo.explorer.objects._search_context import SearchContext
3
+ from ._search_context import SearchContext
4
4
 
5
5
 
6
6
  class Cases(SearchContext):
@@ -16,6 +16,8 @@ class Cases(SearchContext):
16
16
  return
17
17
 
18
18
  def filter(self, **kwargs):
19
- sc = super().filter(**kwargs)
20
- uuids = sc.uuids
21
- return Cases(self, uuids)
19
+ sc = SearchContext(
20
+ self._sumo, must=[{"terms": {"fmu.case.uuid.keyword": self._hits}}]
21
+ ).filter(**kwargs)
22
+ uuids = sc.get_field_values("fmu.case.uuid.keyword")
23
+ return Cases(sc, uuids)
@@ -4,8 +4,8 @@ from typing import Dict
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._child import Child
8
- from fmu.sumo.explorer.objects._search_context import SearchContext
7
+ from ._child import Child
8
+ from ._search_context import SearchContext
9
9
 
10
10
 
11
11
  class CPGrid(Child):
@@ -32,7 +32,7 @@ class CPGrid(Child):
32
32
  "Unable to import xtgeo; probably not installed."
33
33
  )
34
34
  try:
35
- return grid_from_file(self.blob)
35
+ return grid_from_file(self.blob) # pyright: ignore type
36
36
  except TypeError as type_err:
37
37
  raise TypeError(f"Unknown format: {self.format}") from type_err
38
38
 
@@ -49,7 +49,7 @@ class CPGrid(Child):
49
49
  )
50
50
 
51
51
  try:
52
- return grid_from_file(await self.blob_async)
52
+ return grid_from_file(await self.blob_async) # pyright: ignore type
53
53
  except TypeError as type_err:
54
54
  raise TypeError(f"Unknown format: {self.format}") from type_err
55
55
 
@@ -4,8 +4,8 @@ from typing import Dict
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._child import Child
8
- from fmu.sumo.explorer.objects._search_context import SearchContext
7
+ from ._child import Child
8
+ from ._search_context import SearchContext
9
9
 
10
10
 
11
11
  class CPGridProperty(Child):
@@ -1,10 +1,10 @@
1
1
  """Module containing class for cube object"""
2
2
 
3
- from typing import Dict
3
+ from typing import Dict, Tuple
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._child import Child
7
+ from ._child import Child
8
8
 
9
9
 
10
10
  class Cube(Child):
@@ -17,64 +17,28 @@ class Cube(Child):
17
17
  metadata (dict): cube metadata
18
18
  """
19
19
  super().__init__(sumo, metadata, blob)
20
- self._url = None
21
- self._sas = None
22
20
 
23
- def _populate_url(self):
24
- res = self._sumo.get(f"/objects('{self.uuid}')/blob/authuri")
21
+ def _extract_auth(self, res) -> Tuple[str, str]:
25
22
  try:
26
23
  res = res.json()
27
- self._url = res.get("baseuri") + self.uuid
28
- self._sas = res.get("auth")
24
+ url = res.get("baseuri") + self.uuid
25
+ sas = res.get("auth")
29
26
  except Exception:
30
- self._url = res.text
31
-
32
- async def _populate_url_async(self):
33
- res = await self._sumo.get_async(
34
- f"/objects('{self.uuid}')/blob/authuri"
35
- )
36
- try:
37
- res = res.json()
38
- self._url = res.get("baseuri") + self.uuid
39
- self._sas = res.get("auth")
40
- except Exception:
41
- self._url = res.text
42
-
43
- @property
44
- def url(self) -> str:
45
- if self._url is None:
46
- self._populate_url()
47
- if self._sas is None:
48
- return self._url
49
- else:
50
- return self._url.split("?")[0] + "/"
51
-
52
- @property
53
- async def url_async(self) -> str:
54
- if self._url is None:
55
- await self._populate_url_async()
56
- if self._sas is None:
57
- return self._url
58
- else:
59
- return self._url.split("?")[0] + "/"
27
+ url, sas = res.text.split("?")
28
+ pass
29
+ return url, sas
60
30
 
61
31
  @property
62
- def sas(self) -> str:
63
- if self._url is None:
64
- self._populate_url()
65
- if self._sas is None:
66
- return self._url.split("?")[1]
67
- else:
68
- return self._sas
32
+ def auth(self) -> Tuple[str, str]:
33
+ res = self._sumo.get(f"/objects('{self.uuid}')/blob/authuri")
34
+ return self._extract_auth(res)
69
35
 
70
36
  @property
71
- async def sas_async(self) -> str:
72
- if self._url is None:
73
- await self._populate_url_async()
74
- if self._sas is None:
75
- return self._url.split("?")[1]
76
- else:
77
- return self._sas
37
+ async def auth_async(self) -> Tuple[str, str]:
38
+ res = await self._sumo.get_async(
39
+ f"/objects('{self.uuid}')/blob/authuri"
40
+ )
41
+ return self._extract_auth(res)
78
42
 
79
43
  @property
80
44
  def openvds_handle(self):
@@ -85,15 +49,10 @@ class Cube(Child):
85
49
  "Unable to import openvds; probably not installed."
86
50
  )
87
51
 
88
- if self._url is None:
89
- self._populate_url()
90
-
91
- if self._sas is None:
92
- return openvds.open(self._url)
93
- else:
94
- url = "azureSAS" + self._url[5:] + "/"
95
- sas = "Suffix=?" + self._sas
96
- return openvds.open(url, sas)
52
+ url, sas = self.auth
53
+ url = url.replace("https://", "azureSAS://") + "/"
54
+ sas = "Suffix=?" + sas
55
+ return openvds.open(url, sas)
97
56
 
98
57
  @property
99
58
  async def openvds_handle_async(self):
@@ -104,12 +63,7 @@ class Cube(Child):
104
63
  "Unable to import openvds; probably not installed."
105
64
  )
106
65
 
107
- if self._url is None:
108
- await self._populate_url_async()
109
-
110
- if self._sas is None:
111
- return openvds.open(self._url)
112
- else:
113
- url = "azureSAS" + self._url[5:] + "/"
114
- sas = "Suffix=?" + self._sas
115
- return openvds.open(url, sas)
66
+ url, sas = await self.auth_async
67
+ url = url.replace("https://", "azureSAS://") + "/"
68
+ sas = "Suffix=?" + sas
69
+ return openvds.open(url, sas)
@@ -1,7 +1,7 @@
1
1
  """Module containing class for dictionary object"""
2
2
 
3
3
  import json
4
- from typing import Dict
4
+ from typing import Dict, Optional
5
5
 
6
6
  from sumo.wrapper import SumoClient
7
7
 
@@ -11,7 +11,7 @@ from fmu.sumo.explorer.objects._child import Child
11
11
  class Dictionary(Child):
12
12
  """Class representing a dictionary object in Sumo"""
13
13
 
14
- _parsed: dict
14
+ _parsed: Optional[Dict]
15
15
 
16
16
  def __init__(self, sumo: SumoClient, metadata: Dict, blob=None) -> None:
17
17
  """
@@ -19,18 +19,26 @@ class Dictionary(Child):
19
19
  sumo (SumoClient): connection to Sumo
20
20
  metadata (dict): dictionary metadata
21
21
  """
22
- self._parsed = None
22
+ self._parsed: Optional[Dict] = None
23
23
 
24
24
  super().__init__(sumo, metadata, blob)
25
25
 
26
26
  def parse(self) -> Dict:
27
+ parsed = (
28
+ json.loads(self.blob.read().decode("utf-8"))
29
+ if self._parsed is None
30
+ else self._parsed
31
+ )
27
32
  if self._parsed is None:
28
- self._parsed = json.loads(self.blob.read().decode("utf-8"))
29
-
30
- return self._parsed
33
+ self._parsed = parsed
34
+ return parsed
31
35
 
32
36
  async def parse_async(self) -> Dict:
37
+ parsed = self._parsed = (
38
+ json.loads((await self.blob_async).read().decode("utf-8"))
39
+ if self._parsed is None
40
+ else self._parsed
41
+ )
33
42
  if self._parsed is None:
34
- self._parsed = json.loads(self.blob_async.read().decode("utf-8"))
35
-
36
- return self._parsed
43
+ self._parsed = parsed
44
+ return parsed
@@ -0,0 +1,76 @@
1
+ """Module for (pseudo) ensemble class."""
2
+
3
+ from typing import Dict, Optional
4
+
5
+ from sumo.wrapper import SumoClient
6
+
7
+ from ._document import Document
8
+ from ._search_context import SearchContext
9
+
10
+
11
+ class Ensemble(Document, SearchContext):
12
+ """Class for representing an ensemble in Sumo."""
13
+
14
+ def __init__(
15
+ self, sumo: SumoClient, metadata: Dict, blob: Optional[bytes] = None
16
+ ):
17
+ assert blob is None
18
+ Document.__init__(self, metadata)
19
+ SearchContext.__init__(
20
+ self,
21
+ sumo,
22
+ must=[{"term": {"fmu.ensemble.uuid.keyword": self.uuid}}],
23
+ )
24
+ pass
25
+
26
+ def __repr__(self):
27
+ return (
28
+ f"<{self.__class__.__name__}: {self.name} {self.uuid}(uuid) "
29
+ f"in case {self.casename} "
30
+ f"in asset {self.asset}>"
31
+ )
32
+
33
+ @property
34
+ def field(self) -> str:
35
+ """Case field"""
36
+ return self.get_property("masterdata.smda.field[0].identifier")
37
+
38
+ @property
39
+ def asset(self) -> str:
40
+ """Case asset"""
41
+ return self.get_property("access.asset.name")
42
+
43
+ @property
44
+ def user(self) -> str:
45
+ """Name of user who uploaded ensemble."""
46
+ return self.get_property("fmu.case.user.id")
47
+
48
+ @property
49
+ def caseuuid(self) -> str:
50
+ """FMU case uuid"""
51
+ return self.get_property("fmu.case.uuid")
52
+
53
+ @property
54
+ def casename(self) -> str:
55
+ """FMU case name"""
56
+ return self.get_property("fmu.case.name")
57
+
58
+ @property
59
+ def ensembleuuid(self) -> str:
60
+ """FMU ensemble uuid"""
61
+ return self.get_property("fmu.ensemble.uuid")
62
+
63
+ @property
64
+ def ensemblename(self) -> str:
65
+ """FMU ensemble name"""
66
+ return self.get_property("fmu.ensemble.name")
67
+
68
+ @property
69
+ def name(self) -> str:
70
+ """FMU ensemble name"""
71
+ return self.get_property("fmu.ensemble.name")
72
+
73
+ @property
74
+ def uuid(self) -> str:
75
+ """FMU ensemble uuid"""
76
+ return self.get_property("fmu.ensemble.uuid")
@@ -0,0 +1,81 @@
1
+ """Module for searchcontext for collection of ensembles."""
2
+
3
+ from typing import Dict, List
4
+
5
+ from ._search_context import SearchContext
6
+
7
+
8
+ class Ensembles(SearchContext):
9
+ def __init__(self, sc, uuids):
10
+ super().__init__(sc._sumo, must=[{"ids": {"values": uuids}}])
11
+ self._hits = uuids
12
+ return
13
+
14
+ # def __str__(self) -> str:
15
+ # length = len(self)
16
+ # if length == 0:
17
+ # return "None"
18
+ # else:
19
+ # preview = [self[i].metadata for i in range(min(5, length))]
20
+ # return f"Data Preview:\n{json.dumps(preview, indent=4)}"
21
+
22
+ # def __repr__(self) -> str:
23
+ # return(f"<{self.__class__.__name__} {len(self)} objects of type ensemble>")
24
+
25
+ @property
26
+ def classes(self) -> List[str]:
27
+ return ["ensemble"]
28
+
29
+ @property
30
+ async def classes_async(self) -> List[str]:
31
+ return ["ensemble"]
32
+
33
+ def _maybe_prefetch(self, index):
34
+ return
35
+
36
+ async def _maybe_prefetch_async(self, index):
37
+ return
38
+
39
+ def get_object(self, uuid: str) -> Dict:
40
+ """Get metadata object by uuid
41
+
42
+ Args:
43
+ uuid (str): uuid of metadata object
44
+ select (List[str]): list of metadata fields to return
45
+
46
+ Returns:
47
+ Dict: a metadata object
48
+ """
49
+ obj = self._cache.get(uuid)
50
+ if obj is None:
51
+ obj = self.get_ensemble_by_uuid(uuid)
52
+ self._cache.put(uuid, obj)
53
+ pass
54
+
55
+ return obj
56
+
57
+ async def get_object_async(self, uuid: str) -> Dict:
58
+ """Get metadata object by uuid
59
+
60
+ Args:
61
+ uuid (str): uuid of metadata object
62
+ select (List[str]): list of metadata fields to return
63
+
64
+ Returns:
65
+ Dict: a metadata object
66
+ """
67
+
68
+ obj = self._cache.get(uuid)
69
+ if obj is None:
70
+ obj = await self.get_ensemble_by_uuid_async(uuid)
71
+ self._cache.put(uuid, obj)
72
+
73
+ return obj
74
+
75
+ def filter(self, **kwargs):
76
+ sc = SearchContext(
77
+ self._sumo,
78
+ must=[{"terms": {"fmu.ensemble.uuid.keyword": self._hits}}],
79
+ ).filter(**kwargs)
80
+ uuids = sc.get_field_values("fmu.iteration.uuid.keyword")
81
+ return Ensembles(sc, uuids)
@@ -1,17 +1,20 @@
1
1
  """Module for (pseudo) iteration class."""
2
2
 
3
- from typing import Dict
3
+ from typing import Dict, Optional
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._document import Document
8
- from fmu.sumo.explorer.objects._search_context import SearchContext
7
+ from ._document import Document
8
+ from ._search_context import SearchContext
9
9
 
10
10
 
11
11
  class Iteration(Document, SearchContext):
12
12
  """Class for representing an iteration in Sumo."""
13
13
 
14
- def __init__(self, sumo: SumoClient, metadata: Dict):
14
+ def __init__(
15
+ self, sumo: SumoClient, metadata: Dict, blob: Optional[bytes] = None
16
+ ):
17
+ assert blob is None
15
18
  Document.__init__(self, metadata)
16
19
  SearchContext.__init__(
17
20
  self,
@@ -20,6 +23,13 @@ class Iteration(Document, SearchContext):
20
23
  )
21
24
  pass
22
25
 
26
+ def __repr__(self):
27
+ return (
28
+ f"<{self.__class__.__name__}: {self.name} {self.uuid}(uuid) "
29
+ f"in case {self.casename} "
30
+ f"in asset {self.asset}>"
31
+ )
32
+
23
33
  @property
24
34
  def field(self) -> str:
25
35
  """Case field"""
@@ -45,7 +55,22 @@ class Iteration(Document, SearchContext):
45
55
  """FMU case name"""
46
56
  return self.get_property("fmu.case.name")
47
57
 
58
+ @property
59
+ def iterationuuid(self) -> str:
60
+ """FMU iteration uuid"""
61
+ return self.get_property("fmu.iteration.uuid")
62
+
63
+ @property
64
+ def iterationname(self) -> str:
65
+ """FMU iteration name"""
66
+ return self.get_property("fmu.iteration.name")
67
+
48
68
  @property
49
69
  def name(self) -> str:
50
70
  """FMU iteration name"""
51
71
  return self.get_property("fmu.iteration.name")
72
+
73
+ @property
74
+ def uuid(self) -> str:
75
+ """FMU iteration uuid"""
76
+ return self.get_property("fmu.iteration.uuid")
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Dict, List
4
4
 
5
- from fmu.sumo.explorer.objects._search_context import SearchContext
5
+ from ._search_context import SearchContext
6
6
 
7
7
 
8
8
  class Iterations(SearchContext):
@@ -11,13 +11,21 @@ class Iterations(SearchContext):
11
11
  self._hits = uuids
12
12
  return
13
13
 
14
+ @property
15
+ def classes(self) -> List[str]:
16
+ return ["iteration"]
17
+
18
+ @property
19
+ async def classes_async(self) -> List[str]:
20
+ return ["iteration"]
21
+
14
22
  def _maybe_prefetch(self, index):
15
23
  return
16
24
 
17
25
  async def _maybe_prefetch_async(self, index):
18
26
  return
19
27
 
20
- def get_object(self, uuid: str, select: List[str] = None) -> Dict:
28
+ def get_object(self, uuid: str) -> Dict:
21
29
  """Get metadata object by uuid
22
30
 
23
31
  Args:
@@ -35,9 +43,7 @@ class Iterations(SearchContext):
35
43
 
36
44
  return obj
37
45
 
38
- async def get_object_async(
39
- self, uuid: str, select: List[str] = None
40
- ) -> Dict:
46
+ async def get_object_async(self, uuid: str) -> Dict:
41
47
  """Get metadata object by uuid
42
48
 
43
49
  Args:
@@ -56,6 +62,9 @@ class Iterations(SearchContext):
56
62
  return obj
57
63
 
58
64
  def filter(self, **kwargs):
59
- sc = super().filter(**kwargs)
60
- uuids = sc.uuids
61
- return Iterations(self, uuids)
65
+ sc = SearchContext(
66
+ self._sumo,
67
+ must=[{"terms": {"fmu.iteration.uuid.keyword": self._hits}}],
68
+ ).filter(**kwargs)
69
+ uuids = sc.get_field_values("fmu.iteration.uuid.keyword")
70
+ return Iterations(sc, uuids)
@@ -4,7 +4,7 @@ from typing import Dict
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._child import Child
7
+ from ._child import Child
8
8
 
9
9
 
10
10
  class Polygons(Child):
@@ -1,17 +1,20 @@
1
1
  """Module for (pseudo) realization class."""
2
2
 
3
- from typing import Dict
3
+ from typing import Dict, Optional
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._document import Document
8
- from fmu.sumo.explorer.objects._search_context import SearchContext
7
+ from ._document import Document
8
+ from ._search_context import SearchContext
9
9
 
10
10
 
11
11
  class Realization(Document, SearchContext):
12
12
  """Class for representing a realization in Sumo."""
13
13
 
14
- def __init__(self, sumo: SumoClient, metadata: Dict):
14
+ def __init__(
15
+ self, sumo: SumoClient, metadata: Dict, blob: Optional[bytes] = None
16
+ ):
17
+ assert blob is None
15
18
  Document.__init__(self, metadata)
16
19
  SearchContext.__init__(
17
20
  self,
@@ -20,6 +23,14 @@ class Realization(Document, SearchContext):
20
23
  )
21
24
  pass
22
25
 
26
+ def __repr__(self):
27
+ return (
28
+ f"<{self.__class__.__name__}: {self.realizationid} {self.uuid}(uuid) "
29
+ f"in iteration {self.iterationname} "
30
+ f"in case {self.casename} "
31
+ f"in asset {self.asset}>"
32
+ )
33
+
23
34
  @property
24
35
  def field(self) -> str:
25
36
  """Case field"""
@@ -54,3 +65,18 @@ class Realization(Document, SearchContext):
54
65
  def iterationname(self) -> str:
55
66
  """FMU iteration name"""
56
67
  return self.get_property("fmu.iteration.name")
68
+
69
+ @property
70
+ def realizationuuid(self) -> str:
71
+ """FMU realization uuid"""
72
+ return self.get_property("fmu.realization.uuid")
73
+
74
+ @property
75
+ def realizationname(self) -> str:
76
+ """FMU realization name"""
77
+ return self.get_property("fmu.realization.name")
78
+
79
+ @property
80
+ def realizationid(self) -> int:
81
+ """FMU realization id"""
82
+ return self.get_property("fmu.realization.id")
@@ -1,8 +1,8 @@
1
1
  """Module for searchcontext for collection of realizations."""
2
2
 
3
- from typing import Dict, List
3
+ from typing import Dict
4
4
 
5
- from fmu.sumo.explorer.objects._search_context import SearchContext
5
+ from ._search_context import SearchContext
6
6
 
7
7
 
8
8
  class Realizations(SearchContext):
@@ -17,7 +17,7 @@ class Realizations(SearchContext):
17
17
  async def _maybe_prefetch_async(self, index):
18
18
  return
19
19
 
20
- def get_object(self, uuid: str, select: List[str] = None) -> Dict:
20
+ def get_object(self, uuid: str) -> Dict:
21
21
  """Get metadata object by uuid
22
22
 
23
23
  Args:
@@ -35,9 +35,7 @@ class Realizations(SearchContext):
35
35
 
36
36
  return obj
37
37
 
38
- async def get_object_async(
39
- self, uuid: str, select: List[str] = None
40
- ) -> Dict:
38
+ async def get_object_async(self, uuid: str) -> Dict:
41
39
  """Get metadata object by uuid
42
40
 
43
41
  Args:
@@ -56,6 +54,9 @@ class Realizations(SearchContext):
56
54
  return obj
57
55
 
58
56
  def filter(self, **kwargs):
59
- sc = super().filter(**kwargs)
60
- uuids = sc.uuids
57
+ sc = SearchContext(
58
+ self._sumo,
59
+ must=[{"terms": {"fmu.realization.uuid.keyword": self._hits}}],
60
+ ).filter(**kwargs)
61
+ uuids = sc.get_field_values("fmu.realization.uuid.keyword")
61
62
  return Realizations(self, uuids)
@@ -4,7 +4,7 @@ from typing import Dict
4
4
 
5
5
  from sumo.wrapper import SumoClient
6
6
 
7
- from fmu.sumo.explorer.objects._child import Child
7
+ from ._child import Child
8
8
 
9
9
 
10
10
  class Surface(Child):
@@ -5,7 +5,7 @@ from typing import Dict
5
5
 
6
6
  from sumo.wrapper import SumoClient
7
7
 
8
- from fmu.sumo.explorer.objects._child import Child
8
+ from ._child import Child
9
9
 
10
10
 
11
11
  class Table(Child):