@@ -138,14 +138,14 @@ async def get_realization_surface_data_async(
138
138
139
139
return xtgeo_surf
140
140
141
- async def get_statistical_surface_data_async (
141
+ async def get_statistical_surfaces_data_async (
142
142
self ,
143
- statistic_function : StatisticFunction ,
143
+ statistic_functions : list [ StatisticFunction ] ,
144
144
name : str ,
145
145
attribute : str ,
146
146
time_or_interval_str : Optional [str ] = None ,
147
147
realizations : Optional [List [int ]] = None ,
148
- ) -> Optional [xtgeo .RegularSurface ]:
148
+ ) -> list [xtgeo .RegularSurface ]:
149
149
"""
150
150
Compute statistic and return surface data
151
151
"""
@@ -192,12 +192,12 @@ async def get_statistical_surface_data_async(
192
192
193
193
et_collect_reals_ms = timer .lap_ms ()
194
194
195
- xtgeo_surf = await _compute_statistical_surface_async (statistic_function , surface_collection )
195
+ xtgeo_surfs = await _compute_statistical_surfaces_async (statistic_functions , surface_collection )
196
+ print (xtgeo_surfs )
196
197
et_calc_stat_ms = timer .lap_ms ()
197
198
198
- if not xtgeo_surf :
199
+ if not xtgeo_surfs :
199
200
LOGGER .warning (f"Could not calculate statistical surface using Sumo for { addr_str } " )
200
- return None
201
201
202
202
LOGGER .debug (
203
203
f"Calculated statistical surface using Sumo in: { timer .elapsed_ms ()} ms ("
@@ -207,32 +207,50 @@ async def get_statistical_surface_data_async(
207
207
f"({ addr_str } { len (realizations )= } )"
208
208
)
209
209
210
- return xtgeo_surf
210
+ return xtgeo_surfs
211
211
212
212
def _make_addr_str (self , real_num : int , name : str , attribute : str , date_str : Optional [str ]) -> str :
213
213
addr_str = f"R:{ real_num } __N:{ name } __A:{ attribute } __D:{ date_str } __I:{ self ._iteration_name } __C:{ self ._case_uuid } "
214
214
return addr_str
215
215
216
216
217
- async def _compute_statistical_surface_async (
218
- statistic : StatisticFunction , surface_coll : SurfaceCollection
219
- ) -> xtgeo .RegularSurface :
220
- xtgeo_surf : xtgeo .RegularSurface = None
221
- if statistic == StatisticFunction .MIN :
222
- xtgeo_surf = await surface_coll .min_async ()
223
- elif statistic == StatisticFunction .MAX :
224
- xtgeo_surf = await surface_coll .max_async ()
225
- elif statistic == StatisticFunction .MEAN :
226
- xtgeo_surf = await surface_coll .mean_async ()
227
- elif statistic == StatisticFunction .P10 :
228
- xtgeo_surf = await surface_coll .p10_async ()
229
- elif statistic == StatisticFunction .P90 :
230
- xtgeo_surf = await surface_coll .p90_async ()
231
- elif statistic == StatisticFunction .P50 :
232
- xtgeo_surf = await surface_coll .p50_async ()
233
- elif statistic == StatisticFunction .STD :
234
- xtgeo_surf = await surface_coll .std_async ()
235
- else :
236
- raise ValueError ("Unhandled statistic function" )
237
-
238
- return xtgeo_surf
217
+ async def _compute_statistical_surfaces_async (
218
+ statistics : StatisticFunction , surface_coll : SurfaceCollection
219
+ ) -> list [xtgeo .RegularSurface ]:
220
+ # xtgeo_surf: xtgeo.RegularSurface = None
221
+ # if statistic == StatisticFunction.MIN:
222
+ # xtgeo_surf = await surface_coll.min_async()
223
+ # elif statistic == StatisticFunction.MAX:
224
+ # xtgeo_surf = await surface_coll.max_async()
225
+ # elif statistic == StatisticFunction.MEAN:
226
+ # xtgeo_surf = await surface_coll.mean_async()
227
+ # elif statistic == StatisticFunction.P10:
228
+ # xtgeo_surf = await surface_coll.p10_async()
229
+ # elif statistic == StatisticFunction.P90:
230
+ # xtgeo_surf = await surface_coll.p90_async()
231
+ # elif statistic == StatisticFunction.P50:
232
+ # xtgeo_surf = await surface_coll.p50_async()
233
+ # elif statistic == StatisticFunction.STD:
234
+ # xtgeo_surf = await surface_coll.std_async()
235
+ # else:
236
+ # raise ValueError("Unhandled statistic function")
237
+
238
+ # return xtgeo_surf
239
+ objects = await surface_coll ._utils .get_objects_async (500 , surface_coll ._query , ["_id" ])
240
+ object_ids = list (map (lambda obj : obj ["_id" ], objects ))
241
+ res = await surface_coll ._sumo .post_async (
242
+ "/surface/aggregate" ,
243
+ json = {"operation" : [stat .value for stat in statistics ], "object_ids" : object_ids },
244
+ )
245
+ res_bytes = res .content
246
+ # print(res.content)
247
+ import zipfile
248
+
249
+ surfs = []
250
+ with zipfile .ZipFile (BytesIO (res_bytes )) as z :
251
+ # return z.read(z.namelist()[0])
252
+ for stat_op in z .namelist ():
253
+ xtgeo_surf = xtgeo .surface_from_file (BytesIO (z .read (stat_op )))
254
+ xtgeo_surf .name = StatisticFunction .from_string_value (stat_op .upper ())
255
+ surfs .append (xtgeo_surf )
256
+ return surfs
0 commit comments