operator Module

class indica.operators.AsymmetryParameter(sess=<indica.session.Session object>)[source]

Calculate the asymmetry parameter from toroidal rotation.

Returns

xarray.DataArray containing asymmetry_parameter for a given impurity element

Return type

asymmetry_parameter

Parameters

sess (indica.session.Session) –

__call__(toroidal_rotations, ion_temperature, main_ion, impurity, Zeff, electron_temp)[source]

Calculates the asymmetry parameter from the toroidal rotation frequency.

Parameters
Returns

xarray.DataArray containing data for asymmetry parameters for the given impurity element

Return type

asymmetry_parameter

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Any, …]

class indica.operators.BolometryDerivation(flux_surfs, LoS_bolometry_data, t_arr, impurity_densities, frac_abunds, impurity_elements, electron_density, main_ion_power_loss, impurities_power_loss, sess=<indica.session.Session object>)[source]

Class to hold relevant variables and functions relating to the derivation of bolometry data from plasma quantities (densities, temperatures, etc.)

Parameters
  • flux_surfaces – FluxSurfaceCoordinates object representing polar coordinate systems using flux surfaces for the radial coordinate.

  • LoS_bolometry_data (Sequence) – Line-of-sight bolometry data in the same format as given in: tests/unit/operator/KB5_Bolometry_data.py

  • t_arr (xarray.core.dataarray.DataArray) – Array of time values to interpolate the (rho, theta) grids on. xarray.DataArray with dimensions (t).

  • impurity_densities (xarray.core.dataarray.DataArray) – Densities for all impurities (including the extrapolated smooth density of the impurity in question), xarray.DataArray with dimensions (elements, rho, theta, t).

  • frac_abunds (Sequence) – Fractional abundances list of fractional abundances (an xarray.DataArray for each impurity) dimensions of each element in the list are (ion_charges, rho, t).

  • impurity_elements (Sequence) – List of element symbols(as strings) for all impurities.

  • electron_density (xarray.core.dataarray.DataArray) – xarray.DataArray of electron density, xarray.DataArray wit dimensions (rho, t)

  • main_ion_power_loss (xarray.core.dataarray.DataArray) – Power loss associated with the main ion (eg. deuterium), xarray.DataArray with dimensions (rho, t)

  • main_ion_density – Density profile for the main ion, xarray.DataArray with dimensions (rho, theta, t)

  • flux_surfs (indica.converters.flux_surfaces.FluxSurfaceCoordinates) –

  • impurities_power_loss (xarray.core.dataarray.DataArray) –

  • sess (indica.session.Session) –

Returns

Total derived bolometric power loss values along all lines-of-sight. xarray.DataArray with dimensions (channels, t) or (channels) depending on whether t_val is provided.

Return type

derived_power_loss_LoS_tot

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

__call__(deriv_only=False, trim=False, t_val=None)[source]

Varying workflow to derive bolometry from plasma quantities. (Varying as in, if full setup and derivation is needed or only derivaiton.)

Parameters
  • deriv_only (bool) – Optional boolean specifying if only derivation is needed(True) or if full setup and derivation is needed(False).

  • trim (bool) – Optional boolean specifying whether to use bolometry data with trimmed channels(True) or not(False).

  • t_val (Optional[float]) – Optional time value for which to calculate the bolometry data. (This is passed to bolometry_derivation())

Returns

Total derived bolometric power loss values along all lines-of-sight. xarray.DataArray with dimensions (channels, t) or (channels) depending on whether t_val is provided.

Return type

derived_power_loss_LoS_tot

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.CalcZeff(adas_data, sess=<indica.session.Session object>)[source]

Calculate effective charge of ions in plasma.

This is intended for illustrative purposes only and will likely undergo considerable refactoring prior to inclusion in the codebase

Parameters
  • adas_data (str) – String indicating what source of atomic data to use. (Details TBC)

  • sess (indica.session.Session) – Object representing this session of calculations with the library. Holds and communicates provenance information.

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

__call__(n_e, n_Be, T_e)[source]

Perform the calculation.

Parameters
Returns

The effective charge of the plasma.

Return type

DataArray

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.ExtrapolateImpurityDensity(sess=<indica.session.Session object>)[source]

Extrapolate the impurity density beyond the limits of SXR (Soft X-ray)

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

Returns

  • extrapolated_smooth_density_Rz – Extrapolated and smoothed impurity density, xarray.DataArray with dimensions (R, z, t).

  • extrapolated_smooth_density_rho_theta – Extrapolated and smoothed impurity density, xarray.DataArray with dimensions (rho, theta, t).

  • t – If t was not specified as an argument for the __call__ function, return the time the results are given for. Otherwise return the argument.

Parameters

sess (indica.session.Session) –

__call__(impurity_density_sxr, electron_density, electron_temperature, truncation_threshold, flux_surfaces, asymmetry_parameter=None, t=None)[source]

Extrapolates the impurity density beyond the limits of SXR (Soft X-ray)

Parameters
Returns

  • extrapolated_smooth_density_R_z – Extrapolated and smoothed impurity density ((R, z) grid). xarray.DataArray with dimensions (R, z, t)

  • extrapolated_smooth_density_rho_theta – Extrapolated and smoothed impurity density ((rho, theta) grid). xarray.DataArray with dimensions (rho, theta, t).

  • t – If t was not specified as an argument for the __call__ function, return the time the results are given for. Otherwise return the argument.

apply_asymmetry(asymmetry_parameter, extrapolated_smooth_hfs, extrapolated_smooth_lfs, R_deriv)[source]

Applying an asymmetry parameter to low-field-side data which will be extended over the poloidal extent to obtain an asymmetric extrapolated smoothed data on a (rho, theta) grid.

Parameters
  • asymmetry_parameter (xarray.core.dataarray.DataArray) – Asymmetry parameter to apply. xarray.DataArray with dimensions (rho, t)

  • extrapolated_smooth_hfs (xarray.core.dataarray.DataArray) – Extrapolated smoothed data on high-field side (fixed theta = pi). xarray.DataArray with dimensions (rho, t)

  • extrapolated_smooth_lfs (xarray.core.dataarray.DataArray) – Extrapolated smoothed data on low-field side (fixed theta = 0). xarray.DataArray with dimensions (rho, t)

  • R_deriv (xarray.core.dataarray.DataArray) – Variable describing value of R in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t)

Returns

  • extrapolated_smooth_data – Extrapolated and smoothed data on full (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t)

  • asymmetry_modifier – Asymmetry modifier used to transform a low-field side only rho-profile of a poloidally asymmetric quantity to a full poloidal cross-sectional profile ie. (rho, t) -> (rho, theta, t). Also can be defined as: exp(asymmetry_parameter * (R ** 2 - R_lfs ** 2)), where R is the major radius as a function of (rho, theta, t) and R_lfs is the low-field-side major radius as a function of (rho, t). xarray DataArray with dimensions (rho, theta, t)

basic_extrapolation(data_rho_theta, electron_density, threshold_rho)[source]

Basic extrapolation which eliminates the data_rho_theta for rho > threshold_rho and joins on electron density from that point outwards (in rho). Also multiplies electron density to prevent a discontinuity at rho_poloidal=threshold_rho.

Parameters
  • data_rho_theta (xarray.core.dataarray.DataArray) – xarray.DataArray to extrapolate. Dimensions (rho, theta, t)

  • electron_density (xarray.core.dataarray.DataArray) – xarray.DataArray of Electron density (axisymmetric). Dimensions (rho, t)

  • threshold_rho (float) – Threshold value (float) of rho beyond which SXR diagnostics cannot be used to accurately infer impurity density.

Returns

xarray.DataArray of extrapolated impurity density. Dimensions (rho, theta, t)

Return type

extrapolated_impurity_density

extrapolation_smoothing(extrapolated_data, rho_arr)[source]

Function to smooth extrapolatd data. Extrapolated data may not have any 0th order discontinuity but 1st order discontinuities may exist. Smoothing is necessary to eliminate these higher order discontinuities.

Parameters
  • extrapolated_data (xarray.core.dataarray.DataArray) – xarray.DataArray extrapolated data to be smoothed. Dimensions (rho, theta, t)

  • rho_arr (xarray.core.dataarray.DataArray) – xarray.DataArray used to construct smoothing splines. Dimensions (rho) (Must be higher or the same resolution as the rho dimension of extrapolated_data)

Returns

  • extrapolated_smooth_lfs_arr – Extrapolated smoothed data on low-field side (fixed theta = 0)

  • extrapolated_smooth_hfs_arr – Extrapolated smoothed data on high-field side (fixed theta = pi)

fitting_function(amplitude, standard_dev, position)[source]

Function to construct a signal that modifies the extrapolated smoothed impurity density. The signal is constructed using a Gaussian profile with the three free parameters.

Parameters
  • amplitude (float) – Amplitude of the additional signal (Gaussian amplitude)

  • standard_dev (float) – Standard deviation associated with the Gaussian construction (can be defined as FWHM/2.355 where FWHM is full-width at half maximum)

  • position (float) – Position of the Gaussian. During optimization this is constrained to the extrapolated region of rho (ie. outside the SXR validity region).

Returns

xarray.DataArray containing the Gaussian signal with dimensions (rho)

Return type

sig

optimize_perturbation(extrapolated_smooth_data, orig_bolometry_data, bolometry_obj, impurity_element, asymmetry_parameter, threshold_rho, R_deriv, time_correlation=True)[source]

Optimizes a Gaussian-style perturbation to recover the over-density structure that is expected on the low-field-side of the plasma.

Parameters
  • extrapolated_smooth_data (xarray.core.dataarray.DataArray) – Extrapolated and smoothed data which continues the impurity density beyond the soft x-ray threshold limit by using electron density as a guide. xarray DataArray with dimensions (rho, theta, t).

  • orig_bolometry_data (xarray.core.dataarray.DataArray) – Original bolometry data that is used in the objective function to fit the perturbation. xarray DataArray with dimensions (channels, t).

  • bolometry_obj (indica.operators.bolometry_derivation.BolometryDerivation) – BolometryDerivation object.

  • impurity_element (str) – String of impurity element symbol.

  • asymmetry_parameter (xarray.core.dataarray.DataArray) – Asymmetry parameter used to transform a low-field side only rho-profile of a poloidally asymmetric quantity to a full poloidal cross-sectional profile ie. (rho, t) -> (rho, theta, t). Dimensions (rho, t)

  • threshold_rho (xarray.core.dataarray.DataArray) – Threshold rho value beyond which asymmetry parameter is invalid and should be fitted from bolometry.

  • R_deriv (xarray.core.dataarray.DataArray) – Variable describing value of R in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t)

  • time_correlation (bool) – Boolean to indicate whether or not to use time correlated guesses during the optimization (ie. the result of the optimization for the previous time-step is used as a guess for the next time-step.)

Returns

New density with an optimized perturbation on the low-field-side that matches the original bolometry data. xarray DataArray with dimensions (rho, theta, t)

Return type

fitted_density

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

transform_to_R_z(R_deriv, z_deriv, extrapolated_smooth_data, flux_surfaces)[source]

Function to transform data from an (rho, theta) grid to a (R, z) grid

Parameters
  • R_deriv (xarray.core.dataarray.DataArray) – Variable describing value of R in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t) (from derive_and_apply_asymmetry)

  • z_deriv (xarray.core.dataarray.DataArray) – Variable describing value of z in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t) (from derive_and_apply_asymmetry)

  • extrapolated_smooth_data (xarray.core.dataarray.DataArray) – Extrapolated and smoothed data to transform onto (R, z) grid. xarray.DataArray with dimensions (rho, theta, t)

  • flux_surfaces (indica.converters.flux_surfaces.FluxSurfaceCoordinates) – FluxSurfaceCoordinates object representing polar coordinate systems using flux surfaces for the radial coordinate.

Returns

Extrapolated and smoothed data on (R, z) grid. xarray.DataArray with dimensions (R, z, t)

Return type

extrapolated_smooth_data

transform_to_rho_theta(data_R_z, flux_surfaces, rho_arr, t_arr=None)[source]

Function to transform data from an (R, z) grid to a (rho_poloidal, theta) grid

Parameters
Returns

  • data_rho_theta – Transformed xarray.DataArray. Dimensions (rho_poloidal, theta, t)

  • R_deriv – Variable describing value of R in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t)

  • z_deriv – Variable describing value of z in every coordinate on a (rho, theta) grid. xarray.DataArray with dimensions (rho, theta, t)

class indica.operators.FractionalAbundance(SCD, ACD, CCD=None, sess=<indica.session.Session object>)[source]

Calculate fractional abundance for all ionisation charges of a given element.

Parameters
  • SCD (xarray.core.dataarray.DataArray) – xarray.DataArray of effective ionisation rate coefficients of all relevant ionisation charges of given impurity element.

  • ACD (xarray.core.dataarray.DataArray) – xarray.DataArray of effective recombination rate coefficients of all relevant ionisation charges of given impurity element.

  • CCD (Optional[xarray.core.dataarray.DataArray]) – xarray.DataArray of charge exchange cross coupling coefficients of all relevant ionisation charges of given impurity element. (Optional)

  • sess (indica.session.Session) – Object representing this session of calculations with the library. Holds and communicates provenance information. (Optional)

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

Returns

xarray.DataArray of fractional abundance of all ionisation charges of given impurity element.

Return type

F_z_t

Parameters
__call__(Ne, Te, Nh=None, tau=1000.0, F_z_t0=None, full_run=True)[source]

Executes all functions in correct order to calculate the fractional abundance.

Parameters
Returns

Fractional abundance at tau.

Return type

F_z_t

calc_F_z_tinf()[source]

Calculates the equilibrium fractional abundance of all ionisation charges, F_z(t=infinity) used for the final time evolution equation.

Returns

Fractional abundance at equilibrium.

Return type

F_z_tinf

calc_eigen_coeffs(F_z_t0=None)[source]

Calculates the coefficients from the eigenvalues and eigenvectors for the time evolution equation.

Parameters

F_z_t0 (Optional[xarray.core.dataarray.DataArray]) – Initial fractional abundance for given impurity element. (Optional)

Returns

  • eig_coeffs – Coefficients calculated from the eigenvalues and eigenvectors needed for the time evolution equation.

  • F_z_t0 – Initial fractional abundance, either user-provided or fully neutral eg. [1.0, 0.0, 0.0, 0.0, 0.0] for Beryllium.

calc_eigen_vals_and_vecs()[source]

Calculates the eigenvalues and eigenvectors of the ionisation balance matrix.

Returns

  • eig_vals – Eigenvalues of the ionisation balance matrix.

  • eig_vecs – Eigenvectors of the ionisation balance matrix.

calc_ionisation_balance_matrix(Ne, Nh=None)[source]

Calculates the ionisation balance matrix that defines the differential equation that defines the time evolution of the fractional abundance of all of the ionisation charges.

Ne

xarray.DataArray of electron density as a profile of a user-chosen coordinate.

Nh

xarray.DataArray of thermal hydrogen as a profile of a user-chosen coordinate. (Optional)

Returns

Matrix representing coefficients of the differential equation governing the time evolution of the ionisation balance.

Return type

ionisation_balance_matrix

Parameters
calculate_abundance(tau)[source]

Calculates the fractional abundance of all ionisation charges at time tau.

Parameters

tau (Union[float, int, numpy.ndarray, xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset, xarray.core.variable.Variable]) – Time after t0 (t0 is defined as the time at which F_z_t0 is taken).

Returns

Fractional abundance at tau.

Return type

F_z_t

interpolate_rates(Ne, Te)[source]

Interpolates rates based on inputted Ne and Te, also determines the number of ionisation charges for a given element.

Parameters
Returns

  • SCD_spec – Interpolated effective ionisation rate coefficients.

  • ACD_spec – Interpolated effective recombination rate coefficients.

  • CCD_spec – Interpolated charge exchange cross coupling coefficients.

  • num_of_ion_charges – Number of ionisation charges(stages) for the given impurity element.

interpolation_bounds_check(Ne, Te)[source]

Checks that inputted data (Ne and Te) has values that are within the interpolation ranges specified inside imported_data(SCD,CCD,ACD,PLT,PRC,PRB).

Parameters
return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.ImpurityConcentration(sess=<indica.session.Session object>)[source]

Calculate impurity concentration of a given element.

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

Returns

  • concentration – xarray.DataArray containing the impurity concentration for the given impurity element.

  • t – If t was not specified as an argument for the __call__ function, return the time the results are given for. Otherwise return the argument.

Parameters

sess (indica.session.Session) –

__call__(

element, Zeff_LoS, impurity_densities, electron_density, mean_charge, flux_surfaces, t

)

Calculates the impurity concentration for the inputted element.

__call__(element, Zeff_LoS, impurity_densities, electron_density, mean_charge, flux_surfaces, t=None)[source]

Calculates the impurity concentration for the inputted element.

Parameters
Returns

  • concentration – xarray.DataArray containing the impurity concentration for the given impurity element.

  • t – If t was not specified as an argument for the __call__ function, return the time the results are given for. Otherwise return the argument.

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.InvertRadiation(num_cameras=1, datatype='sxr', n_knots=6, n_intervals=65, sess=<indica.session.Session object>)[source]

Estimates the emissivity distribution of the plasma using radiation data.

Parameters
  • flux_coordinates (FluxSurfaceCoordinates) – The flux surface coordinate system on which to calculate the fit.

  • datatype (SpecificDataType) – The type of radiation data to be inverted.

  • num_cameras (int) – The number of cameras to which the data will be fit.

  • n_knots (int) – The number of spline knots to use when fitting the emissivity data.

  • n_intervals (int) – The number of intervals over which to integrate th eemissivity. Should be \(2^m + 1\), where m is an integer.

  • sess (session.Session) – An object representing the session being run. Contains information such as provenance data.

__call__(times, *cameras)[source]

Calculate the emissivity profile for the plasma.

Parameters
Returns

  • DataArray – The fit emissivity, on the R-z grid. Will also contain an attribute “emissivity_model”, which is an indica.operators.invert_radiation.EmissivityProfile object that can interpolate the fit emissivity onto arbitrary coordinates.

  • Dataset – A dataset containing

    • symmetric_emissivity: The symmetric emissivity

      values which were found during the fit, given along \(\rho\).

    • asymmetry_parameter: The asymmetry of the emissivity which was found during the fit, given along \(\rho\).

  • Dataset – For each camera passed as an argument, a dataset containing

    • camera: The radiation data for that camera, binned in time.

    • back_integral: The integral of the fit emissivity along the lines of sight of the camera.

    • weights: The weights assigned to each line of sight of the camera when fitting emissivity.

Return type

Tuple[indica.operators.invert_radiation.EmissivityProfile, xarray.core.dataset.Dataset, List[xarray.core.dataset.Dataset]]

static knot_positions(n, rho_max)[source]

Calculates location of knots in magnetic flux coordinates.

Parameters
  • n (int) – The number of knots needed.

  • rho_max (float) – The normalised magnetic flux of the final knot location.

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.MeanCharge(sess=<indica.session.Session object>)[source]

Calculate mean charge for a given element from its fractional abundance.

Returns

numpy.ndarray of mean charge of the given element.

Return type

mean_charge

Parameters

sess (indica.session.Session) –

__call__(FracAbundObj, element)[source]

Function to calculate the mean charge.

Parameters
  • FracAbundObj (xarray.core.dataarray.DataArray) – numpy.ndarray describing the fractional abundance of the given element. The first axis must correspond to the ionisation charges of the element.

  • element (str) – Symbol of the element for which the mean charge is desired.

Returns

numpy.ndarray of mean charge of the given element.

Return type

mean_charge

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.Operator(sess=<indica.session.Session object>, **kwargs)[source]

Abstract base class for performing calculations with data.

Note that the “Parameters” section below describes the paramters used when calling an object of this class and not when constructing a new object as would normally be the case.

Parameters
  • sess (session.Session) – An object representing the session being run. Contains information such as provenance data.

  • kwargs (Any) – Any other arguments which should be recorded in the PROV entity for the reader.

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator. If there are variadic positional arguments then their type is given by the final element of the list.

Type

ClassVar[List[DataType]]

RETURN_TYPES

Ordered list of the types of data returned by the operator.

Type

ClassVar[List[DataType]]

prov_id

The hash used to identify this object in provenance documents.

Type

str

agent

An agent representing this object in provenance documents. DataArray objects can be attributed to it.

Type

prov.model.ProvAgent

entity

An entity representing this object in provenance documents. It is used to provide information on the object’s own provenance.

Type

prov.model.ProvEntity

abstract __call__(*args)[source]

The invocation of the operator.

The exact number of arguments should be determined by the subclass. However, it is anticipated that these would all be xarray.DataArray objects.

Unfortunately, we can not use Mypy static type-checking for this routine or its overriding implementations, as the number of arguments will vary.

Parameters

args (xarray.core.dataarray.DataArray) –

Return type

Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]

assign_provenance(data)[source]

Create and assign a provenance entity to the argument. This argument should be one of the results of the operator.

This should only be called after validate_arguments(), as it relies on that routine to collect information about the inputs to the operator. It should not be called until after all calculations are finished, as the first call will be used to determine the end-time of the calculation.

Returns

A provenance entity for the newly calculated data.

Parameters

data (Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]) –

Return type

prov.model.ProvEntity

abstract return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

validate_arguments(*args)[source]

Checks that arguments to the operator are of the expected types.

Also gathers provenance information for use later.

Parameters

args (Union[xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset]) – All of the arguments to be used in the operation.

exception indica.operators.OperatorError[source]

An Exception class raised by operator.Operator when receiving erroneous arguments.

class indica.operators.PowerLoss(PLT, PRB, PRC=None, sess=<indica.session.Session object>)[source]

Calculate the total power loss associated with a given impurity element

Parameters
  • PLT (xarray.core.dataarray.DataArray) – xarray.DataArray of radiated power of line emission from excitation of all relevant ionisation charges of given impurity element.

  • PRB (xarray.core.dataarray.DataArray) – xarray.DataArray of radiated power from recombination and bremsstrahlung of given impurity element.

  • PRC (Optional[xarray.core.dataarray.DataArray]) – xarray.DataArray of radiated power of charge exchange emission of all relevant ionisation charges of given impurity element. (Optional)

  • sess (indica.session.Session) – Object representing this session of calculations with the library. Holds and communicates provenance information. (Optional)

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

Returns

xarray.DataArray of total radiated power loss of all ionisation charges of given impurity element.

Return type

cooling_factor

Parameters
__call__(Ne, Te, F_z_t, Nh=None, full_run=True)[source]

Executes all functions in correct order to calculate the total radiated power.

Parameters
  • Ne (xarray.core.dataarray.DataArray) – xarray.DataArray of electron density as a profile of a user-chosen coordinate.

  • Te (xarray.core.dataarray.DataArray) – xarray.DataArray of electron temperature as a profile of a user-chosen coordinate.

  • Nh (Optional[xarray.core.dataarray.DataArray]) – xarray.DataArray of thermal hydrogen number density as a profile of a user-chosen coordinate. (Optional)

  • F_z_t (xarray.core.dataarray.DataArray) – xarray.DataArray of fractional abundance of all ionisation charges of given impurity element. (Optional)

  • full_run (bool) – Boolean specifying whether to only run calculate_power_loss(False) or to run the entire ordered workflow(True) for calculating power loss from the start. This is mostly only useful for unit testing and is set to True by default. (Optional)

Returns

Total radiated power of all ionisation charges.

Return type

cooling_factor

calculate_power_loss(Ne, F_z_t, Nh=None)[source]

Calculates total radiated power of all ionisation charges of a given impurity element.

Parameters
Returns

Total radiated power of all ionisation charges.

Return type

cooling_factor

interpolate_power(Ne, Te)[source]

Interpolates the various powers based on inputted Ne and Te.

Parameters
Returns

  • PLT_spec – Interpolated radiated power of line emission from excitation of all relevant ionisation charges.

  • PRC_spec – Interpolated radiated power of charge exchange emission of all relevant ionisation charges.

  • PRB_spec – Interpolated radiated power from recombination and bremsstrahlung.

  • num_of_ion_charges – Number of ionisation charges(stages) for the given impurity element.

interpolation_bounds_check(Ne, Te)[source]

Checks that inputted data (Ne and Te) has values that are within the interpolation ranges specified inside imported_data(PLT,PRC,PRB).

Parameters
return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.Spline(values, dim, coord_transform, bounds='clamped')[source]

Callable class wrapping a :class:scipy.interpolate.CubicSpline object so it will work with DataArrays. It performs interpolation over one dimension, but can do this onto a multidimensional grid.

Parameters
  • values (DataArray) – The values to interpolate.

  • dim (Hashable) – The axis along which to interpolate.

  • coord_transform (CoordinateTransform) – The transform describing the coordinate system used by values.

  • bounds (BoundaryType) – The boundary condition to pass to :class:scipy.interpolate.CubicSpline.

__call__(coord_system, x1, x2, t)[source]

Get the spline values at the locations given by the coordinates. Although it takes multiple coordinates as arguments, the actual interpolation will only be done along the dim specified at instantiation.

Parameters
Return type

xarray.core.dataarray.DataArray

class indica.operators.SplineFit(knots=[0.0, 0.3, 0.6, 0.85, 0.95, 1.05], lower_bound=-inf, upper_bound=inf, sess=<indica.session.Session object>)[source]

Fit a 1-D spline to data. The spline will be given on poloidal flux surface coordinates, as specified by the user. It can derive a single spline fit for multiple DataArray arguments simultaneously.

Parameters
  • knots (ArrayLike) – A 1-D array containing the location of spline knots to use when fitting the data.

  • lower_bound (ArrayLike) – The lower bounds to use for values at each not. May be either a scalar or an array of the same shape as knots.

  • upper_bound (ArrayLike) – The upper bounds to use for values at each not. May be either a scalar or an array of the same shape as knots.

  • sess (session.Session) – An object representing the session being run. Contains information such as provenance data.

__call__(rho, times, *data)[source]

Fit a spline to the provided data.

Parameters
Returns

The results of the fit on the give rho and time values. It contains the attribute splines which can be used to interpolate results onto arbitrary coordinates.

Return type

Tuple[xarray.core.dataarray.DataArray, …]

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]], …]

class indica.operators.ToroidalRotation(sess=<indica.session.Session object>)[source]

Calculate the toroidal rotation from asymmetry parameter.

Returns

xarray.DataArray containing toroidal rotation for a given impurity element

Return type

toroidal_rotation

Parameters

sess (indica.session.Session) –

ARGUMENT_TYPES

Ordered list of the types of data expected for each argument of the operator.

Type

List[DataType]

RESULT_TYPES

Ordered list of the types of data returned by the operator.

Type

List[DataType]

__call__(asymmetry_parameters, ion_temperature, main_ion, impurity, Zeff, electron_temp)[source]

Calculates the toroidal rotation frequency from the asymmetry parameter.

Parameters
Returns

xarray.DataArray containing data for toroidal rotation frequencies for the given impurity element

Return type

toroidal_rotation

return_types(*args)[source]

Indicates the datatypes of the results when calling the operator with arguments of the given types. It is assumed that the argument types are valid.

Parameters

args (Union[Tuple[Optional[str], Optional[str]], Tuple[Optional[str], Dict[str, str]]]) – The datatypes of the parameters which the operator is to be called with.

Returns

The datatype of each result that will be returned if the operator is called with these arguments.

Return type

Tuple[Any, …]