Core module¶
A module containing core tools and wrappers for paraview data containers used in simphony_paraview.
Classes
CUBADataAccumulator ([keys, container]) |
Accumulate data information per CUBA key. |
Functions
supported_cuba () |
Return a set of currently supported CUBA keys. |
default_cuba_value (cuba) |
Return the default value of the CUBA key as a scalar or numpy array. |
cuds2vtk (cuds) |
Create a vtk.Dataset from a CUDS container |
Mappings
points2edge () |
Return a mapping from number of points to line cells. |
points2face () |
Return a mapping from number of points to face cells. |
points2cell () |
Return a mapping from number of points to volume cells. |
dataset2writer () |
Return a mapping from dataset type to writer instances. |
cuba_value_types () |
Return a mapping from CUBA to VALUETYPE. |
Description¶
-
class
simphony_paraview.core.cuba_data_accumulator.
CUBADataAccumulator
(keys=(), container=None)[source]¶ Bases:
object
Accumulate data information per CUBA key.
A collector object that stores :class:
DataContainer
data into a vtkPointData or vtkCellData array containers where each CUBA key is an array.The Accumulator has two modes of operation
fixed
andexpand
.fixed
means that data will be stored for a predefined set of keys on everyappend
call. Whereexpand
will extend the internal table of values whenever a new key is introduced. Missing values will be stored usingdefault_cuba_value()
.expand operation
>>> accumulator = CUBADataAccumulator(): >>> accumulator.append(DataContainer(TEMPERATURE=34)) >>> accumulator.keys set([<CUBA.TEMPERATURE: 55>]) >>> accumulator.append(DataContainer(VELOCITY=(0.1, 0.1, 0.1)) >>> accumulator.append(DataContainer(TEMPERATURE=56)) >>> accumulator.keys set([<CUBA.VELOCITY: 21>, <CUBA.TEMPERATURE: 55>]) >>> vtk_to_numpy(accumulator[CUBA.TEMPERATURE]) array([ 34., nan, 56.]) >>> vtk_to_numpy(accumulator[CUBA.VELOCITY]) array([[ nan, nan, nan], [ 0.1, 0.1, 0.1], [ nan, nan, nan]])
fixed operation
>>> accumulator = CUBADataAccumulator([CUBA.TEMPERATURE, CUBA.PRESSURE]) >>> accumulator.keys set([<CUBA.PRESSURE: 54>, <CUBA.TEMPERATURE: 55>]) >>> accumulator.append(DataContainer(TEMPERATURE=34)) >>> accumulator.append(DataContainer(VELOCITY=(0.1, 0.1, 0.1)) >>> accumulator.append(DataContainer(TEMPERATURE=56)) >>> accumulator.keys set([<CUBA.PRESSURE: 54>, <CUBA.TEMPERATURE: 55>]) >>> vtk_to_numpy(accumulator[CUBA.TEMPERATURE]) array([ 34., nan, 56.]) >>> vtk_to_numpy(accumulator[CUBA.PRESSURE]) [nan, nan, nan] >>> accumulator[CUBA.VELOCITY] KeyError(...)
Constructor
Parameters: keys (list) – The list of keys that the accumulator should care about. Providing this value at initialisation sets up the accumulator to operate in fixed
mode. If no keys are provided then accumulator operates inexpand
mode.-
__getitem__
(key)[source]¶ Get the list of accumulated values for the CUBA key.
Parameters: key (CUBA) – A CUBA Enum value Returns: result (vtkDataArray) – An array of data values collected for
key
. Missing values are assigned the default value as returned by :function:`~.default_cuba_value`.Raises: KeyError – When values for the requested CUBA key do not exist.
-
append
(data)[source]¶ Append data from a
DataContainer
.If the accumulator operates in
fixed
mode:- Any keys in
self.keys()
that have values indata
will be stored (appended to the related key arrays). - Missing keys will be stored with the
returned value of the
default_cuba_value()
.
If the accumulator operates in
expand
mode:- Any new keys in Data will be added to the
self.keys()
list and the related list of values with length equal to the current record size will be initialised with the returned value of thedefault_cuba_value()
. - Any keys in the modified
self.keys()
that have values indata
will be stored (appended to the list of the related key). - Missing keys will be stored with the
returned value of the
default_cuba_value()
.
Parameters: data (DataContainer) – The data information to append. - Any keys in
-
keys
¶ The set of CUBA keys that this accumulator contains.
-
-
simphony_paraview.core.cuba_utils.
supported_cuba
()[source]¶ Return a set of currently supported CUBA keys.
-
simphony_paraview.core.cuba_utils.
default_cuba_value
(cuba)[source]¶ Return the default value of the CUBA key as a scalar or numpy array.
Int type values have
-1
as default, while float type values havenumpy.nan
.
-
simphony_paraview.core.constants.
points2edge
()[source]¶ Return a mapping from number of points to line cells.
-
simphony_paraview.core.constants.
points2face
()[source]¶ Return a mapping from number of points to face cells.
-
simphony_paraview.core.constants.
points2cell
()[source]¶ Return a mapping from number of points to volume cells.