fmu-sumo 2.6.2__py3-none-any.whl → 2.8.0__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.
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '2.6.2'
32
- __version_tuple__ = version_tuple = (2, 6, 2)
31
+ __version__ = version = '2.8.0'
32
+ __version_tuple__ = version_tuple = (2, 8, 0)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -212,3 +212,8 @@ class Child(Document):
212
212
  def operationname(self) -> str:
213
213
  """Object aggregation operation name"""
214
214
  return self.get_property("fmu.aggregation.operation")
215
+
216
+ @property
217
+ def entity(self) -> str:
218
+ """Entity uuid for object."""
219
+ return self.get_property("fmu.entity.uuid")
@@ -219,6 +219,30 @@ def _build_bucket_query_simple(query, field, size):
219
219
  }
220
220
 
221
221
 
222
+ def _build_composite_query(query, fields, size):
223
+ return {
224
+ "size": 0,
225
+ "query": query,
226
+ "aggs": {
227
+ "composite": {
228
+ "composite": {
229
+ "size": size,
230
+ "sources": [
231
+ {k: {"terms": {"field": v}}} for k, v in fields.items()
232
+ ],
233
+ }
234
+ }
235
+ },
236
+ }
237
+
238
+
239
+ def _extract_composite_results(res):
240
+ aggs = res["aggregations"]["composite"]
241
+ after_key = aggs.get("after_key")
242
+ buckets = [bucket["key"] for bucket in aggs["buckets"]]
243
+ return buckets, after_key
244
+
245
+
222
246
  def _set_after_key(query, field, after_key):
223
247
  if after_key is not None:
224
248
  query["aggs"][field]["composite"]["after"] = after_key
@@ -1027,6 +1051,52 @@ class SearchContext:
1027
1051
  }
1028
1052
  }
1029
1053
 
1054
+ def get_composite_agg(self, fields: Dict[str, str]):
1055
+ buckets_per_batch = 1000
1056
+ query = _build_composite_query(self._query, fields, buckets_per_batch)
1057
+ all_buckets = []
1058
+ after_key = None
1059
+ with Pit(self._sumo, "1m") as pit:
1060
+ while True:
1061
+ query = pit.stamp_query(
1062
+ _set_after_key(query, "composite", after_key)
1063
+ )
1064
+ res = self._sumo.post("/search", json=query)
1065
+ res = res.json()
1066
+ pit.update_from_result(res)
1067
+ buckets, after_key = _extract_composite_results(res)
1068
+ if len(buckets) == 0:
1069
+ break
1070
+ all_buckets = all_buckets + buckets
1071
+ if len(buckets) < buckets_per_batch:
1072
+ break
1073
+ pass
1074
+
1075
+ return all_buckets
1076
+
1077
+ async def get_composite_agg_async(self, fields: Dict[str, str]):
1078
+ buckets_per_batch = 1000
1079
+ query = _build_composite_query(self._query, fields, buckets_per_batch)
1080
+ all_buckets = []
1081
+ after_key = None
1082
+ async with Pit(self._sumo, "1m") as pit:
1083
+ while True:
1084
+ query = pit.stamp_query(
1085
+ _set_after_key(query, "composite", after_key)
1086
+ )
1087
+ res = await self._sumo.post_async("/search", json=query)
1088
+ res = res.json()
1089
+ pit.update_from_result(res)
1090
+ buckets, after_key = _extract_composite_results(res)
1091
+ if len(buckets) == 0:
1092
+ break
1093
+ all_buckets = all_buckets + buckets
1094
+ if len(buckets) < buckets_per_batch:
1095
+ break
1096
+ pass
1097
+
1098
+ return all_buckets
1099
+
1030
1100
  def _context_for_class(self, cls):
1031
1101
  return self.filter(cls=cls)
1032
1102
 
@@ -19,3 +19,7 @@ class Cases(SearchContext):
19
19
  sc = super().filter(**kwargs)
20
20
  uuids = sc.get_field_values("fmu.case.uuid.keyword")
21
21
  return Cases(sc, uuids)
22
+
23
+ @property
24
+ def names(self):
25
+ return self.get_field_values("fmu.case.name.keyword")
@@ -1,7 +1,10 @@
1
1
  """Module for searchcontext for collection of ensembles."""
2
2
 
3
+ from copy import deepcopy
3
4
  from typing import List
4
5
 
6
+ from fmu.sumo.explorer.objects.ensemble import Ensemble
7
+
5
8
  from ._search_context import SearchContext
6
9
 
7
10
 
@@ -9,16 +12,10 @@ class Ensembles(SearchContext):
9
12
  def __init__(self, sc, uuids):
10
13
  super().__init__(sc._sumo, must=[{"ids": {"values": uuids}}])
11
14
  self._hits = uuids
15
+ self._prototype = None
16
+ self._map = {}
12
17
  return
13
18
 
14
- @property
15
- def classes(self) -> List[str]:
16
- return ["ensemble"]
17
-
18
- @property
19
- async def classes_async(self) -> List[str]:
20
- return ["ensemble"]
21
-
22
19
  def _maybe_prefetch(self, index):
23
20
  return
24
21
 
@@ -29,3 +26,65 @@ class Ensembles(SearchContext):
29
26
  sc = super().filter(**kwargs)
30
27
  uuids = sc.get_field_values("fmu.ensemble.uuid.keyword")
31
28
  return Ensembles(sc, uuids)
29
+
30
+ def get_object(self, uuid):
31
+ if self._prototype is None:
32
+ obj = super().get_object(uuid)
33
+ if len(self.get_field_values("fmu.case.uuid.keyword")) > 1:
34
+ return obj
35
+ # ELSE
36
+ self._prototype = obj.metadata
37
+ buckets = self.get_composite_agg(
38
+ {
39
+ "uuid": "fmu.ensemble.uuid.keyword",
40
+ "name": "fmu.ensemble.name.keyword",
41
+ }
42
+ )
43
+ self._map = {b["uuid"]: b for b in buckets}
44
+ pass
45
+ metadata = deepcopy(self._prototype)
46
+ b = self._map[uuid]
47
+ metadata["fmu"]["ensemble"] = b
48
+ return Ensemble(self._sumo, {"_id": uuid, "_source": metadata})
49
+
50
+ async def get_object_async(self, uuid):
51
+ if self._prototype is None:
52
+ obj = await super().get_object_async(uuid)
53
+ if (
54
+ len(await self.get_field_values_async("fmu.case.uuid.keyword"))
55
+ > 1
56
+ ):
57
+ return obj
58
+ # ELSE
59
+ self._prototype = obj.metadata
60
+ buckets = await self.get_composite_agg_async(
61
+ {
62
+ "uuid": "fmu.ensemble.uuid.keyword",
63
+ "name": "fmu.ensemble.name.keyword",
64
+ }
65
+ )
66
+ self._map = {b["uuid"]: b for b in buckets}
67
+ pass
68
+ metadata = deepcopy(self._prototype)
69
+ b = self._map[uuid]
70
+ metadata["fmu"]["ensemble"] = b
71
+ return Ensemble(self._sumo, {"_id": uuid, "_source": metadata})
72
+
73
+ @property
74
+ def classes(self) -> List[str]:
75
+ return ["ensemble"]
76
+
77
+ @property
78
+ async def classes_async(self) -> List[str]:
79
+ return ["ensemble"]
80
+
81
+ @property
82
+ def ensemblenames(self) -> List[str]:
83
+ return [self.get_object(uuid).ensemblename for uuid in self._hits]
84
+
85
+ @property
86
+ async def ensemblenames_async(self) -> List[str]:
87
+ return [
88
+ (await self.get_object_async(uuid)).ensemblename
89
+ for uuid in self._hits
90
+ ]
@@ -1,7 +1,10 @@
1
1
  """Module for searchcontext for collection of realizations."""
2
2
 
3
+ from copy import deepcopy
3
4
  from typing import List
4
5
 
6
+ from fmu.sumo.explorer.objects.realization import Realization
7
+
5
8
  from ._search_context import SearchContext
6
9
 
7
10
 
@@ -9,6 +12,8 @@ class Realizations(SearchContext):
9
12
  def __init__(self, sc, uuids):
10
13
  super().__init__(sc._sumo, must=[{"ids": {"values": uuids}}])
11
14
  self._hits = uuids
15
+ self._prototype = None
16
+ self._map = {}
12
17
  return
13
18
 
14
19
  def _maybe_prefetch(self, index):
@@ -22,6 +27,55 @@ class Realizations(SearchContext):
22
27
  uuids = sc.get_field_values("fmu.realization.uuid.keyword")
23
28
  return Realizations(self, uuids)
24
29
 
30
+ def get_object(self, uuid):
31
+ if self._prototype is None:
32
+ obj = super().get_object(uuid)
33
+ if len(self.get_field_values("fmu.realization.uuid.keyword")) == 1:
34
+ return obj
35
+ # ELSE
36
+ self._prototype = obj.metadata
37
+ buckets = self.get_composite_agg(
38
+ {
39
+ "uuid": "fmu.realization.uuid.keyword",
40
+ "name": "fmu.realization.name.keyword",
41
+ "id": "fmu.realization.id",
42
+ }
43
+ )
44
+ self._map = {b["uuid"]: b for b in buckets}
45
+ pass
46
+ metadata = deepcopy(self._prototype)
47
+ b = self._map[uuid]
48
+ metadata["fmu"]["realization"] = b
49
+ return Realization(self._sumo, {"_id": uuid, "_source": metadata})
50
+
51
+ async def get_object_async(self, uuid):
52
+ if self._prototype is None:
53
+ obj = await super().get_object_async(uuid)
54
+ if (
55
+ len(
56
+ await self.get_field_values_async(
57
+ "fmu.realization.uuid.keyword"
58
+ )
59
+ )
60
+ == 1
61
+ ):
62
+ return obj
63
+ # ELSE
64
+ self._prototype = obj.metadata
65
+ buckets = await self.get_composite_agg_async(
66
+ {
67
+ "uuid": "fmu.realization.uuid.keyword",
68
+ "name": "fmu.realization.name.keyword",
69
+ "id": "fmu.realization.id",
70
+ }
71
+ )
72
+ self._map = {b["uuid"]: b for b in buckets}
73
+ pass
74
+ metadata = deepcopy(self._prototype)
75
+ b = self._map[uuid]
76
+ metadata["fmu"]["realization"] = b
77
+ return Realization(self._sumo, {"_id": uuid, "_source": metadata})
78
+
25
79
  @property
26
80
  def classes(self) -> List[str]:
27
81
  return ["realization"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fmu-sumo
3
- Version: 2.6.2
3
+ Version: 2.8.0
4
4
  Summary: Python package for interacting with Sumo in an FMU setting
5
5
  Author: Equinor
6
6
  License: Apache License
@@ -1,33 +1,33 @@
1
1
  fmu/__init__.py,sha256=ftS-xRPSH-vU7fIHlnZQaCTWbNvs4owJivNW65kzsIM,85
2
2
  fmu/sumo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  fmu/sumo/explorer/__init__.py,sha256=Bc1wd1lQO3HP3tsVyPbqaesf2boZwGdtookWp8lmG-k,317
4
- fmu/sumo/explorer/_version.py,sha256=K_PdMoDM3cnCth9l5Wj8Zgz4tHrD_dXoBfsMuI4VHeQ,704
4
+ fmu/sumo/explorer/_version.py,sha256=9o_P9mg_lm8dZdRjWfkpikVSLuPB26JLjcQeqWLe_GI,704
5
5
  fmu/sumo/explorer/cache.py,sha256=uvz8TciwBnDEwJIHa9wneC0WVWuzhUqyF3dzk4kvGNk,1037
6
6
  fmu/sumo/explorer/explorer.py,sha256=_3nUTO1E_nf6jqpivjgjKcX6rX1fx_mIG76YOM8xb-8,2931
7
7
  fmu/sumo/explorer/filters.py,sha256=_t2PmHeTY9XiBvQeEGM-BpudWUaxIfyUSdNyG70xfRU,875
8
8
  fmu/sumo/explorer/timefilter.py,sha256=AQHa18vkCz2BzH7X9GR1ypmNxfvI4gExh_jxAVYrDjc,6260
9
9
  fmu/sumo/explorer/objects/__init__.py,sha256=72G0yfWWMTXA-oZw5GMRkrWvQqAYfadjerEwsyndCzc,637
10
- fmu/sumo/explorer/objects/_child.py,sha256=I-TVxC5JhmcuCAkj1A_dK-cUzvbQarbonX1zq59d0ZU,6088
10
+ fmu/sumo/explorer/objects/_child.py,sha256=7CJiBGfmtK7zNDUv6NLWphHMMtC8M386VyrGhuHq4dk,6222
11
11
  fmu/sumo/explorer/objects/_document.py,sha256=UR607n9N33vYaTSsYQoMmJUgnmS3To_uVyRSf7Vxulo,1797
12
12
  fmu/sumo/explorer/objects/_metrics.py,sha256=Z7iJ8qmvH3iY5dsSf6At_AFIzITyM0rDfum_oGmUFG8,9989
13
- fmu/sumo/explorer/objects/_search_context.py,sha256=xZq04B0op2Rko-qcsvEqs8SHRFZh_uJYTV6ZXZcNRXY,66564
13
+ fmu/sumo/explorer/objects/_search_context.py,sha256=qV4UIQsddoF1liKiQ9ZlBx8FbMRpll7F6jXvQ-T7gQc,68933
14
14
  fmu/sumo/explorer/objects/case.py,sha256=fKp7X43ETLE1RaH3rMYxZiIuduRmf0JSnJ5gRoUgNPE,3813
15
- fmu/sumo/explorer/objects/cases.py,sha256=i2bnvk7NWIkzbdWMs3BXU7TCqD5tH2r7pg1m1QXUj3o,561
15
+ fmu/sumo/explorer/objects/cases.py,sha256=_6q8rXWUeJgHGF1b3X9rt3VQmH_HE7uPU0Id4Fmtq_E,659
16
16
  fmu/sumo/explorer/objects/cpgrid.py,sha256=nuRgZ6FVEOPZT1ibd-rJhlbYYZ6BuUxXZPzovcH0kVc,2548
17
17
  fmu/sumo/explorer/objects/cpgrid_property.py,sha256=PqqR05oKKKiTTG0iDO9V6TADdHY7VUsLHjai6SqahVo,2694
18
18
  fmu/sumo/explorer/objects/cube.py,sha256=6pJLDajex-mblkt9YRZxtcK1XHcRZ8mlPPqJ-yDGEbA,1948
19
19
  fmu/sumo/explorer/objects/dictionary.py,sha256=9Nt8Br7H4TgXO6qc46HtV1vB40LsEQb6WjWYDT-Ve0g,1191
20
20
  fmu/sumo/explorer/objects/ensemble.py,sha256=MoGiXrtyVL8_cQt5vjh0rIA5bMMGRahPb284teQEqfs,2767
21
- fmu/sumo/explorer/objects/ensembles.py,sha256=uFtnWDgk316NRM_JvD1C7PK20gDOPQVQjCygPFhe3ZE,772
21
+ fmu/sumo/explorer/objects/ensembles.py,sha256=GnE0wJ8fKjJeSWnY4P0X46gKSxlgb9ihVcgWG7BeI5M,2811
22
22
  fmu/sumo/explorer/objects/iteration.py,sha256=vXaH6G93pNPvufgliqRSs4fpqgNvgxa7QI0G0ucgr_U,2784
23
23
  fmu/sumo/explorer/objects/iterations.py,sha256=ZRQOxPl6MpX7JV7lfvtXp8mGLHl37pl3-F9YAXYfRgc,778
24
24
  fmu/sumo/explorer/objects/polygons.py,sha256=0N6sKTOGkYO6augIbBObzdovCAIF5VtA_XDzbWvd3YY,1523
25
25
  fmu/sumo/explorer/objects/realization.py,sha256=HK47WyX6kwe6ZoHaGHeTWEno86Wkh9THLOtEzOt1FGE,2483
26
- fmu/sumo/explorer/objects/realizations.py,sha256=ojyQDZNEGubRE97z7c5WHK1ZnO267jsIureNeIzouAw,1120
26
+ fmu/sumo/explorer/objects/realizations.py,sha256=GmvaDm4y2HB9VGAl3d7FNX5ePVc3jJVht3UHQMQstTg,3061
27
27
  fmu/sumo/explorer/objects/surface.py,sha256=zHBtjLCIfkRHBv39OeJjA9lq3puLTfTII6TndZTtxVI,1627
28
28
  fmu/sumo/explorer/objects/table.py,sha256=vLor3YTddHkDWZSMyWPQsddFNQ2_VXE_O-stmPIWIaQ,4900
29
- fmu_sumo-2.6.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
30
- fmu_sumo-2.6.2.dist-info/METADATA,sha256=3SA9YL-w9t4cFxKw7gDO-uRvgYhdYi3ugLt4Rj6qbQ8,14781
31
- fmu_sumo-2.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
- fmu_sumo-2.6.2.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
33
- fmu_sumo-2.6.2.dist-info/RECORD,,
29
+ fmu_sumo-2.8.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
30
+ fmu_sumo-2.8.0.dist-info/METADATA,sha256=cBIyAnCj97Tx2toZhE_GSiMx684TebA1M1OJkmjUWMA,14781
31
+ fmu_sumo-2.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
32
+ fmu_sumo-2.8.0.dist-info/top_level.txt,sha256=Z-FIY3pxn0UK2Wxi9IJ7fKoLSraaxuNGi1eokiE0ShM,4
33
+ fmu_sumo-2.8.0.dist-info/RECORD,,