bruges.util package#


bruges.util.transformations module#

bruges.util.util module#

bruges.util.util.apply_along_axis(func_1d, arr, *args, **kwargs)[source]#

Apply 1D function across 2D slice as efficiently as possible.

Although np.apply_along_axis seems to do well enough, map usually seems to end up beig a bit faster.


func_1d (function) – the 1D function to apply, e.g. np.convolve. Should take 2 or more arguments: the

Example >>> apply_along_axes(np.convolve, reflectivity_2d, wavelet, mode=’same’)


Flags a method as deprecated. This decorator can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. :param instructions: A human-friendly string of instructions, such :type instructions: str :param as: ‘Please migrate to add_proxy() ASAP.’


The decorated function.

bruges.util.util.error_flag(pred, actual, dev=1.0, method=1)[source]#

Calculate the difference between a predicted and an actual curve and return a log flagging large differences based on a user-defined distance (in standard deviation units) from the mean difference.


Matteo Niccoli, 2018

  • predicted (ndarray) – predicted log.

  • actual (ndarray) – original log.

  • dev (float) – standard deviations to use, default 1

  • method (error calcluation) – default 1 1: difference between curves larger than mean difference plus dev 2: curve slopes have opposite sign. Will require depth log for .diff method 3: curve slopes of opposite sign OR difference larger than mean plus dev


flag (ndarray) = error flag curve


Extrapolate up and down an array from the first and last non-NaN samples.

E.g. Continue the first and last non-NaN values of a log up and down.


a (ndarray) – The array to treat.


The treated array.

Return type


bruges.util.util.moving_average(a, length, mode='same')[source]#

Computes the mean in a moving window using convolution. For an alternative, as well as other kinds of average (median, mode, etc.), see bruges.filters.


>>> test = np.array([1,1,9,9,9,9,9,2,3,9,2,2,np.nan,1,1,1,1])
>>> moving_average(test, 5, mode='same')
array([ 2.2,  4. ,  5.8,  7.4,  9. ,  7.6,  6.4,  6.4,  5. ,  3.6,  nan,
        nan,  nan,  nan,  nan,  0.8,  0.6])
bruges.util.util.moving_avg_conv(a, length, mode='same')[source]#

Moving average via convolution. Keeping it for now for compatibility.

bruges.util.util.moving_avg_fft(a, length, mode='same')[source]#

Moving average via FFT convolution. Keeping it for now for compatibility.

bruges.util.util.nearest(a, num)[source]#

Finds the array’s nearest value to a given num.

  • a (ndarray) – An array.

  • num (float) – The value to find the nearest to.


float. The normalized array.

Calculates the next nearest power of 2 to the input. Uses

2**ceil( log2( num ) ).


num (number) – The number to round to the next power if two.


number. The next power of 2 closest to num.

bruges.util.util.normalize(a, new_min=0.0, new_max=1.0)[source]#

Normalize an array to [0,1] or to arbitrary new min and max.

  • a (ndarray) – An array.

  • new_min (float) – The new min to scale to, default 0.

  • new_max (float) – The new max to scale to, default 1.


ndarray. The normalized array.

bruges.util.util.power(start, stop, num)[source]#

Nonlinear space following a power function.

bruges.util.util.rms(a, axis=None)[source]#

Calculates the RMS of an array.

  • a (ndarray) –

  • axis (int) – the RMS for the whole array is computed.


The RMS of the array along the desired axis or axes.

Return type


bruges.util.util.root(start, stop, num)[source]#

Nonlinear space following a sqrt function.

bruges.util.util.sigmoid(start, stop, num)[source]#

Nonlinear space following a logistic function.

The function is asymptotic; the parameters used in the sigmoid gets within 0.5% of the target thickness in a wedge increasing from 0 to 2x the original thickness.


Top and tail all arrays to the non-NaN extent of the first array.

E.g. crop the NaNs from the top and tail of a well log.


arrays (list) – A list of arrays to treat.


A list of treated arrays.

Return type


Module contents#