pylbo.utilities.toolbox

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.

reduce_to_unique_array(→ numpy.ndarray)

Reduces a given array to its unique values, preserving the order.

get_all_eigenfunction_names(→ numpy.ndarray[str])

Merges the regular and derived eigenfunction names into a unique array,

get_maximum_eigenvalue(→ complex)

Calculates the maximum eigenvalue of a given array of eigenvalues.

solve_cubic_exact(a, b, c, d)

Solves a given cubic polynomial of the form

count_zeroes(eigfuncs[, real])

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

find_resonance_location(continuum, grid, omega)

Finds the resonance location between omega and the continuum. For example, if

is_custom_grid(grid)

Checks if a given grid is a custom grid, i.e. not equidistant.

Module Contents

pylbo.utilities.toolbox.timethis(func)
pylbo.utilities.toolbox.get_axis_geometry(ax)

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)

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)

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)

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

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

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.reduce_to_unique_array(array: numpy.ndarray) numpy.ndarray

Reduces a given array to its unique values, preserving the order.

Parameters:

array (numpy.ndarray) – The array to reduce.

Returns:

The array with unique values.

Return type:

numpy.ndarray

pylbo.utilities.toolbox.get_all_eigenfunction_names(data: pylbo.data_containers.LegolasDataContainer) numpy.ndarray[str]

Merges the regular and derived eigenfunction names into a unique array, preserving order.

Parameters:

data (LegolasDataContainer) – The data container containing the eigenfunction names.

Returns:

The array with unique eigenfunction names.

Return type:

numpy.ndarray

pylbo.utilities.toolbox.get_maximum_eigenvalue(eigenvalues: numpy.ndarray[complex], real: bool = True, re_range: Tuple[float, float] = None) complex

Calculates the maximum eigenvalue of a given array of eigenvalues. The real or imaginary part is used, depending on the real argument. If a range is specified, the maximum eigenvalue is calculated within that range on the real axis.

Parameters:
  • eigenvalues (numpy.ndarray(dtype=complex)) – The array of eigenvalues.

  • real (bool) – If True, the real part of the eigenvalues is used. Imaginary part otherwise.

  • re_range (tuple(float, float)) – The range on the real axis to calculate the maximum eigenvalue. Defaults to None, which means all eigenvalues are considered.

Returns:

The maximum eigenvalue.

Return type:

complex

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

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, real=True)

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. Excludes the eigenfunction boundaries.

Parameters:
  • eigfuncs (numpy.ndarray(dtype=complex)) – Array of eigenfunction arrays of complex numbers.

  • real (bool) – If True, counts the number of zeroes of the real part of the eigenfunctions. If False, counts the number of zeroes of the imaginary part.

Returns:

The number of zeroes of each eigenfunction.

Return type:

np.ndarray(dtype=int)

pylbo.utilities.toolbox.find_resonance_location(continuum, grid, omega)

Finds the resonance location between omega and the continuum. For example, if the continuum is given by [5, 6, 7, 8, 9, 10] and the grid is equal to [0, 1, 2, 3, 4, 5], then for an omega = 9 the resonance location is 4. For an omega equal to 8.5 the resonance location is 3.5. For an omega outside of the continuum the resonance location is None. If the continuum array is not monotone, then the resonance location is interpolated between the first matched interval.

Parameters:
  • continuum (numpy.ndarray(dtype=complex)) – Array containing the range of a specific continuum. Can be complex, but only the resonance with the real part is calculated.

  • grid (numpy.ndarray) – The grid on which the continuum is defined.

  • omega (complex) – A given eigenvalue.

Returns:

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

Return type:

None, np.ndarray(float)

pylbo.utilities.toolbox.is_custom_grid(grid)

Checks if a given grid is a custom grid, i.e. not equidistant.

Parameters:

grid (numpy.ndarray) – The grid to test.

Returns:

True if the grid is a custom grid, False otherwise.

Return type:

bool