Core module¶
A module containing core tools and wrappers for vtk data containers used in simphony_mayavi.
Classes
CubaData (attribute_data[, stored_cuba, ...]) |
Map a vtkCellData or vtkPointData object to a sequence of DataContainers. |
CellCollection ([cell_array]) |
A mutable sequence of cells wrapping a tvtk.CellArray. |
mergedocs (other) |
Merge the docstrings of other class to the decorated. |
CUBADataAccumulator ([keys]) |
Accumulate data information per CUBA key. |
CUBADataExtractor (**traits) |
Extract cuba data from cuds items iterable. |
Functions
supported_cuba () |
Return the list of CUBA keys that can be supported by vtk. |
default_cuba_value (cuba) |
Return the default value of the CUBA key as a scalar or numpy array. |
cell_array_slicer (data) |
Iterate over cell components on a vtk cell array |
mergedoc (function, other) |
Merge the docstring from the other function to the decorated function. |
Description¶
-
class
simphony_mayavi.core.cuba_data.
CubaData
(attribute_data, stored_cuba=None, size=None, masks=None)[source]¶ Bases:
_abcoll.MutableSequence
Map a vtkCellData or vtkPointData object to a sequence of DataContainers.
The class implements the
MutableSequence
api to wrap atvtk.CellData
ortvtk.PointData
array where each CUBA key is atvtk.DataArray
. The aim is to help the conversion between column based structure of thevtkCellData
orvtkPointData
and the row based access provided by a list of~.DataContainer
.While the wrapped tvkt container is empty the following behaviour is active:
- Using
len
will return theinitial_size
, if defined, or 0. - Using element access will return an empty class:~.DataContainer.
- No field arrays have been allocated.
When values are first added/updated with non-empty
DataContainers
then the necessary arrays are created and theinitial_size
info is not used anymore.Note
Missing values for the attribute arrays are stored in separate attribute arrays named “<CUBA.name>-mask” as
0
while present values are designated with a1
.Constructor
- attribute_data: tvtk.DataSetAttributes
- The vtk attribute container.
- stored_cuba : set
- The CUBA keys that are going to be stored default
is the result of running
supported_cuba()
- size : int
- The initial size of the container. Default is None. Setting a value will activate the virtual size behaviour of the container.
- mask : tvtk.FieldData
- A data arrays containing the mask of some of the CUBA data in
attribute_data
.
Raises
- ValueError :
- When a non-empty
attribute_data
container is provided while size != None.
-
cubas
¶ The set of currently stored CUBA keys.
For each cuba key there is an associated
DataArray
connected to thePointData
orCellData
-
classmethod
empty
(type_=<AttributeSetType.POINTS: 1>, size=0)[source]¶ Return an empty sequence based wrapping a vtkAttributeDataSet.
Parameters: - size (int) – The virtual size of the container.
- type_ (AttributeSetType) – The type of the vtkAttributeSet to create.
-
insert
(index, value)[source]¶ Insert the values of the DataContainer in the arrays at row=``index``.
If the provided DataContainer contains new, but supported, cuba keys then a new empty array is created for them and updated with the associated values of
value
. Unsupported CUBA keys are ignored.Note
The underline data structure is better suited for append operations. Inserting values in the middle or at the front will be less efficient.
- Using
-
class
simphony_mayavi.core.cell_collection.
CellCollection
(cell_array=None)[source]¶ Bases:
_abcoll.MutableSequence
A mutable sequence of cells wrapping a tvtk.CellArray.
Constructor
Parameters: cell_array (tvtk.CellArray) – The tvtk object to wrap. Default value is an empty tvtk.CellArray. -
__delitem__
(index)[source]¶ Remove cell at
index
.Note
This operation will need to create temporary arrays in order to keep the data info consistent.
-
-
class
simphony_mayavi.core.cuba_data_accumulator.
CUBADataAccumulator
(keys=None)[source]¶ Bases:
object
Accumulate data information per CUBA key.
A collector object that stores :class:
DataContainer
data into a list of values per CUBA key. By appendingDataContainer
instanced the user can effectively convert the per item mapping of data values in a CUDS container to a per CUBA key mapping of the data values (useful for coping data to vtk array containers).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 and missing values will be saved asNone
. Whereexpand
will extend the internal table of values whenever a new key is introduced.expand operation
>>> accumulator = CUBADataAccumulator(): >>> accumulator.append(DataContainer(TEMPERATURE=34)) >>> accumulator.keys() {CUBA.TEMPERATURE} >>> accumulator.append(DataContainer(VELOCITY=(0.1, 0.1, 0.1)) >>> accumulator.append(DataContainer(TEMPERATURE=56)) >>> accumulator.keys() {CUBA.TEMPERATURE, CUBA.VELOCITY} >>> accumulator[CUBA.TEMPERATURE] [34, None, 56] >>> accumulator[CUBA.VELOCITY] [None, (0.1, 0.1, 0.1), None]
fixed operation
>>> accumulator = CUBADataAccumulator([CUBA.TEMPERATURE, CUBA.PRESSURE]): >>> accumulator.keys() {CUBA.TEMPERATURE, CUBA.PRESSURE} >>> accumulator.append(DataContainer(TEMPERATURE=34)) >>> accumulator.append(DataContainer(VELOCITY=(0.1, 0.1, 0.1)) >>> accumulator.append(DataContainer(TEMPERATURE=56)) >>> accumulator.keys() {CUBA.TEMPERATURE, CUBA.PRESSURE} >>> accumulator[CUBA.TEMPERATURE] [34, None, 56] >>> accumulator[CUBA.PRESSURE] [None, None, None] >>> 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. An empty list is acceptable, and returns a trivial accumulator providing no data. If None is passed, then the 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 (list) – A list of data values collected for key
. Missing values are designated withNone
.
-
__len__
()[source]¶ The number of values that are stored per key
Note
Behaviour is temporary and will probably change soon.
-
append
(data)[source]¶ Append info from a
DataContainer
.Parameters: data (DataContainer) – The data information to append. If the accumulator operates in
fixed
mode:- Any keys in
self.keys()
that have values indata
will be stored (appended to the related key lits). - Missing keys will be stored as
None
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 values ofNone
. - 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 store as
None
.
- Any keys in
-
keys
¶ The set of CUBA keys that this accumulator contains.
-
load_onto_vtk
(vtk_data)[source]¶ Load the stored information onto a vtk data container.
Parameters: vtk_data (vtkPointData or vtkCellData) – The vtk container to load the value onto. Data are loaded onto the vtk container based on their data type. The name of the added array is the name of the CUBA key (i.e.
CUBA.name
). Currently only scalars and three dimensional vectors are supported.
-
-
class
simphony_mayavi.core.cuba_data_extractor.
CUBADataExtractor
(**traits)[source]¶ Bases:
traits.has_traits.HasStrictTraits
Extract cuba data from cuds items iterable.
The class that supports extracting data values of a specific CUBA key from an iterable that returns low level CUDS objects (e.g.
Point
).-
available
= Property(Set(CUBATrait), depends_on='_available')¶ The list of cuba keys that are available (read only). The value is recalculated at initialialisation and when the
reset
method is called.
-
data
= Property(Dict(UUID, Any), depends_on='_data')¶ The dictionary mapping of item uid to the extracted data value. A change Event is fired for
data
whenselected
orkeys
change or thereset
method is called.
-
function
= ReadOnly¶ The function to call that returns a generator over the desired items (e.g. Mesh.iter_points). This value cannot be changed after initialisation.
-
keys
= Either(None, Set(UUID))¶ The list of uuid keys to restrict the data extraction. This attribute is passed to the function generator method to restrict iteration over the provided keys (e.g Mesh.iter_points(uids=keys))
-
selected
= CUBATrait¶ Currently selected CUBA key. Changing the selected key will fire events that will result in executing the generator function and extracting the related values from the CUDS items that the iterator yields. The resulting mapping of
uid -> value
will be stored indata
.
-
-
class
simphony_mayavi.core.doc_utils.
mergedocs
(other)[source]¶ Bases:
object
Merge the docstrings of other class to the decorated.
-
simphony_mayavi.core.cuba_utils.
supported_cuba
()[source]¶ Return the list of CUBA keys that can be supported by vtk.
-
simphony_mayavi.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
.Note
Only vector and scalar values are currently supported.
-
simphony_mayavi.core.cell_array_tools.
cell_array_slicer
(data)[source]¶ Iterate over cell components on a vtk cell array
VTK stores the associated point index for each cell in a one dimensional array based on the following template:
[n, id0, id1, id2, ..., idn, m, id0, ...]
The iterator takes a cell array and returns the point indices for each cell.