8.4.4. pymodaq_utils.array_manipulation module

Created on Mon March 03 2021 author: Sebastien Weber

pymodaq_utils.array_manipulation.arglimit(y, threshold=0.001, padding=0.0, normalize=True)[source]

Returns the first and last index where y >= threshold * max(abs(y)).

pymodaq_utils.array_manipulation.crop_array_to_axis(x, y, M, cropbox)[source]

crops an array M with given cropbox as a tuple (xmin,xmax,ymin,ymax).

Parameters:
  • x (vector)

  • y (vector)

  • M (2D array)

  • cropbox (4 elements tuple containing (xmin,xmax,ymin,ymax))

Returns:

  • x_c (croped x vector)

  • y_c (croped y  vector)

  • M_c (croped 2D M array)

pymodaq_utils.array_manipulation.crop_vector_to_axis(x, V, xlim)[source]

crops a vector V with given x axis vector to a given xlim tuple

Parameters:
  • x (vector)

  • V (vector)

  • xlim (tuple containing (xmin,xmax))

Returns:

  • x_c (vector)

  • V_c (vector)

pymodaq_utils.array_manipulation.find(x, condition, n=1)[source]

Return the index of the nth element that fulfills the condition.

pymodaq_utils.array_manipulation.find_index(x, threshold)[source]

find_index finds the index ix such that x(ix) is the closest from threshold

Parameters:
  • x (vector)

  • threshold (list of scalar)

Returns:

out – out=[(ix0,xval0),(ix1,xval1),…]

Return type:

list of 2-tuple containing ix,x[ix]

pymodaq_utils.array_manipulation.find_rising_edges(x, threshold)[source]

find_rising_edges finds the index ix such that x(ix) is the closest from threshold and values are increasing

Parameters:
  • x (vector)

  • threshold (list of scalar)

Returns:

out – out=[(ix0,xval0),(ix1,xval1),…]

Return type:

list of 2-tuple containing ix,x[ix]

pymodaq_utils.array_manipulation.interp1D(x, M, xlin, axis=1)[source]

same as numpy interp function but works on 2D array you have to specify the axis over which to do the interpolation kwargs refers to the numpy interp kwargs returns both xlin and the new 2D array Minterp

pymodaq_utils.array_manipulation.limit(x, y=None, threshold=0.001, padding=0.25, extend=True)[source]

Returns the maximum x-range where the y-values are sufficiently large.

Parameters:
  • x (array_like) – The x values of the graph.

  • y (array_like, optional) – The y values of the graph. If None the maximum range of x is used. That is only useful if padding > 0.

  • threshold (float) – The threshold relative to the maximum of y of values that should be included in the bracket.

  • padding (float) – The relative padding on each side in fractions of the bracket size.

  • extend (bool, optional) – Signals if the returned range can be larger than the values in x. Default is True.

Returns:

xl, xr – Lowest and biggest value of the range.

Return type:

float

pymodaq_utils.array_manipulation.linspace_this_image(x, M, axis=1, Npts=None)[source]

Given a vector x and a 2D array M, it returns an array vector xlin where xlin is a linearised version of x on the same interval and with the same size. it returns as well a 2D array Minterp interpolated on the new xlin vector along the specified axis.

Parameters:
  • x ((vector))

  • M ((2D array))

  • axis ((int))

  • Npts ((int) size of the linear vector (optional))

Returns:

  • xlin (vector)

  • Minterp (2D array)

pymodaq_utils.array_manipulation.linspace_this_vect(x, y=None, Npts=None)[source]

Given a vector x, it returns a vector xlin where xlin is a linearised version of x on the same interval and with the same size. if args is provided it is a y vector and the function returns both xlin and ylin where ylin is a linear interpolation of y on this new xlin axis

Parameters:
  • x ((ndarray))

  • y ((ndarray) optional)

  • Npts ((int) size of the linear vector (optional))

Returns:

  • xlin (vector)

  • (ylin (vector) optional if args is provided)

pymodaq_utils.array_manipulation.marginals(data, normalize=False, axes=None)[source]

Calculates the marginals of the data array.

axes specifies the axes of the marginals, e.g., the axes on which the sum is projected.

If axis is None a list of all marginals is returned.

pymodaq_utils.array_manipulation.max_ind(x, axis=None)[source]

returns the max value in a vector or array and its index (in a tuple)

Parameters:
  • x (vector)

  • axis (optional dimension aginst which to normalise)

Returns:

  • ind_max (index of the maximum value)

  • max_val (maximum value)

pymodaq_utils.array_manipulation.min_ind(x, axis=None)[source]

returns the min value in a vector or array and its index (in flattened array)

Parameters:
  • x (vector)

  • axis (optional dimension to check the function)

Returns:

  • ind_min (index of the minimum value)

  • min_val (minimum value)

pymodaq_utils.array_manipulation.random_step(start, stop, step)[source]
pymodaq_utils.array_manipulation.rescale(x, window=[0.0, 1.0])[source]

Rescales a numpy array to the range specified by window.

Default is [0, 1].