@@ -95,7 +95,7 @@ def slice_cube_window(self, cube, zsurf=None, other=None,
9595 zrange = 10 , ndiv = None , attribute = 'max' ,
9696 maskthreshold = 0.1 , snapxy = False ,
9797 showprogress = False , deadtraces = True ,
98- deletecube = False ):
98+ deletecube = False , algorithm = 1 ):
9999
100100 """Slice Cube with a window and extract attribute(s)
101101
@@ -140,12 +140,18 @@ def slice_cube_window(self, cube, zsurf=None, other=None,
140140 # This will run slice in a loop within a window. Then, numpy methods
141141 # are applied to get the attributes
142142
143- if other is None :
143+ if other is None and algorithm == 1 :
144144 attvalues = _slice_constant_window (this , cube , sampling , zrange ,
145145 ndiv , mask , attrlist , snapxy ,
146146 showprogress = showprogress ,
147147 deadtraces = deadtraces ,
148148 deletecube = deletecube )
149+ elif other is None and algorithm == 2 :
150+ attvalues = _slice_constant_window2 (this , cube , sampling , zrange ,
151+ ndiv , mask , attrlist , snapxy ,
152+ showprogress = showprogress ,
153+ deadtraces = deadtraces ,
154+ deletecube = deletecube )
149155 else :
150156 attvalues = _slice_between_surfaces (this , cube , sampling , other ,
151157 other_position , zrange ,
@@ -157,19 +163,20 @@ def slice_cube_window(self, cube, zsurf=None, other=None,
157163
158164 results = dict ()
159165
160- for attr in attrlist :
161- scopy = self .copy ()
162- scopy .values = attvalues [attr ]
163- results [attr ] = scopy
164-
165- # for backward compatibility
166- if qattr_is_string :
167- self .values = attvalues [attrlist [0 ]]
168- return None
166+ if algorithm != 2 :
167+ for attr in attrlist :
168+ scopy = self .copy ()
169+ scopy .values = attvalues [attr ]
170+ results [attr ] = scopy
169171
170- return results
172+ # for backward compatibility
173+ if qattr_is_string :
174+ self .values = attvalues [attrlist [0 ]]
175+ return None
171176
172- logger .info ('Mean of cube attribute is {}' .format (self .values .mean ()))
177+ return results
178+ else :
179+ return None
173180
174181
175182def _slice_constant_window (this , cube , sampling , zrange ,
@@ -224,6 +231,77 @@ def _slice_constant_window(this, cube, sampling, zrange,
224231 return attvalues # this is dict with numpies, one per attribute
225232
226233
234+ def _slice_constant_window2 (this , cube , sampling , zrange ,
235+ ndiv , mask , attrlist , snapxy , showprogress = False ,
236+ deadtraces = True , deletecube = False ):
237+ """Slice a window, (constant in vertical extent); faster and better
238+ algorithm (algorithm2).
239+ """
240+
241+ zincr = zrange / float (ndiv )
242+ ztmp = this .copy ()
243+ ztmp .values = ztmp .values - zincr * (ndiv + 1 )
244+
245+ if mask :
246+ opt2 = 0
247+ else :
248+ opt2 = 1
249+
250+ if deadtraces :
251+ # set dead traces to cxtgeo UNDEF -> special treatment in the C code
252+ olddead = cube .values_dead_traces (_cxtgeo .UNDEF )
253+
254+ cubeval1d = np .ravel (cube .values , order = 'C' )
255+
256+ usesampling = 0
257+ if sampling == 'trilinear' :
258+ usesampling = 1
259+ if snapxy :
260+ usesampling = 2
261+
262+ # allocate the attribute maps
263+ nattr = 5 # predefined attributes
264+ nsurf = ztmp .ncol * ztmp .nrow * nattr
265+
266+ istat , attrmaps = _cxtgeo .surf_slice_cube_window (
267+ cube .ncol ,
268+ cube .nrow ,
269+ cube .nlay ,
270+ cube .xori ,
271+ cube .xinc ,
272+ cube .yori ,
273+ cube .yinc ,
274+ cube .zori ,
275+ cube .zinc ,
276+ cube .rotation ,
277+ cube .yflip ,
278+ cubeval1d ,
279+ ztmp .ncol ,
280+ ztmp .nrow ,
281+ ztmp .xori ,
282+ ztmp .xinc ,
283+ ztmp .yori ,
284+ ztmp .yinc ,
285+ ztmp .yflip ,
286+ ztmp .rotation ,
287+ ztmp .get_values1d (),
288+ zincr ,
289+ ndiv * 2 ,
290+ nsurf ,
291+ nattr ,
292+ usesampling ,
293+ opt2 ,
294+ xtg_verbose_level )
295+
296+ if istat != 0 :
297+ logger .warning ('Problem, ISTAT = {}' .format (istat ))
298+
299+ if deadtraces :
300+ cube .values_dead_traces (olddead ) # reset value for dead traces
301+
302+ return istat
303+
304+
227305def _slice_between_surfaces (this , cube , sampling , other , other_position ,
228306 zrange , ndiv , mask , attrlist , mthreshold ,
229307 snapxy , showprogress = False , deadtraces = True ,
0 commit comments