Python routines#

boututils#

  • class Datafile provides a convenient way to read and write NetCDF files. There are many different NetCDF libraries available for Python, so this class tries to provide a consistent interface to many of them.

  • deriv()

  • determineNumberOfCPUs()

  • file_import() reads the contents of a NetCDF file into a dictionary

  • integrate()

  • launch()

  • linear_regression()

  • showdata() visualises and animates 2D data (time + 1 spatial dimension) or 3D data (time + 2 spatial dimensions). The animation object can be returned, or the animation can be saved to a file or displayed on screen.

  • boutwarnings contains functions to raise warning messages. alwayswarn() by default prints the warning every time it is called. defaultwarn() by default prints the warning only the first time an instance of it is called. This module is a wrapper for the Python warnings module, so printing the warnings can be controlled using warnings.simplefilter() or warnings.filterwarnings().

Generic routines, useful for all data

boutdata#

  • collect() provides an interface to read BOUT++ data outputs, returning NumPy arrays of data. It deals with the processor layout, working out which file contains each part of the domain.

    from boutdata.collect import collect
    
    t = collect("t_array")  # Collect the time values
    
  • pol_slice() takes a 3 or 4-D data set for a toroidal equilibrium, and calculates a slice through it at fixed toroidal angle.

  • gen_surface() is a generator for iterating over flux surfaces

Routines for exchanging data to/from BOUT++

boutdata.attributes(varname, path='.', prefix='BOUT.dmp')#

Return a dictionary of variable attributes in an output file

Parameters:
  • varname (str) – Name of the variable

  • path (str, optional) – Path to data files (default: “.”)

  • prefix (str, optional) – File prefix (default: “BOUT.dmp”)

Returns:

A dictionary of attributes of varname

Return type:

dict

boutdata.collect(varname, xind=None, yind=None, zind=None, tind=None, path='.', yguards=False, xguards=True, info=True, prefix='BOUT.dmp', strict=False, tind_auto=False, datafile_cache=None)#

Collect a variable from a set of BOUT++ outputs.

Parameters:
  • varname (str) – Name of the variable

  • xind, yind, zind, tind (int, slice or list of int, optional) – Range of X, Y, Z or time indices to collect. Either a single index to collect, a list containing [start, end] (inclusive end), or a slice object (usual python indexing). Default is to fetch all indices

  • path (str, optional) – Path to data files (default: “.”)

  • prefix (str, optional) – File prefix (default: “BOUT.dmp”)

  • yguards (bool or “include_upper”, optional) – Collect Y boundary guard cells? (default: False) If yguards==”include_upper” the y-boundary cells from the upper (second) target are also included.

  • xguards (bool, optional) – Collect X boundary guard cells? (default: True) (Set to True to be consistent with the definition of nx)

  • info (bool, optional) – Print information about collect? (default: True)

  • strict (bool, optional) – Fail if the exact variable name is not found? (default: False)

  • tind_auto (bool, optional) – Read all files, to get the shortest length of time_indices. Useful if writing got interrupted (default: False)

  • datafile_cache (datafile_cache_tuple, optional) – Optional cache of open DataFile instances: namedtuple as returned by create_cache. Used by BoutOutputs to pass in a cache so that we do not have to re-open the dump files to read another variable (default: None)

Examples

>>> collect(name)
BoutArray([[[[...]]]])