Sources module¶
A module containing tools to convert from CUDS containers to Mayavi
compatible sources. Please use the simphony_mayavi.sources.api
module to access the provided tools.
Classes
ParticlesSource |
SimPhoNy CUDS Particle container to Mayavi Source converter |
LatticeSource |
SimPhoNy CUDS Lattice container to Mayavi Source converter |
MeshSource |
SimPhoNy CUDS Mesh container to Mayavi Source converter |
CUDSDataAccumulator ([keys]) |
Accumulate data information per CUBA key. |
CUDSDataExtractor (**traits) |
Extract data from cuds items iterable. |
Functions
cell_array_slicer (data) |
Iterate over cell components on a vtk cell array |
Description¶
-
class
simphony_mayavi.sources.particles_source.
ParticlesSource
[source]¶ Bases:
mayavi.sources.vtk_data_source.VTKDataSource
SimPhoNy CUDS Particle container to Mayavi Source converter
-
bond2index
= Dict¶ The mapping from the bond uid to the vtk polydata cell index.
-
classmethod
from_particles
(particles)[source]¶ Return a ParticlesSource from a CUDS Particles container.
Parameters: particles (Particles) – The CUDS Particles instance to copy the information from.
-
point2index
= Dict¶ The mapping from the point uid to the vtk polydata points array.
-
-
class
simphony_mayavi.sources.mesh_source.
MeshSource
[source]¶ Bases:
mayavi.sources.vtk_data_source.VTKDataSource
SimPhoNy CUDS Mesh container to Mayavi Source converter
-
element2index
= Dict¶ The mapping from the element uid to the vtk cell index.
-
classmethod
from_mesh
(mesh)[source]¶ Return a MeshSource from a CUDS Mesh container.
Parameters: mesh (Mesh) – The CUDS Mesh instance to copy the information from.
-
point2index
= Dict¶ The mapping from the point uid to the vtk points array.
-
-
class
simphony_mayavi.sources.lattice_source.
LatticeSource
[source]¶ Bases:
mayavi.sources.vtk_data_source.VTKDataSource
SimPhoNy CUDS Lattice container to Mayavi Source converter
-
class
simphony_mayavi.sources.cuds_data_accumulator.
CUDSDataAccumulator
(keys=())[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 when ever a new key is introduced.expand operation
>>> accumulator = CUDSDataAccumulator(): >>> 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 = CUDSDataAccumulator([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. 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 (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.sources.cuds_data_extractor.
CUDSDataExtractor
(**traits)[source]¶ Bases:
traits.has_traits.HasStrictTraits
Extract 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
.
-
-
simphony_mayavi.sources.utils.
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.