pencil.read.varraw

Contains classes and methods to read the varfile data. Fortran binary varfiles for all Pencil code I/O schemes supported. Selective reading of variables supported. The section with vector_groups is incomplete. Please add variable names as necessary. Reading reduced varfiles from ‘data/reduced’ not implemented, since that would require the same to be implemented in at least dims.py as well (and in grids.py also for completeness). swap_endian option has not been tested. Persistent variables not yet implemented. Downsampled snapshots not implemented. OGVAR files not implemented. IMPORTANT: the f array returned is Fortran-ordered: f[nx, ny, nz, nvar]. Please transpose if required.

Classes

Varraw

Varraw -- holds Pencil Code VAR file data.

Functions

varraw(*args, **kwargs)

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

Module Contents

pencil.read.varraw.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’]]

class pencil.read.varraw.Varraw

Bases: object

Varraw – holds Pencil Code VAR file data.

Fill members with default values.

t = 0.0
x = None
y = None
z = None
f = None
l1 = None
l2 = None
m1 = None
m2 = None
n1 = None
n2 = None
keys()
read(var_file='', datadir='data', proc=-1, ivar=-1, var_list=None, quiet=False, precision='d', trimall=False, swap_endian=False)

read(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 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’]]