pylbo.utilities.toolbox
Functions
|
|
Retrieves the geometry of a given matplotlib axis. |
|
|
Determines which values to retrieve from an array. |
|
Makes a matplotlib artist pickable and adds a pickradius. |
|
Does a custom enumeration with a given stepsize. |
|
Transforms a given input argument obj to a list. If obj |
|
Transforms a given input argument obj to a numpy array. |
|
Reduces a given array to its unique values, preserving the order. |
|
Merges the regular and derived eigenfunction names into a unique array, |
|
Calculates the maximum eigenvalue of a given array of eigenvalues. |
|
Solves a given cubic polynomial of the form |
|
Counts the number of zeroes of an array of complex eigenfunctions by looking at |
|
Finds the resonance location between sigma and the continuum. For example, if |
Module Contents
- pylbo.utilities.toolbox.get_axis_geometry(ax)[source]
Retrieves the geometry of a given matplotlib axis.
- 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:
- 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.
- pylbo.utilities.toolbox.custom_enumerate(iterable, start=0, step=1)[source]
Does a custom enumeration with a given stepsize.
- Parameters:
- 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:
- 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:
- pylbo.utilities.toolbox.reduce_to_unique_array(array: numpy.ndarray) numpy.ndarray [source]
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:
- pylbo.utilities.toolbox.get_all_eigenfunction_names(data: pylbo.data_containers.LegolasDataContainer) numpy.ndarray[str] [source]
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:
- pylbo.utilities.toolbox.get_maximum_eigenvalue(eigenvalues: numpy.ndarray[complex], real: bool = True, re_range: Tuple[float, float] = None) complex [source]
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:
- 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, real=True)[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. 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, sigma)[source]
Finds the resonance location between sigma 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 a sigma = 9 the resonance location is 4. For a sigma equal to 8.5 the resonance location is 3.5. For a sigma 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.
sigma (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)