Adding Your Own Plugins

The code archetecture allows for the additon of plugins to calculate the Gordeyev integral. The plugins are required to be in the “plugins” folder. The script find_gord_plugs.py can move the file to the correct folder. The plugin must have the following naming convention gord_<NAME>.py.

Plugin Format

Each plugin is required to have a class name GordPlug with a method calcgordeyev. The inputs are a numpy array that is defined by the user. The basic inputs will be the dataline, K value of the radar in rad/m, omeg the frequency vector as a numpy array that the spectrum is evaluated over in rad/s and a boolian called dFlag to determine if any print statements will be used. The dataline has to include the following [Ns, Ts, qs, vs, ms], where Ns is species number density in m^-3, Ts is the species temperature in K, vs is the Doppler velocity in m/s, qs is the charge, and ms is the atomic weight. The returned data must be four outputs: (gord, Ts, Ns, qs,omeg_s) which is the resulting Gordeyev integral evaluated over the frequency space, the species temperature, the species density, the charge, and the doppler corrected radian frequency. The rest of the inputs can be defined as neccesary as the getspec method has a kwargs input. The user needs to name their inputs that are needed.

import numpy as np
import scipy.special as sp
import scipy.constants as spconst

import scipy.special as sp_spec


class GordPlug:

    def calcgordeyev(self, dataline, K, omeg, dFlag, *args, **kwargs):
        """
        Direct calculation of Gordeyev integral with no magnetic field or collisions.

        Parameters
        ----------
        dataline : ndarray
            A numpy array of length that holds the plasma parameters needed to create the spectrum. Each row of the array will have the following set up.
                [Ns, Ts, Vs, ms, nus]
                Ns - The density of the species in m^-3
                Ts - Temperature of the species in degrees K
                Vs - The Doppler velocity in m/s.
                qs - The charge of the species in elementary charges. (Value will be replaced for the electrons)
                ms - Mass of the species in kg.
        alphadeg : float
            The magnetic aspect angle in radians.
        K : float
            K value of the radar in rad/m
        omeg : ndarray
            Radian frequency vector the integral will be evaluated over.
        dFlag : float
            A debug flag, if set true will output debug text. Default is false.

        Returns
        -------
        gord : ndarray
            The result of the Gordeyev integral over Doppler corrected radian frequency
        hs : ndarray
            The Debye length in m.
        Ns : ndarray
            The density of the species in m^-3
        qs : float
            The charge of the species in elementary charges.
        omeg_s : ndarray
            An array of the Doppler corrected radian frequency

        """
        assert (
            len(dataline) >= 5
        ), "The dataline input needs to be length of at least 4 elements."
        (Ns, Ts, Vs, qs, ms) = dataline[:5]

        assert (
            ms > 0 and ms < 1e-20
        ), "Atomic masses should be very small and greater than 0."

        C = np.sqrt(spconst.k * Ts / ms)
        omeg_s = omeg - K * Vs
        theta = omeg_s / (K * C * np.sqrt(2.0))

        num_g = np.sqrt(np.pi) * np.exp(-(theta**2)) - 1j * 2.0 * sp_spec.dawsn(theta)
        den_g = K * C * np.sqrt(2)
        gord = num_g / den_g

        if dFlag:
            print("\t No collisions No magnetic field,again")
        return (gord, Ts, Ns, qs, omeg_s)

Finding and Importing Plugin

After the plugin is created you have to add it to the plugin folder. There are other possible ways of importing the plugin but for now the easiest way is to use the find_gord_plugs.py script.

The script does two things, first it imports any avalible plugins and lists the locations along with its directory.

python find_gord_plugs.py
Pluggin directory: <repolocation>/ISRSpectrum/plugins

Plugin name: simple
Location: <repolocation>/ISRSpectrum/plugins/gord_simple.py

Plugin name: default
Location: <repolocation>/ISRSpectrum/plugins/gord_default.py

It’s second purpost is copy a users plugin and put it in the directory where it can be found.

python find_gord_plugs.py -f <filenames>

The script can be run again to confirm that the plug in was copied and can now be imported.

One extra note, when using ipython it seems that the plugins are not automatically reloaded when the reload magic command. Thus you need to reload the module again using the importlib method reload.