bruges.util package#
Submodules#
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.
- Parameters
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’)
- bruges.util.util.deprecated(instructions)[source]#
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.’
- Returns
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.
- Author:
Matteo Niccoli, 2018
- Parameters
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
- Returns
flag (ndarray) = error flag curve
- bruges.util.util.extrapolate(a)[source]#
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.
- Parameters
a (ndarray) – The array to treat.
- Returns
The treated array.
- Return type
ndarray
- 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.
Example
>>> 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.
- Parameters
a (ndarray) – An array.
num (float) – The value to find the nearest to.
- Returns
float. The normalized array.
- bruges.util.util.next_pow2(num)[source]#
- Calculates the next nearest power of 2 to the input. Uses
2**ceil( log2( num ) ).
- Parameters
num (number) – The number to round to the next power if two.
- Returns
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.
- Parameters
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.
- Returns
ndarray. The normalized array.
- bruges.util.util.rms(a, axis=None)[source]#
Calculates the RMS of an array.
- Parameters
a (ndarray) –
axis (int) – the RMS for the whole array is computed.
- Returns
The RMS of the array along the desired axis or axes.
- Return type
ndarray