:py:mod:`pylbo.utilities.toolbox` ================================= .. py:module:: pylbo.utilities.toolbox Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: pylbo.utilities.toolbox.timethis pylbo.utilities.toolbox.get_axis_geometry pylbo.utilities.toolbox.get_values pylbo.utilities.toolbox.add_pickradius_to_item pylbo.utilities.toolbox.custom_enumerate pylbo.utilities.toolbox.transform_to_list pylbo.utilities.toolbox.transform_to_numpy pylbo.utilities.toolbox.reduce_to_unique_array pylbo.utilities.toolbox.get_all_eigenfunction_names pylbo.utilities.toolbox.get_maximum_eigenvalue pylbo.utilities.toolbox.solve_cubic_exact pylbo.utilities.toolbox.count_zeroes pylbo.utilities.toolbox.find_resonance_location .. py:function:: timethis(func) .. py:function:: get_axis_geometry(ax) Retrieves the geometry of a given matplotlib axis. :param ax: The axis to retrieve the geometry from. :type ax: ~matplotlib.axes.Axes :returns: The geometry of the given matplotlib axis. :rtype: tuple .. !! processed by numpydoc !! .. py:function:: get_values(array, which_values) Determines which values to retrieve from an array. :param array: The array with values. :type array: numpy.ndarray :param which_values: 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. :type which_values: str :returns: **array** -- Numpy array with values depending on the argument provided. :rtype: numpy.ndarray .. !! processed by numpydoc !! .. py:function:: 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 :meth:`~matplotlib.axes.Axes.set_picker` is deprecated from version 3.3 onwards. :param item: The artist which will be made pickable :type item: ~matplotlib.artist.Artist :param pickradius: Sets the pickradius, which determines if something is "on" the picked point. :type pickradius: int, float .. !! processed by numpydoc !! .. py:function:: custom_enumerate(iterable, start=0, step=1) Does a custom enumeration with a given stepsize. :param iterable: The iterable to iterate over. :type iterable: ~typing.Iterable :param start: The starting value for enumerate. :type start: int :param step: The stepsize between enumerate values. :type step: int :Yields: * **start** (*int*) -- The current index in `iterable`, incremented with `step`. * **itr** (*~typing.Iterable*) -- The corresponding entry of `iterable`. .. !! processed by numpydoc !! .. py:function:: 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. :param obj: The object to transform. :type obj: any :returns: The object converted to a list. :rtype: list .. !! processed by numpydoc !! .. py:function:: transform_to_numpy(obj: any) -> numpy.ndarray Transforms a given input argument `obj` to a numpy array. :param obj: The object to transform. :type obj: any :returns: The object transformed to a numpy array. :rtype: numpy.ndarray .. !! processed by numpydoc !! .. py:function:: reduce_to_unique_array(array: numpy.ndarray) -> numpy.ndarray Reduces a given array to its unique values, preserving the order. :param array: The array to reduce. :type array: numpy.ndarray :returns: The array with unique values. :rtype: numpy.ndarray .. !! processed by numpydoc !! .. py:function:: 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. :param data: The data container containing the eigenfunction names. :type data: LegolasDataContainer :returns: The array with unique eigenfunction names. :rtype: numpy.ndarray .. !! processed by numpydoc !! .. py:function:: 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. :param eigenvalues: The array of eigenvalues. :type eigenvalues: numpy.ndarray(dtype=complex) :param real: If `True`, the real part of the eigenvalues is used. Imaginary part otherwise. :type real: bool :param re_range: The range on the real axis to calculate the maximum eigenvalue. Defaults to None, which means all eigenvalues are considered. :type re_range: tuple(float, float) :returns: The maximum eigenvalue. :rtype: complex .. !! processed by numpydoc !! .. py:function:: solve_cubic_exact(a, b, c, d) Solves a given cubic polynomial of the form :math:`ax^3 + bx^2 + cx + d = 0` using the analytical cubic root formula instead of the general `numpy.roots` routine. From `StackOverflow `_. :param a: Cubic coefficient. :type a: int, float, complex :param b: Quadratic coefficient. :type b: int, float, complex :param c: Linear coefficient. :type c: int, float, complex :param d: Constant term :type d: int, float, complex :returns: **roots** -- The three roots of the cubic polynomial as a Numpy array. :rtype: np.ndarray(ndim=3, dtype=complex) .. !! processed by numpydoc !! .. py:function:: 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. :param eigfuncs: Array of eigenfunction arrays of complex numbers. :type eigfuncs: numpy.ndarray(dtype=complex) :param real: 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. :type real: bool :returns: The number of zeroes of each eigenfunction. :rtype: np.ndarray(dtype=int) .. !! processed by numpydoc !! .. py:function:: find_resonance_location(continuum, grid, sigma) 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. :param continuum: Array containing the range of a specific continuum. Can be complex, but only the resonance with the real part is calculated. :type continuum: numpy.ndarray(dtype=complex) :param grid: The grid on which the continuum is defined. :type grid: numpy.ndarray :param sigma: A given eigenvalue. :type sigma: complex :returns: The position where there is resonance between the eigenmode and the continuum. Returns None if there is no resonance with the specified continuum. :rtype: None, np.ndarray(float) .. !! processed by numpydoc !!