PLaSK User Manual

Data Class

class plask.Data

Data returned by field providers.

This class is returned by field providers and receivers and cointains the values of the computed field at specified mesh points. It can be passed to the field plotting and saving functions or even feeded to some receivers. Also, if the mesh is a rectangular one, the data can be converted into an multi-dimensional numpy array.

You may access the data by indexing the Data object, where the index always corresponds to the index of the mesh point where the particular value is specified. Hence, you may also iterate Data objects as normal Python sequences.

You may construct the data object manually from a numpy array and a mesh. The constructor always take two argumentsa as specified below:

Parameters:
  • array – The array with a custom data. It must be either a one dimensional array with sequential data of the desired type corresponding to the sequential mesh points or (for the rectangular meshes) an array with the same shape as returned by the array attribute.
  • mesh – The mesh specifying where the data points are located. The size of the mesh must be equal to the size of the provided array. Furthermore, when constructing the data from the structured array, the mesh ordering must match the data stride, so it is possible to avoid data copying (defaults for both are fine).
Returns:

Data based on the specified mesh and array.

Return type:

plask._Data

Examples

To create the data from the flat sequential array:

>>> msh = plask.mesh.Rectangular2D([1, 2, 3], [10, 20])
>>> Data(array([1., 2., 3., 4., 5., 6.]), msh)
<plask.Data at 0x4698938>

As the msh is a rectangular mesh, the data can be created from a structured array with the shape (3, 2), as the first and second mesh dimensions are 3 and 2, respectively:

>>> dat = Data(array([[1., 2.], [3., 4.], [5., 6.]]), msh)
>>> dat[0]
1.0

By adding one more dimension, you can create an array of vectors:

>>> d = Data(array([[[1.,0.], [2.,0.]], [[3.,0.], [4.,1.]],
...                 [[5.,1.], [6.,1.]]]), msh)
>>> d.dtype
plask.vec
>>> d[1]
plask.vec(2, 0)
>>> d.array[:,:,0]    # retrieve first components of all the vectors
array([[1., 2.], [3., 4.], [5., 6.]])

Construction of the data objects is efficient i.e. no data is copied in the memory from the provided array.

Methods

interpolate(mesh, interpolation[, geometry]) Interpolate data to a different mesh.

Attributes

array Array formatted by the mesh.
mesh The mesh at which the data was obtained.

Static Attributes

dtype Value type.

Descriptions

Method Details

Data.interpolate(mesh, interpolation, geometry=None)

Interpolate data to a different mesh.

This method interpolated data into a different mesh using specified interpolation method. This is exactly the same interpolation that is usually done by solvers in their providers.

Parameters:
  • mesh – Mesh to interpolate into.
  • interpolation – Requested interpolation method.
  • geometry – Optional geometry, over which the interpolation is performed.
Returns:

Interpolated data.

Return type:

plask._Data

Attribute Details

Data.array

Array formatted by the mesh.

This attribute is available only if the :attr:~plask.Data.mesh` is a rectangular one. It contains the held data reshaped to match the shape of the mesh (i.e. the first dimension is equal the size of the first mesh axis and so on). If the data type is plask.vec then the array has one additional dimention equal to 2 for 2D vectors and 3 for 3D vectors. The vector components are stored in this dimention.

Example

>>> msh = plask.mesh.Rectangular2D(plask.mesh.Rectilinear([1, 2]),
... plask.mesh.Rectilinear([10, 20]))
>>> dat = Data(array([[[1., 0.], [2., 0.]], [[3., 1.], [4., 1.]]]), msh)
>>> dat.array[:,:,0]
array([[1., 2.],
       [3., 4.]])

Accessing this field is efficient, as only the numpy array view is created and no data is copied in the memory.

Data.mesh

The mesh at which the data was obtained.

The sequential points of this mesh always correspond to the sequential points of the data. This implies that len(data.mesh) == len(data) is always True.

Static Attribute Details

plask.Data.dtype

Value type.

This attribute is the type of a single element in this vector.