peqdsk#

P-EQDSK files describe kinetics profiles as a function of \(\psi_N\), the normalised poloidal flux function. This is defined such that \(\psi_N = 0\) on the magnetic axis of a tokamak, and \(\psi_N=1\) on the last closed flux surface. Values in the range \([0,1]\) are used to index each nested flux surface.

The data contained within a P-EQDSK file varies depending on the source, but it will typically contain information such as ion/electron number densities and temperatures. It also contains the derivatives of each variaible with respect to \(\psi_N\). Data is represented in a csv-like format, and separated into blocks within the file. Each block of kinetics profile data has the form:

nrows psinorm var dvar/dpsiN
 0.000000   3.141592   2.718282
 ...
 1.000000   42.000000   -1.000000

where nrows is an integer specifying the number of rows in the block, and var is the variable described by the block.

At the bottom of a P-EQDSK file, a small block contains information describing the atomic number, charge (in units of \(e\)), and atomic mass of the ions:

nrows N Z A of ION SPECIES
 6.000000   6.000000   12.000000
 1.000000   1.000000   2.000000
 1.000000   1.000000   2.000000
class freeqdsk.peqdsk.ProfileDict(*args, **kwargs)#

TypedDict describing an individual kinetics profile.

data: ndarray#

Kinetics profile

derivative: ndarray#

Derivative of profile with respect to psinorm

psinorm: ndarray#

\(\psi_N\) grid, where \(\psi_N=0\) on the magnetic axis and \(\psi_N=1\) on the last closed flux surface

units: str#

Units of profile

class freeqdsk.peqdsk.SpeciesDict(*args, **kwargs)#

TypedDict describing each species.

A: float#

Atomic mass

N: float#

Atomic number

Z: float#

Charge (units of \(e\))

class freeqdsk.peqdsk.PEQDSKDict(*args, **kwargs)#

TypedDict returned by the read function.

profile: Dict[str, ProfileDict]#

Dict of kinetics profiles. The names of each profile are used as keys, while the data is presented in a ProfileDict.

species: List[SpeciesDict]#

List of species.

peqdsk.read()#

Given a file handle, reads a P-EQDSK file and returns a dict containing profile and species data.

The returned dict has two entries:

  • data["profiles"] is a dict of keys and ProfileDict. For example, to access the electron density data, use data["profiles"]["ne"]["data"]. To access the ion density dervative with respect to \(\psi_N\), use data["profiles"]["ni"]["derivative"].

  • data["species"] is a list of SpeciesDict. To access the atomic number of the first entry, use data["species"][0]["N"].

Parameters:

fh (TextIO) – File handle. Should be in a text read mode, open(filename, "r").

Return type:

PEQDSKDict

peqdsk.write(fh)#

Given a file handle and a PEQDSKDict dict, write a P-EQDSK file. The provided dict should have the same structure as that returned by the read function.

Parameters:
  • data (PEQDSKDict) – Dict of P-EQDSK data. Should be in the format of a PEQDSKDict, which is itself composed of ProfileDict and SpeciesDict dicts.

  • fh (TextIO) – File handle. Should be opened in a text write mode, open(filename, "w").

Return type:

None