pyrokinetics.gk_code.gk_output.GKOutput#

class pyrokinetics.gk_code.gk_output.GKOutput(*, coords, norm, output_convention='pyrokinetics', fields=None, fluxes=None, moments=None, eigenvalues=None, eigenfunctions=None, linear=True, normalise_flux_moment=False, gk_code=None, input_file=None, input_convention=None, jacobian=None)[source]#

Bases: DatasetWrapper, ReadableFromFile

Contains the output data from gyrokinetics codes. Converts the results of each code to a standard set of normalisation conventions, which allows for easier cross-code comparisons.

Users are not expected to initialise GKOutput objects directly, and in most cases should instead make use of the function read_gk_output.

The inputs to GKOutput should be given “physical units”, as defined on the normalisation page, appropriate to the code that generated the output data. If inputs are not given units, it is assumed they are already compliant with the Pyrokinetics standards.

Parameters:
  • coords (Coords) – Dataclass specifying the coordinates of the simulation

  • norm (SimulationNormalisation) – The normalisation scheme of the simulation.

  • fields (Optional[Fields]) – Dataclass specifying the fields in the simulation

  • fluxes (Optional[Fluxes]) – Dataclass specifying the fluxes in the simulation

  • moments (Optional[Moments]) – Dataclass specifying the moments in the simulation

  • eigenvalues (Optional[Eigenvalues]) – Dataclass specifying the eigenvalues in the simulation. Should only be supplied for linear runs. If not provided, will be set from field data.

  • eigenfunctions (Optional[Eigenfunctions]) – Dataclass specifying the eigenfunctions in the simulation Should only be supplied for linear runs. If not provided, will be set from field data.

  • linear (bool) – Set True for linear gyrokinetics runs, False for nonlinear runs.

  • normalise_flux_moment (bool) – TODO write docs

  • gk_code (Optional[str]) – The gyrokinetics code that generated the results.

  • input_file (Optional[str]) – The input file used to generate the results.

  • output_convention (str)

  • input_convention (Optional[str])

  • jacobian (Optional[ArrayLike])

data#

The internal representation of the GKOutput object. The functions __getattr__ and __getitem__ redirect most attribute/indexing lookups here, but the Dataset itself may be accessed directly by the user if they wish to perform more complex manipulations.

Type:

xarray.Dataset

linear#

True if the run is linear, False if the run is nonlinear

Type:

bool

gk_code#

The gyrokinetics code that generated the data.

Type:

str

input_file#

Gyrokinetics input file expressed as a string.

Type:

str

norm#

The normalisation scheme used for the data.

Type:

SimulationNormalisation

__init__(*, coords, norm, output_convention='pyrokinetics', fields=None, fluxes=None, moments=None, eigenvalues=None, eigenfunctions=None, linear=True, normalise_flux_moment=False, gk_code=None, input_file=None, input_convention=None, jacobian=None)[source]#
Parameters:

Methods

__init__(*, coords, norm[, ...])

add_data(name, data, coords, units[, ...])

Modifies existing GKOutput by adding specified data

convert_physical_units(norms)

Convert physical-unit data vars and coords to generic simulation units of norms.

field(name)

flux(name)

from_file(path[, file_type])

Read a file from disk, returning an instance of this class.

from_netcdf(path, *args[, ...])

Initialise self.data from a netCDF file.

get_growth_rate_tolerance([time_range])

Given a pyrokinetics output dataset with eigenvalues determined, calculate the growth rate tolerance.

moment(name)

supported_file_types()

Returns a list of all registered file types.

to(norms, *contexts)

to_netcdf(*args, **kwargs)

Writes self.data to disk.

Attributes

attrs

Redirects to underlying Xarray Dataset attrs.

coords

Redirects to underlying Xarray Dataset coords.

data

Property for managing the underlying Xarray Dataset.

data_vars

Redirects to underlying Xarray Dataset data_vars.

dims

Redirects to underlying Xarray Dataset dims.

sizes

Redirects to underlying Xarray Dataset sizes.

add_data(name, data, coords, units, output_convention='pyrokinetics')[source]#

Modifies existing GKOutput by adding specified data

Parameters:
  • data (ArrayLike) – N-D array of data to be added in

  • coords (Tuple) – Coordinates of the data provided. Must match shape of data

  • units (pint.Unit) – Units of data

  • name (str)

convert_physical_units(norms)[source]#

Convert physical-unit data vars and coords to generic simulation units of norms.

field(name)[source]#
Return type:

DataArray

Parameters:

name (str)

flux(name)[source]#
Return type:

DataArray

Parameters:

name (str)

get_growth_rate_tolerance(time_range=0.8)[source]#

Given a pyrokinetics output dataset with eigenvalues determined, calculate the growth rate tolerance. This is calculated starting at the time given by time_range * max_time.

Return type:

float

Parameters:

time_range (float)

moment(name)[source]#
Return type:

DataArray

Parameters:

name (str)

to(norms, *contexts)[source]#
Parameters:

norms (ConventionNormalisation) – Normalisation convention to convert to

Return type:

GKOutput with units from norms