pencil.read

Read data and parameters from data directories.

Submodules

Attributes

record_types

Classes

PDim

Class holding the data from pdim.dat and its methods.

pdf

Reads the output of the power_xy subroutine

Functions

pdim(*args, **kwargs)

Wrapper for PDim.read()

index(*args, **kwargs)

index(datadir='data', param=None, dim=None)

ts(*args, **kwargs)

Wrapper for TimeSeries.read()

power(*args, **kwargs)

Wrapper for Power.read()

ogdim(*args, **kwargs)

ogdim(datadir='data', proc=-1)

ogvar(*args, **kwargs)

ogvar(var_file='', datadir='data', proc=-1, iogvar=-1,

dim(*args, **kwargs)

Wrapper for Dim.read()

param(*args, **kwargs)

Wrapper for Param.read()

grid(*args, **kwargs)

Wrapper for Grid.read()

var(*args, **kwargs)

Wrapper for DataCube.read()

slices(*args, **kwargs)

Wrapper for SliceSeries.read()

aver(*args, **kwargs)

Wrapper for Averages.read()

pvar(*args, **kwargs)

pvar(pvarfile='', datadir='data', proc=-1, ipvar=-1, quiet=True,

phiaver(*args, **kwargs)

Wrapper for Averages.read()

varraw(*args, **kwargs)

varraw(var_file="", datadir="data", proc=-1, ivar=-1, var_list=None, quiet=False,

pstalk2([datadir, it0, it1, swap_endian, quiet, ...])

Read Pencil Code particle stalker data (PSTALK) and return a Struct with

pstalk(*args, **kwargs)

Wrapper for ParticleStalkData

Package Contents

pencil.read.pdim(*args, **kwargs)

Wrapper for PDim.read()

class pencil.read.PDim

Bases: object

Class holding the data from pdim.dat and its methods.

Fill members with default values.

npar = 0
mpvar = 0
npar_stalk = 0
mpaux = 0
keys()
read(datadir='data')

read(sim=None, datadir=’data’)

Read the pdim.dat file.

Parameters:
  • sim (obj) – Specifies the simulation object from which to obtain the datadir.

  • datadir (string) – Directory where the data is stored.

Return type:

Object containing the particle dimensions.

pencil.read.index(*args, **kwargs)

index(datadir=’data’, param=None, dim=None)

Read Pencil Code index data from index.pro.

Parameters:
  • datadir (string) – Directory where the data is stored.

  • param (obj) – Parameter object.

  • dim (obj) – Dimension object.

Return type:

Class containing the index information.

pencil.read.ts(*args, **kwargs)

Wrapper for TimeSeries.read()

class pencil.read.pdf(datadir='data', filename=None, debug=False)

Reads the output of the power_xy subroutine

Arguments

datadir: path to the data directory. Default: “data” filename: name of the file to read. Default: all files named pdf_*.dat

Examples
>>> p = pc.read.pdfs()
>>> p.t #1D array, length nt
>>> p.lnrho #PDFContainer instance
>>> p.lnrho.bins: #1D array, length nb
>>> p.lnrho.counts #2D array, size (nt,nb): counts in each bin at a particular timestep
>>> plt.semilogy(p.lnrho.bin_centers, p.lnrho.calc_counts(t_min=10)) #plots the PDF of lnrho for t>10
Attributes

t: 1D array, times Remaining attributes are PDFContainer instances, named after the variables whose PDFs are being calculated.

keys()
pencil.read.power(*args, **kwargs)

Wrapper for Power.read()

pencil.read.ogdim(*args, **kwargs)

ogdim(datadir=’data’, proc=-1)

Read the ogdim.dat file.

Parameters:
  • datadir (string) – Directory where the data is stored.

  • proc (int) – Processor to be read. If proc is -1, then read the ‘global’ dimensions. If proc is >=0, then read the dim.dat in the corresponding processor directory.

Return type:

Class containing the simulation dimensions.

pencil.read.ogvar(*args, **kwargs)
ogvar(var_file=’’, datadir=’data’, proc=-1, iogvar=-1,

quiet=True, trimall=False, magic=None, sim=None, precision=’f’)

Read OGVAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load OGVAR file from specified processor.

The file format written by output() (and used, e.g. in ogvar.dat) consists of the followinig Fortran records: 1. data(mx, my, mz, nvar) 2. t(1), x(mx), y(my), z(mz), dx(1), dy(1), dz(1), deltay(1) Here nvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 8 for ogvar.dat in the case of MHD with entropy. but, deltay(1) is only there if lshear is on! need to know parameters.

Parameters:
  • var_file (string) – Name of the OGVAR file.

  • datadir (string) – Directory where the data is stored.

  • proc (int) – Processor to be read. If -1 read all and assemble to one array.

  • iogvar (int) – Index of the OGVAR file, if var_file is not specified.

  • quiet (bool) – Flag for switching off output.

  • trimall (bool) – Trim the data cube to exclude ghost zones.

  • magic (list of string) – Values to be computed from the data, e.g. B = curl(A).

  • sim (obj) – Simulation sim object.

  • precision (string) – Precision of the data. Either float ‘f’ or double ‘d’.

pencil.read.record_types
pencil.read.dim(*args, **kwargs)

Wrapper for Dim.read()

pencil.read.param(*args, **kwargs)

Wrapper for Param.read()

pencil.read.grid(*args, **kwargs)

Wrapper for Grid.read()

pencil.read.var(*args, **kwargs)

Wrapper for DataCube.read()

pencil.read.slices(*args, **kwargs)

Wrapper for SliceSeries.read()

pencil.read.aver(*args, **kwargs)

Wrapper for Averages.read()

pencil.read.pvar(*args, **kwargs)
pvar(pvarfile=’’, datadir=’data’, proc=-1, ipvar=-1, quiet=True,

ID=False, pflist=None, sim=None, precision=’f’, dtype=np.float64)

Read PVAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load VAR file from specified processor.

The file format written by output() (and used, e.g. in pvar.dat) consists of the followinig Fortran records: 1. [npar] 2. indices(npar) 3. pdata(npvar, npar) Here npvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 6 for pvar.dat in the case of npar particles with 3 coordinates and 3 velocity components.

Parameters:
  • pvarfile (string) – Name of the VAR file. If not specified, use var.dat (which is the latest snapshot of the fields)

  • datadir (string) – Directory where the data is stored.

  • proc (int) – Processor to be read. If -1 read all and assemble to one array.

  • ipvar (int) – Index of the VAR file, if var_file is not specified.

  • quiet (bool) – Flag for switching off output.

  • ID (bool) – Flag for including the particle IDs in the object.

  • pflist (bool) – If present list of exclusive basic pfarrays to include

  • sim (pencil code simulation object) – Contains information about the local simulation.

  • precision (string) – Float ‘f’, double ‘d’ or half ‘half’.

  • lpersist (bool) – Read the persistent variables if they exist

Returns:

Instance of the pencil.read.var.DataCube class. All of the computed fields are imported as class members.

Return type:

DataCube

Examples

Read the latest var.dat file and print the shape of the uu array: >>> pvar = pc.read.pvar() >>> print(pvar.px.shape)

Read the PVAR2 file, and include only the x coordinates and velocity e.g., for instance to reduce memory load for large arrays. >>> pvar = pc.read.pvar(pvar_file=’PVAR2’, pflist=[‘px’,’pvx’]) >>> print(pvar.pvx.shape)

pencil.read.phiaver(*args, **kwargs)

Wrapper for Averages.read()

pencil.read.varraw(*args, **kwargs)

varraw(var_file=””, datadir=”data”, proc=-1, ivar=-1, var_list=None, quiet=False, precision=”d”, trimall=False, swap_endian=False)

Read VAR files from Pencil Code. If proc < 0, then load all data and assemble, otherwise load VAR file from specified processor.

The file format written by output() (and used, e.g. in var.dat) consists of the following Fortran records: 1. data(mx, my, mz, nvar) 2. t(1), x(mx), y(my), z(mz), dx(1), dy(1), dz(1), deltay(1) Here nvar denotes the number of slots, i.e. 1 for one scalar field, 3 for one vector field, 8 for var.dat in the case of MHD with entropy. but, deltay(1) is only there if lshear is on! need to know parameters.

Parameters:
  • var_file (string) – Name of the VAR file. If not specified, use var.dat (which is the latest snapshot of the fields)

  • datadir (string) – Directory where the data is stored.

  • proc (int) – Processor to be read. If -1, read all and assemble to one array.

  • ivar (int) – Index of the VAR file, if var_file is not specified.

  • var_list (list of str) – List of variables to read. If not provided or empty, all available variables will be read by default.

  • quiet (bool) – Flag for switching off output.

  • precision (string) – Float ‘f’, double ‘d’ or half ‘half’.

  • trimall (bool) – Trim the data cube to exclude ghost zones.

  • swap_endian (bool) – Flag for swapping the endianness.

Returns:

Class instance containing the varfile information.

Return type:

Varraw

Examples

Read the latest var.dat file and print the shape of the uu array: >>> var = pc.read.varraw() >>> print(var.uu.shape)

Read the VAR2 file, only the logarithmic temperature & density, and remove the ghost zones: >>> var = pc.read.varraw(var_file=’VAR2’, var_list=[‘lnTT’, ‘lnrho’], trimall=True) >>> print(var.lnTT.shape) or >>> print(var.f[:,:,:,var.tags[‘lnTT’]].shape)

Read the VAR2 file, only the vector potential & z-velocity, in single precision: >>> var = pc.read.varraw(ivar=2, var_list=[‘aa’, ‘uz’], precision=’f’) >>> ay = var.ay[:] or >>> ay = var.aa[:,:,:,1] or >>> ay = var.f[:,:,:,var.tags[‘ay’]]

Read the VAR2 file, only the vector potential & z-velocity, in single precision: >>> var = pc.read.varraw(ivar=2, var_list=[‘ax’, ‘uz’,’ay’,’az’], precision=’f’) >>> ay = var.ay[:] or >>> ay = var.aa[:,:,:,1] or >>> ay = var.f[:,:,:,var.tags[‘ay’]]

pencil.read.pstalk2(datadir='data', it0=0, it1=-1, swap_endian=False, quiet=False, noutmax=None, single=False, nstalk=None, ipar=None, read_last=False)

Read Pencil Code particle stalker data (PSTALK) and return a Struct with dot-access fields:

fs.t : (nout,) fs.ipar : (nstalk,) fs.<field>: (nstalk, nout) for each field in particles_stalker_header.dat

Parameters:
  • datadir (str) – Base data directory (e.g. “data”). ~ expansion is supported.

  • it0 (int) – First time index to read (inclusive).

  • it1 (int) – If >0, print a log line whenever it % it1 == 0.

  • swap_endian (bool) – If True, swap endianness when reading the binary PSTALK files.

  • quiet (bool) – If True, suppress most logging.

  • noutmax (int or None) – Maximum number of output times to read. None => use all available. Semantics match IDL: min(noutmax, noutmaxfile), with -1 meaning “all”.

  • single (bool) – If True, store output data in float32; otherwise float64. (Binary precision is auto-detected and then cast.)

  • nstalk (int or None) – Max number of stalked particles to keep. Defaults to pdim.npar_stalk. In non-sink mode, particles with index >= nstalk are ignored. In sink-particle mode, nstalk may be increased internally if needed.

  • ipar (int or list of int or None) – If given, read only these particle indices (memory-efficient).

  • read_last (bool) – If True, read only the last timestep (overrides it0)

Returns:

fs – Container with fields t, ipar, and one field per stalk quantity.

Return type:

Struct

pencil.read.pstalk(*args, **kwargs)

Wrapper for ParticleStalkData