utilities

geobipy.src.base.utilities.Ax(A, x)

Custom matrix vector multiplication for different representations of the matrix.

Parameters:
  • A (float or ndarray of floats) – A scalar, 1D array, or 2D array. If A is scalar, assume it represents a diagonal matrix with constant value. If A is 1D, assume it represents a diagonal matrix and do an element wise multiply. If A is 2D, take the dot product.

  • x (numpy.ndarray) – The 1D vector to multiply A with.

Returns:

out – Resultant matrix vector multiplication.

Return type:

ndarray of floats

geobipy.src.base.utilities.Det(A, N=1.0)

Custom function to compute the determinant of a matrix.

Parameters:
  • A (float or ndarray of floats) – If A is 2D: Use numpy.linalg.det obtain determinant. Uses LU factorization. If A is 1D: Take the cumulative product of the numbers, assumes A represents a diagonal matrix. If A is scalar: Take the number to power N, assumes A represents a diagonal matrix with constant value.

  • N (int, optional) – If A is a scalar, N is the number of elements in the constant valued diagonal.

Returns:

out – The determinant of the matrix.

Return type:

float

geobipy.src.base.utilities.Inv(A)

Custom matrix inversion upto 2 dimensions.

Parameters:

A (float or ndarray of floats) – A scalar, 1D array, or 2D array. If A is scalar, assume it represents a diagonal matrix with constant value and take the reciprocal. If A is 1D, assume it is the diagonal of a matrix: take reciprocal of entries. If A is 2D, invert using linalg.

Returns:

out – The inversion of A.

Return type:

float or ndarray of floats

geobipy.src.base.utilities.LogDet(A, N=1.0)

Custom function to get the natural logarithm of the determinant.

Parameters:
  • A (float or numpy.ndarray of floats) – If A is 2D: Use linalg.to obtain determinant. Uses LU factorization. If A is 1D: Take the cumulative product of the numbers, assumes A represents a diagonal matrix. If A is scalar: Take the number to power N, assumes A represents a diagonal matrix with constant value.

  • N (int, optional) – If A is a scalar, N is the number of elements in the constant valued diagonal.

Returns:

out – The logged determinant of the matrix.

Return type:

float

geobipy.src.base.utilities.cosSin1(x, y, a, p)

Simple function for creating tests.

geobipy.src.base.utilities.expReal(this)

Custom exponential of a number to allow a large negative exponent, overflow truncates without warning message.

Parameters:

this (float) – Real number to take exponential to.

Returns:

out – exp(this).

Return type:

float

geobipy.src.base.utilities.findFirstLastNotValue(this, values, invalid_val=-1)

Find the indices to the first and last non zero values along each axis

Parameters:

this (array_like) – An array of numbers

Returns:

out – Indices of the first and last non zero values along each axisgg

Return type:

array_like

geobipy.src.base.utilities.findFirstNonZeros(this, axis, invalid_val=-1)

Find the indices to the first non zero values

Parameters:
  • this (array_like) – An array of numbers

  • axis (int) – Axis along which to find first non zeros

  • invalid_val (int) – If all values along that axis are zero, use this value

Returns:

out – Indices of the first non zero values.

Return type:

ints

geobipy.src.base.utilities.findLastNonZeros(this, axis, invalid_val=-1)

Find the indices to the last non zero values

Parameters:
  • this (array_like) – An array of numbers

  • axis (int) – Axis along which to find last non zeros

  • invalid_val (int) – If all values along that axis are zero, use this value

Returns:

out – Indices of the last non zero values.

Return type:

ints

geobipy.src.base.utilities.findNans(this)

Find the indicies to NaN values.

Parameters:

this (array_like) – An array of numbers.

Returns:

out – Integer array to locations of nans.

Return type:

array_like

geobipy.src.base.utilities.findNotNans(this)

Find the indicies to non NaN values.

Parameters:

this (array_like) – An array of numbers.

Returns:

out – Integer array to locations of non nans.

Return type:

array_like

geobipy.src.base.utilities.getName(self, default='')

Tries to obtain an attached name to a variable.

If the variable is an object with a getName() procedure, that function will take precedence. If the variable does not have that procedure, a variable called name will be sought. If this fails, the specified default will be returned.

Parameters:

self (any type) – Any type of variable.

Returns:

out – A string containing the variable’s name or the default.

Return type:

str

geobipy.src.base.utilities.getNameUnits(self, defaultName='', defaultUnits='')

Tries to obtain any attached name and units to a variable. Any units are surrounded by round brackets.

Parameters:

self (any type) – Any type of variable.

Returns:

out – A string containing the variable’s name and units or the defaults.

Return type:

str

geobipy.src.base.utilities.getUnits(self, default='')

Tries to obtain an attached units to a variable.

If the variable is an object with a getUnits() procedure, that function will take precedence. If the variable does not have that procedure, a variable called units will be sought. If this fails, the specified default will be returned.

Parameters:

self (any type) – Any type of variable.

Returns:

out – A string containing the variable’s units or the default.

Return type:

str

geobipy.src.base.utilities.histogramEqualize(values, nBins=256)

Equalize the histogram of the values so that all colours have an equal amount

Parameters:
  • values (array_like) – Values to be equalized.

  • nBins (int) – Number of bins to use.

Returns:

  • res (array_like) – Equalized values

  • cdf (array_like) – Cumulative Density Function.

geobipy.src.base.utilities.interleave(a, b)

Interleave two arrays together like zip

Parameters:
  • a (array_like) – Interleave in [0::2]

  • b (array_like) – Interleave in [1::2]

Returns:

out – Interleaved arrays

Return type:

array_like

geobipy.src.base.utilities.isInt(this)

Check whether an entry is a subtype of an int

Parameters:

this (variable) – Variable to check whether an int or not

Returns:

out – Is or is not an int

Return type:

bool

geobipy.src.base.utilities.isIntorSlice(this)

Check whether an entry is a subtype of an int or a slice

Parameters:

this (variable) – Variable to check whether an int/slice or not

Returns:

out – Is or is not an int/slice

Return type:

bool

geobipy.src.base.utilities.isNumpy(x)

Test that the variable is a compatible numpy type with built ins like .ndim

Parameters:

x (anything) – A variable to check

Returns:

out – Whether the variable is a compatible numpy type

Return type:

bool

geobipy.src.base.utilities.mergeComplex(this)

Merge a 1D array containing a vertical concatenation of N real then N imaginary components into an N/2 complex 1D array.

Parameters:

this (numpy.ndarray of float64) – 1D array containing the vertical concatentation of real then imaginary values.

Returns:

out – The combined real and imaginary components into a complex 1D array.

Return type:

numpy.ndarray of complex128

geobipy.src.base.utilities.rosenbrock(x, y, a, b)

Generates values from the Rosenbrock function.

geobipy.src.base.utilities.smooth(x, a)

Smooth x by an LTI gaussian filter, forwards and backwards pass.

Parameters:
  • x (array_like) – signal to process

  • a (scalar between 0.0 and 1.0) – Weight

Returns:

out – Smoothed signal

Return type:

array_like

geobipy.src.base.utilities.splitComplex(this)

Splits a vector of complex numbers into a vertical concatenation of the real and imaginary components.

Parameters:

this (numpy.ndarray of complex128) – 1D array of complex numbers.

Returns:

out – Vertically concatenated real then imaginary components of this.

Return type:

numpy.ndarray of float64

geobipy.src.base.utilities.str_to_raw(s)

Helper function for latex

Parameters:

s (str) – String with special latex commands.

Returns:

out – String with latex special characters.

Return type:

str

geobipy.src.base.utilities.tanh(this)

Custom hyperbolic tangent, return correct overflow.

geobipy.src.base.utilities.trim_by_percentile(values, percent)

Trim an array by a given percentile from either end

Parameters:
  • values (array_like) – Values to trim

  • percent (float) – Percent from 0.0 to 100.0

Returns:

out – Trimmed values

Return type:

array_like