postpic.io package

The postpic.io module provides free functions for importing and exporting data.

postpic.io.export_field(filename, field, **kwargs)[source]

export Field object as a file. Format depends on the extention of the filename. Currently supported are: .npz:

uses numpy.savez.
.csv:
uses numpy.savetxt.
.vtk:
vtk export to paraview
postpic.io.load_field(filename)[source]

Load a field object previously stored using the saveto method. These are .npz files with a specific metadata layout.

postpic.io.export_scalar_vtk(filename, scalarfield, **kwargs)[source]

exports one 2D or 3D scalar field object to a VTK file which is suitable for viewing in ParaView. It is assumed that all fields are defined on the same grid.

postpic.io.export_scalars_vtk(filename, *fields, **kwargs)[source]

exports a set of scalar fields to a VTK file suitable for viewing in ParaView. Up to four fields may be given

postpic.io.export_vector_vtk(filename, *fields, **kwargs)[source]

exports a vector field to a VTK file suitable for viewing in ParaView. Three 3D fields are expected, which will form the X, Y and Z component of the vector field. If less than tree fields are given, the missing components will be assumed to be zero.

Submodules

postpic.io.common module

The postpic.io module provides free functions for importing and exporting data.

postpic.io.csv module

The postpic.io module provides free functions for importing and exporting data.

postpic.io.npy module

The postpic.io module provides free functions for importing and exporting data.

postpic.io.vtk module

The postpic.io.vtk module provides classes and functions to export fields to the vtk 2.0 legacy file format.

The files are written in binary form and may have single or double precision.

The vtk exporter is built up from multiple classes, representing the different parts of data that are put into a vtk file:

VtkFile: represents the actual file to be written. Works as a context-manager that opens and
initializes the file on __enter__ and closes the file on __exit__. Next to the actual file object vtkfile.file, it carries the attributes vtkfile.type, vtkfile.dtype` and vtkfile.mode, which are later used to make sure the file is written in the intended format.
VtkData: represents the data that should be written to a file. Has a “tofile” method that will
create a VtkFile and pass it to the “tofile” methods of the other objects that carry the actual data. VtkData stores one object that is an instance of DataSet that defines the grid that the data lives on and one or more objects that are instances of Data that contain the data to be exported.
DataSet: Superclass for different types of grid. Subclasses are StructuredPoints and
RectilinearGrid. They have classmethods .from_field which allow the creation of objects from a given Field.
Data: Superclass for representing either PointData or CellData. So far only
PointData is used. This will be used to contain a subclass of ArrayData.
ArrayData: Superclass for representing a collection of Scalars or Vectors that are stored in
an array that will be created from one or more `Field`s.

Using all of this, writing a vtk file with Scalar data attached to the points (PointData) of a StructuredGrid is as simple as:

VtkData(StructuredPoints.from_field(scalarfield),
PointData(Scalars(scalarfield))

).tofile(filename)

class postpic.io.vtk.ArrayData(*fields, **kwargs)[source]

Bases: object

Superclass to represent different kinds of data that can be attributed to Points or Cells and are given as an iterable of Fields

tofile(vtk)[source]
transform_data(dtype)[source]
class postpic.io.vtk.CellData(arraydata)[source]

Bases: postpic.io.vtk.Data

CellData associated with a DataSet

tofile(vtk)[source]
class postpic.io.vtk.Data(arraydata)[source]

Bases: object

Superclass to represent the attributed data associated with a DataSet.

tofile(vtk)[source]
class postpic.io.vtk.DataSet[source]

Bases: object

Superclass to represent different vtkDataSets

class postpic.io.vtk.PointData(arraydata)[source]

Bases: postpic.io.vtk.Data

PointData associated with a DataSet

tofile(vtk)[source]
class postpic.io.vtk.RectilinearGrid(grid)[source]

Bases: postpic.io.vtk.DataSet

Class to represent a vtkRectilinearGrid

classmethod from_field(field)[source]
tofile(vtk)[source]
class postpic.io.vtk.Scalars(*fields, **kwargs)[source]

Bases: postpic.io.vtk.ArrayData

Class to represent a collection of Scalars

tofile(vtk)[source]
class postpic.io.vtk.StructuredPoints(dimensions, origin, spacing)[source]

Bases: postpic.io.vtk.DataSet

Class to represent a vtkStructuredPoints

classmethod from_field(field)[source]
tofile(vtk)[source]
class postpic.io.vtk.Vectors(*fields, **kwargs)[source]

Bases: postpic.io.vtk.ArrayData

Class to represent Vectors

tofile(vtk)[source]
class postpic.io.vtk.VtkData(dataset, *data)[source]

Bases: object

Class to represent the data that should be written to a .vtk file. Uses VtkFile.

tofile(fname, type='double', mode='binary')[source]
class postpic.io.vtk.VtkFile(fname, type='double', mode='binary')[source]

Bases: object

Class used to write a .vtk file. Used by VtkData.

__enter__()[source]
__exit__(exception_type, exception_value, traceback)[source]
postpic.io.vtk.export_scalar_vtk(filename, scalarfield, **kwargs)[source]

exports one 2D or 3D scalar field object to a VTK file which is suitable for viewing in ParaView. It is assumed that all fields are defined on the same grid.

postpic.io.vtk.export_scalars_vtk(filename, *fields, **kwargs)[source]

exports a set of scalar fields to a VTK file suitable for viewing in ParaView. Up to four fields may be given

postpic.io.vtk.export_vector_vtk(filename, *fields, **kwargs)[source]

exports a vector field to a VTK file suitable for viewing in ParaView. Three 3D fields are expected, which will form the X, Y and Z component of the vector field. If less than tree fields are given, the missing components will be assumed to be zero.