scotty.density_fit module#

class scotty.density_fit.DensityFit(poloidal_flux_enter)#

Bases: object

Base class for density parameterisations.

Subclasses should implement _fit_impl which takes a 1D array of the poloidal flux and returns the density at those points. This base class will handle setting the density to zero outside the plasma.

Parameters

poloidal_flux_enter (float) – Flux at edge of plasma. Density is zero outside this flux label

__call__(poloidal_flux)#

Returns the interpolated density at poloidal_flux points.

Parameters

poloidal_flux (numpy.typing.ArrayLike) –

Return type

numpy.typing.ArrayLike

scotty.density_fit.DensityFitLike#

A callable that can parameterise density in 1D

alias of Callable[[Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]]], Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]]]

class scotty.density_fit.PolynomialFit(poloidal_flux_enter, *coefficients)#

Bases: scotty.density_fit.DensityFit

Fit using a \(m\)-th order polynomial:

\[n_e(\psi) = \sum_{i=0,m} a_i \psi^i\]

where \(m+1\) is the number of coefficients

Parameters
  • poloidal_flux_enter (float) – Poloidal flux where solver starts and/or boundary conditions are applied; density has to be zero in the current implementation (\(\psi_0\) above)

  • coefficients – List of polynomial coefficients, from highest degree to the constant term

class scotty.density_fit.QuadraticFit(poloidal_flux_enter, ne_0, psi_0=None)#

Bases: scotty.density_fit.DensityFit

Quadratic fit

Given the density on the magnetic axis, \(n_{e0}\), and the poloidal flux where the density goes to zero, \(\psi_0\), the density is given by:

\[n_e(\psi) = n_{e0} - \frac{n_{e0}}{\psi_0}\psi^2\]
Parameters
  • poloidal_flux_enter (float) – Poloidal flux where density goes to zero (\(\psi_0\) above)

  • ne_0 (float) – Density at magnetic axis (\(n_{e0} \equiv n_e(\psi = 0)\))

  • psi_0 (Optional[float]) –

    If passed, this must be the same as poloidal_flux_enter

    Deprecated since version 2.4.0: psi_0 can be safely dropped

class scotty.density_fit.SmoothingSplineFit(poloidal_flux_enter, poloidal_flux, density, order=5, smoothing=None)#

Bases: scotty.density_fit.DensityFit

1D smoothing spline using scipy.interpolate.UnivariateSpline

Parameters
  • poloidal_flux_enter (float) –

  • poloidal_flux (ArrayLike) –

  • density (ArrayLike) –

  • order (int) –

  • smoothing (Optional[float]) –

classmethod from_dat_file(poloidal_flux_enter, filename, order=5, smoothing=None)#

Create a SmoothingSplineFit using parameters from text file.

File should contain electron density as a function of poloidal flux label in units of \(10^{19} \mathrm{m}^{-3}\).

The first line is ignored, the rest of the file is expected to be in two columns: the first should contain the radial coordinate (\(\sqrt(\psi)\)), the second the electron density. The columns should be separated by whitespace.

101
0.00000000e+00 4.00000000e+00
1.00000000e-02 3.99960000e+00
2.00000000e-02 3.99840000e+00
...
Parameters
Return type

scotty.density_fit.SmoothingSplineFit

class scotty.density_fit.StefanikovaFit(poloidal_flux_enter, a_height, a_width, a_exp, b_height, b_SOL, b_width, b_slope, b_pos)#

Bases: scotty.density_fit.DensityFit

Fit according to Stefanikova et al (2016) 1

\[\begin{split}F_\mathrm{ped}(r, b) &= \frac{b_\mathrm{height} − b_\mathrm{SOL}}{2} \left[ \mathrm{mtanh}\left( \frac{b_\mathrm{pos} − r}{2 b_\mathrm{width}}, b_\mathrm{slope} \right) + 1 \right] + b_\mathrm{SOL} \\ \mathrm{mtanh}(x, b_\mathrm{slope}) &= \frac{(1+b_\mathrm{slope}x)e^x - e^{−x}}{e^x+e^{−x}} \\ F_\mathrm{full}(r, a, b) &= F_\mathrm{ped}(r, b) + \left[ a_\mathrm{height} - F_\mathrm{ped}(r, b) \right] \cdot \exp\left(-(\frac{r}{a_\mathrm{width}})^{a_\mathrm{exp}}\right)\end{split}\]

Adapted from code by Simon Freethy

Footnotes

1

https://doi.org/10.1063/1.4961554

Parameters
class scotty.density_fit.TanhFit(poloidal_flux_enter, ne_0, ne_1, psi_0=None)#

Bases: scotty.density_fit.DensityFit

Fit using \(\tanh\):

\[n_e(\psi) = n_{e0} \tanh\left(n_{e1} (\psi - \psi_0)\right)\]
Parameters
  • poloidal_flux_enter (float) – Poloidal flux where density goes to zero (\(\psi_0\) above)

  • ne_0 (float) – (Asymptotic) density at magnetic axis (\(n_{e0} \le n_e(\psi = 0)\))

  • ne_1 (float) – Second fitting parameter

  • psi_0 (Optional[float]) –

    If passed, this must be the same as poloidal_flux_enter

    Deprecated since version 2.4.0: psi_0 can be safely dropped

scotty.density_fit.density_fit(method, poloidal_flux_enter, parameters, filename=None)#

Create a density profile parameterisation

Parameters
  • method (Optional[str]) – Name of density fit parameterisation

  • poloidal_flux_enter (float) – Poloidal flux label where density goes to zero

  • parameters (Sequence) – List of parameters passed to density fit

  • filename (Optional[Union[os.PathLike, str]]) –

Return type

scotty.density_fit.DensityFit