pylbo.utilities.toolbox

Module Contents

Functions

timethis(func)

get_axis_geometry(ax)

Retrieves the geometry of a given matplotlib axis.

get_values(array, which_values)

Determines which values to retrieve from an array.

add_pickradius_to_item(item, pickradius)

Makes a matplotlib artist pickable and adds a pickradius.

custom_enumerate(iterable[, start, step])

Does a custom enumeration with a given stepsize.

transform_to_list(→ list)

Transforms a given input argument obj to a list. If obj

transform_to_numpy(→ numpy.ndarray)

Transforms a given input argument obj to a numpy array.

solve_cubic_exact(a, b, c, d)

Solves a given cubic polynomial of the form

count_zeroes(eigfuncs)

Counts the number of zeroes of an array of complex eigenfunctions by looking at

invert_continuum_array(cont, r_gauss, sigma)

Finds the location of resonance for eigenmode solutions having a real part that

pylbo.utilities.toolbox.timethis(func)[source]
pylbo.utilities.toolbox.get_axis_geometry(ax)[source]

Retrieves the geometry of a given matplotlib axis.

Parameters:

ax (Axes) – The axis to retrieve the geometry from.

Returns:

The geometry of the given matplotlib axis.

Return type:

tuple

pylbo.utilities.toolbox.get_values(array, which_values)[source]

Determines which values to retrieve from an array.

Parameters:
  • array (numpy.ndarray) – The array with values.

  • which_values (str) –

    Can be one of the following:

    • ”average”: returns the average of the array

    • ”minimum”: returns the minimum of the array

    • ”maximum”: returns the maximum of the array

    If not supplied or equal to None, simply returns the array.

Returns:

array – Numpy array with values depending on the argument provided.

Return type:

numpy.ndarray

pylbo.utilities.toolbox.add_pickradius_to_item(item, pickradius)[source]

Makes a matplotlib artist pickable and adds a pickradius. We have to handle this separately, because for line2D items the method set_picker() is deprecated from version 3.3 onwards.

Parameters:
  • item (Artist) – The artist which will be made pickable

  • pickradius (int, float) – Sets the pickradius, which determines if something is “on” the picked point.

pylbo.utilities.toolbox.custom_enumerate(iterable, start=0, step=1)[source]

Does a custom enumeration with a given stepsize.

Parameters:
  • iterable (Iterable) – The iterable to iterate over.

  • start (int) – The starting value for enumerate.

  • step (int) – The stepsize between enumerate values.

Yields:
  • start (int) – The current index in iterable, incremented with step.

  • itr (~typing.Iterable) – The corresponding entry of iterable.

pylbo.utilities.toolbox.transform_to_list(obj: any) list[source]

Transforms a given input argument obj to a list. If obj is a Numpy-array or tuple, a cast to list() is invoked.

Parameters:

obj (any) – The object to transform.

Returns:

The object converted to a list.

Return type:

list

pylbo.utilities.toolbox.transform_to_numpy(obj: any) numpy.ndarray[source]

Transforms a given input argument obj to a numpy array.

Parameters:

obj (any) – The object to transform.

Returns:

The object transformed to a numpy array.

Return type:

numpy.ndarray

pylbo.utilities.toolbox.solve_cubic_exact(a, b, c, d)[source]

Solves a given cubic polynomial of the form \(ax^3 + bx^2 + cx + d = 0\) using the analytical cubic root formula instead of the general numpy.roots routine. From StackOverflow.

Parameters:
Returns:

roots – The three roots of the cubic polynomial as a Numpy array.

Return type:

np.ndarray(ndim=3, dtype=complex)

pylbo.utilities.toolbox.count_zeroes(eigfuncs)[source]

Counts the number of zeroes of an array of complex eigenfunctions by looking at sign changes of the real and imaginary part of the eigenfunctions. Doesn’t include the grid endpoints in the count, since the boundary conditions are automatically satisfied. This only becomes accurate for eigenfunctions with enough oscillations and is resolution dependent. Therefore, we take the minimum of the number of zeroes of the real and imaginary part.

Parameters:

eigfuncs (numpy.ndarray) – Array of eigenfunction arrays of complex numbers.

Returns:

nzeroes – Counter array containing the number of zeroes of the real or imaginary part of each input eigenfunction array.

Return type:

np.ndarray(dtype=int)

pylbo.utilities.toolbox.invert_continuum_array(cont, r_gauss, sigma)[source]

Finds the location of resonance for eigenmode solutions having a real part that might overlap with a continuum range.

Parameters:
  • cont (numpy.ndarray) – Array containing the range of a specific continuum. Automatically has the same length as r_gauss, since it has the same shape as the equilibrium fields used to calculate the continua. Can be complex, but only the resonance with the real part is calculated.

  • r_gauss (numpy.ndarray) – Array containing the grid on which equilibrium fields are defined.

  • sigma (complex) – An eigenvalue solution of the generalized eigenvalue problem.

Returns:

r_inv – The location where there is resonance between the eigenmode and the continuum. Returns None if there is no resonance with the specified continuum.

Return type:

None, float