readers Module

Module to provide objects for reading fusion data from the filesystem or databases. These objects are all subclasses of readers.DataReader, with each subclass providing functionality for a different format of data.

class indica.readers.ADASReader(path=PosixPath('.'), sess=<indica.session.Session object>)[source]

Class for reading atomic data from ADAS files.

Parameters
  • path (Union[str, Path]) – Location from which relative paths should be evaluated. Default is to download files from OpenADAS, storing them in your home directory for later use.

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

  • sess (indica.session.Session) –

close()[source]

Closes connections to database/files. For this class it does not need to do anything.

create_provenance(filename, start_time)[source]

Create a provenance entity for the given ADAS file.

Note that this method just creates the provenance data appropriate for the arguments it has been provided with. It does not check that these arguments are actually valid and that the provenance corresponds to actually existing data.

Parameters
Return type

prov.model.ProvEntity

get_adf11(quantity, element, year)[source]

Read data from the specified ADAS file.

Parameters
  • quantity (str) – The type of data to retrieve. Options: scd, acd, plt, prb, plsx, prsx.

  • element (str) – The atomic symbol for the element which will be retrieved.

  • year (str) – The two-digit year label for the data.

Returns

The data in the specified file. Dimensions are density and temperature. Each members of the dataset correspond to a different charge state.

Return type

xarray.core.dataarray.DataArray

get_adf15(element, charge, filetype, year='')[source]

Read data from the specified ADF15 ADAS file.

Implementation is capable of reading files with compact and expanded formatting e.g. pec96][ne_pju][ne9.dat and pec40][ar_cl][ar16.dat respectively

Parameters
  • element (str) – The atomic symbol for the element which will be retrieved.

  • charge (str) – Charge state of the ion (e.g. 16 for Ar 16+), can also include other string for more complicated path (transport_llu][ar15ic.dat setting charge to “15ic”)

  • filetype (str) – The type of data to retrieve. Options: ic, cl, ca, ls, llu, …

  • year – The two-digit year label for the data. = “transport” if special transport path

Returns

The data in the specified file. Dimensions are density and temperature. Each members of the dataset correspond to a different charge state.

Return type

xarray.core.dataarray.DataArray

property requires_authentication: Literal[False]

Reading ADAS data never requires authentication.

class indica.readers.DataReader(tstart, tend, max_freq, sess, selector=<function choose_on_plot>, **kwargs)[source]

Abstract base class to read data in from a database.

This defines the interface used by all concrete objects which read data from the disc, a database, etc. It is a context manager and can be used in a with statement.

Parameters
agent

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

Type

prov.model.ProvAgent

INSTRUMENT_METHODS

Mapping between instrument (DDA in JET) names and method to use to assemble that data. Implementation-specific.

Type

Dict[str, str]

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

NAMESPACE

The abbreviation and full URL for the PROV namespace of the database the class reads from.

Type

Classvar[Tuple[str, str]]

prov_id

The hash used to identify this object in provenance documents.

Type

str

classmethod available_quantities(instrument)[source]

Return the quantities which can be read for the specified instrument.

create_provenance(diagnostic, uid, instrument, revision, quantity, data_objects, ignored)[source]

Create a provenance entity for the given set of data. This should be attached as metadata.

Note that this method just creates the provenance data appropriate for the arguments it has been provided with. It does not check that these arguments are actually valid and that the provenance corresponds to actually existing data.

Parameters
  • key – Identifies what data was read. Should be present in AVAILABLE_DATA.

  • revision (Union[str, int]) – Object indicating which version of data should be used.

  • data_objects (Iterable[str]) – Identifiers for the database entries or files which the data was read from.

  • ignored (Iterable[numbers.Number]) – A list of channels which were ignored/dropped from the data.

  • diagnostic (str) –

  • uid (str) –

  • instrument (str) –

  • quantity (str) –

Returns

A provenance entity for the newly read-in data.

Return type

prov.model.ProvEntity

get(uid, instrument, revision=0, quantities={})[source]

Reads data for the requested instrument. In general this will be the method you want to use when reading.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – The instrument which measured this data (DDA at JET)

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database. Defaults to all available quantities for that instrument.

Returns

A dictionary containing the requested physical quantities.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_bremsstrahlung_spectroscopy(uid, instrument, revision, quantities)[source]

Reads spectroscopic measurements of effective charge.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested effective charge data.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_charge_exchange(uid, instrument, revision, quantities)[source]

Reads charge exchange data.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested physical quantities.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_cyclotron_emissions(uid, instrument, revision, quantities)[source]

Reads electron temperature measurements from cyclotron data.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to fetch the data for.

Returns

A dictionary containing the electron temperature.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_equilibrium(uid, instrument, revision, quantities)[source]

Reads equilibrium data.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the code used to calculate this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested physical quantities.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_filters(uid, instrument, revision, quantities)[source]

Reads filtered radiation diodes

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested data.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_helike_spectroscopy(uid, instrument, revision, quantities)[source]

Reads spectroscopic measurements of He-like emission.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested data.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_interferometry(uid, instrument, revision, quantities)[source]

Reads interferometer electron density.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database.

Returns

A dictionary containing the requested data.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_radiation(uid, instrument, revision, quantities)[source]

Reads data on irradiance.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which cameras to read quantitie(s) from.

Returns

A dictionary containing the requested radiation values.

Return type

Dict[str, xarray.core.dataarray.DataArray]

get_thomson_scattering(uid, instrument, revision, quantities)[source]

Reads data based on Thomson Scattering.

Parameters
  • uid (str) – User ID (i.e., which user created this data)

  • instrument (str) – Name of the instrument which measured this data

  • revision (Union[str, int]) – An object (of implementation-dependent type) specifying what version of data to get. Default is the most recent.

  • quantities (Set[str]) – Which physical quantitie(s) to read from the database..

Returns

A dictionary containing the requested physical quantities.

Return type

Dict[str, xarray.core.dataarray.DataArray]

class indica.readers.PPFReader(pulse, tstart, tend, server='https://sal.jet.uk', default_error=0.05, max_freq=1000000.0, selector=<function choose_on_plot>, session=<indica.session.Session object>)[source]

Class to read JET PPF data using SAL.

Parameters
DIAGNOSTIC_QUANTITIES

Hierarchical information on the quantities which are available for reading. These are indexed by (in order) diagnostic name, UID, instrument name, and quantity name. The values of the innermost dictionary describe the physical type of the data to be read.

Type

Dict[str, Dict[str, Dict[str, Dict[str, ArrayType]]]]

NAMESPACE

The abbreviation and full URL for the PROV namespace of the reader class.

Type

Tuple[str, str]

authenticate(name, password)[source]

Log onto the JET/SAL system to access data.

Parameters
  • name (str) – Your username when logging onto Heimdall.

  • password (str) – Your single sign-on password.

Returns

Indicates whether authentication was succesful.

close()[source]

Ends connection to the SAL server from which PPF data is being read.

get_sal_path(uid, instrument, quantity, revision)[source]

Return the path in the PPF database to for the given INSTRUMENT (DDA in JET).

Parameters
Return type

str

property requires_authentication

Indicates whether authentication is required to read data.

Returns

True if authentication is needed, otherwise false.

indica.readers.choose_on_plot(data, channel_dim, bad_channels, unselected_channels=[])[source]

Produces a plot in its own window, on which the user can click data from channels which they wish to be discarded.

Instructions are printed to the command line, so it is probably not suitable for use in a GUI.

Parameters
  • data (xarray.core.dataarray.DataArray) – The data from which channels should be selected to discard.

  • channel_dim (str) – The name of the dimension used for storing separate channels. This will be used for the x-axis in the plot.

  • bad_channels (Collection[numbers.Number]) – A (possibly empty) list of channel labels which are known to be incorrectly calibrated, faulty, or otherwise untrustworty. These will be plotted in red, but must still be specifically selected by the user to be discared.

  • unselected_channels (Iterable[numbers.Number]) – A (possibly empty) list of channels which will be ignored by default. These could be, e.g., cached values from a previous run. The user is welcome to change this.

Returns

A list of channel labels which the user has selected to be discarded.

Return type

Iterable[numbers.Number]

Reader classes (along with writer classes) inherit from the BaseIO class, which provides common functionality.

class indica.abstractio.BaseIO[source]

An abstract class defining methods needed by all IO objects.

authenticate(name, password)[source]

Confirms user has permission to write data.

This must be called before writing data to some locations. The default implementation does nothing. If the value of py:meth:requires_authentication is False then it does not need to be called.

Parameters
  • name (str) – Username to authenticate against.

  • password (str) – Password for that user.

Returns

Indicates whether authentication was succesful.

Return type

bool

abstract close()[source]

Closes connection to whatever backend (file, database, server, etc.) to which data is being written.

Return type

None

abstract property requires_authentication: bool

Indicates whether authentication is required to read data.

Returns

True if authentication is needed, otherwise false.