pylbo.utilities.toolbox ======================= .. py:module:: pylbo.utilities.toolbox 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.solve_cubic_exact pylbo.utilities.toolbox.count_zeroes pylbo.utilities.toolbox.invert_continuum_array Module Contents --------------- .. 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:: 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) 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. :param eigfuncs: Array of eigenfunction arrays of complex numbers. :type eigfuncs: numpy.ndarray :returns: **nzeroes** -- Counter array containing the number of zeroes of the real or imaginary part of each input eigenfunction array. :rtype: np.ndarray(dtype=int) .. !! processed by numpydoc !! .. py:function:: invert_continuum_array(cont, r_gauss, sigma) Finds the location of resonance for eigenmode solutions having a real part that might overlap with a continuum range. :param cont: 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. :type cont: numpy.ndarray :param r_gauss: Array containing the grid on which equilibrium fields are defined. :type r_gauss: numpy.ndarray :param sigma: An eigenvalue solution of the generalized eigenvalue problem. :type sigma: complex :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. :rtype: None, float .. !! processed by numpydoc !!