simphony / simphony-mayavi Goto Github PK
View Code? Open in Web Editor NEWThe mayavi adapters to the simphony framework
License: BSD 2-Clause "Simplified" License
The mayavi adapters to the simphony framework
License: BSD 2-Clause "Simplified" License
A new class named ParticleSource
subclass of the VTKDataSource class needs to be implemented.
class ParticleSource(VTKDataSource):
""" A mayavi source wrapper to a CUDS Particles instance.
.. note::
Attributes used for visualization are imported lazily from the CUDS container.
"""
@classmethod
def from_particles(cls, particles):
""" Create a new VTKDataSource based on particles
The method extracts the x,y,z position of the particles and the bond connectivity to populate
a vtk.PolyData source.
"""
The aim is to reduce the memory footprint during visualization.
LatticeSource is a mayavi Source wrapping a Lattice instance.
I added a EngineSource
(similar to CUDSFileSource
) for handling datasets from a simphony modeling engine. Then I added a EngineSourceManager
for visualisation and basic operations of the engine. The screenshot below is the EngineSourceManager
in action. (I actually used it on an engine from simphony-lammps
)
@dpinte, @itziakos, the new feature is currently available in the branch add-engine-source
. I still need to add more tests and documentation before I can make a PR. At the moment I would like to solicit feedbacks.
If you could check out the branch, there is a dummy engine so you can experiment with the following:
>>> from simphony_mayavi.sources.tests import testing_utils
>>> engine = testing_utils.DummyEngine()
>>> from simphony_mayavi.plugins.api import EngineSourceManager
>>> manager = EngineSourceManager(engine)
>>> manager.show_config() # show the UI
If you dig into the code you will find some in-function imports. That's because I intend to make it available as a plugin in Mayavi (ref)
Please let me know if you have any comments/suggestions.
The test codes needs to be cleaned-up
The following example demonstrates the issue
In [10] points = tvtk.Points()
In [11]: points.insert_next_point((0,1,2))
Out[11]: 0L
In [12]: points[0]
Out[12]: (0.0, 1.0, 2.0)
In [13]: points[0L] # raises TypeError
Having these masks in the vtkDatasets makes operations more complicated. It is probably better to store this information in the wrapper.
A MeshSource is a Mayavi source that wraps a simphony Mesh container
So that a user can do something like this:
from simphony.visualization import mayavi_tools
from mayavi import mlab
engine = ... # do some stuff setting up a simulation...
# add a bunch of datasets to the same scene
source1 = mayavi_tools.add_to_scene(engine.get_dataset("lattice1"), point_scalar="TEMPERATURE") # show temperature only
source2 = mayavi_tools.add_to_scene(engine.get_dataset("lattice2"), point_vector="MASS")
# run the simulation N times
# update the scene
for i in xrange(N):
engine.run()
source1.update()
source2.update()
mlab.savefig("saved_{}.png".format(i))
Similar to show
, but show
is synchronous
This function can be used by show
and snapshot
. The signature for these functions should be the same.
This is the reverse wrapper that the VTKLattice and others. It would be cool to have this but, the implementation is not trivial.
The requirement for vtk is not listed at http://simphony-mayavi.readthedocs.org/en/latest/
A CUDSDataSelector
is a class that operates on a CUDS container item iterator is described as follows:
class CUDSDataExtractor(HasStrictTraits):
"""
"""
#: The function to call that iterates over the desired items. Iteration
#: should return a tuple of (uid, data).
function = Callable
# The list of keys to restrict the data extraction.
keys = Either(None, List(UUID))
#: The list of cuba keys that are available (read only)
available = Property(List(CUBA), depends_on='function')
#: Currently selected CUBA key
selected = Instance(CUBA)
#: The dictionary mapping uid to the extracted value.
data = Property(Dict(Instance(UUID), Any), depends_on='selected, available')
I try to get the latest mayavi wrapper installed, put it fails in unittest.
Ubuntu 12.04LTS on VM
Mayavi version 4.4.3
simphony-common version 0.3.0
python -m unittest discover
Xlib: extension "RANDR" missing on display "localhost:13.0".
/usr/local/lib/python2.7/dist-packages/traits/etsconfig/etsconfig.py:373: UserWarning: Environment variable "HOME" not set, setting home directory to /tmp
(environment_variable, parent_directory))
...../root/simphony-mayavi/simphony_mayavi/core/cuba_data_accumulator.py:144: UserWarning: property <CUBA.NAME: 1> is currently ignored
warnings.warn(message.format(cuba))
....................../root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.NAME: 1> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.CHEMICAL_SPECIE: 7> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.CRYSTAL_STORAGE: 14> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.NAME_UC: 15> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.LATTICE_VECTORS: 16> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:50: UserWarning: ignored property <CUBA.BOND_LABEL: 19> : not a vector or scalar
warnings.warn(message.format(cuba))
/root/simphony-mayavi/simphony_mayavi/core/cuba_utils.py:38: UserWarning: ignored property <CUBA.MATERIAL: 68> : not a float or int
warnings.warn(message.format(cuba))
........................................................................................................................................................................................................................................................................ssssQObject::startTimer: QTimer can only be used with threads started with QThread
EQObject::startTimer: QTimer can only be used with threads started with QThread
EQObject::startTimer: QTimer can only be used with threads started with QThread
E.Segmentation fault (core dumped)
parameter names defined in several functions (e.g. vtk_particles.add_particles(particles)) are not consistent with the docstring defined in the ABC
One should be able to create a CubaData
instance with an initial size but without any allocated vtk arrays. The container should return an empty DataContainer
when item access is perfomed. memory space should be allocated as soon as an non empty DataContainer
value is added/updated in the sequence.
To reproduce the bug
import numpy
from tvtk.api import tvtk
from simphony_mayavi.core.api import CellCollection
# Create a cell array with a tetra cell and a hex cell
points = numpy.array([[0,0,0], [1,0,0], [0,1,0], [0,0,1], # tetra
[2,0,0], [3,0,0], [3,1,0], [2,1,0],
[2,0,1], [3,0,1], [3,1,1], [2,1,1], # Hex
], 'f')
cells = numpy.array([4, 0, 1, 2, 3, # tetra
8, 4, 5, 6, 7, 8, 9, 10, 11 # hex
])
offset = numpy.array([0,5])
tetra_type = tvtk.Tetra().cell_type
hex_type = tvtk.Hexahedron().cell_type
cell_types = numpy.array([tetra_type, hex_type])
cell_array = tvtk.CellArray()
cell_array.set_cells(2, cells)
ug = tvtk.UnstructuredGrid(points=points)
ug.set_cells(cell_types, offset, cell_array)
elements = CellCollection(ug.get_cells())
# update the first cell to a wedge cell
elements[0] = [0, 1, 2, 3, 4, 5] # a wedge
ug.get_cells().to_array() # is okay
# get point ids for the hex cell, should get 8 points
ug.get_cell(1).point_ids # gives [5L, 8L, 4L, 5L]...oops!
To fix it:
# because the cell_type_array and cell_location_array are not updated
ug.cell_types_array
ug.cell_locations_array
# update cell type
ug.cell_types_array[0] = tvtk.Wedge().cell_type
# modify location
ug.cell_locations_array[1] = 7
ug.get_cell(1).point_ids # gives [4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L]
@itziakos , shall I modify CellCollection or do you already have it implemented some where?
Running tests on an ubuntu VM connected through vpn the snapshot tests fail with the following tracebacks.
simphony_mayavi.tests.test_snapshot.TestSnapShot
======================================================================
FAIL: test_lattice_snapshot (simphony_mayavi.tests.test_snapshot.TestSnapShot)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 31, in test_lattice_snapshot
self.assertImageSavedWithContent(filename)
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 67, in assertImageSavedWithContent
self.assertEqual(image.shape[:2], (600, 800))
AssertionError: Tuples differ: (320, 400) != (600, 800)
First differing element 0:
320
600
- (320, 400)
+ (600, 800)
======================================================================
FAIL: test_mesh_snapshot (simphony_mayavi.tests.test_snapshot.TestSnapShot)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 45, in test_mesh_snapshot
self.assertImageSavedWithContent(filename)
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 67, in assertImageSavedWithContent
self.assertEqual(image.shape[:2], (600, 800))
AssertionError: Tuples differ: (320, 400) != (600, 800)
First differing element 0:
320
600
- (320, 400)
+ (600, 800)
======================================================================
FAIL: test_particles_snapshot (simphony_mayavi.tests.test_snapshot.TestSnapShot)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 59, in test_particles_snapshot
self.assertImageSavedWithContent(filename)
File "/home/kaitsu/simphony-mayavi/simphony_mayavi/tests/test_snapshot.py", line 67, in assertImageSavedWithContent
self.assertEqual(image.shape[:2], (600, 800))
AssertionError: Tuples differ: (320, 400) != (600, 800)
First differing element 0:
320
600
- (320, 400)
+ (600, 800)
----------------------------------------------------------------------
Ran 32 tests in 16.228s
FAILED (failures=3)
Using the 3D glyph for each point in the containers uses to much memory and makes processing and interaction very slow.
First occurrence of these two errors in build: https://travis-ci.org/simphony/simphony-mayavi/jobs/76682346
and have persisted as of today.
test_load_blowGeom_vtk (simphony_mayavi.tests.test_load.TestLoad) ... ERROR: In /build/buildd/vtk-5.8.0/Graphics/vtkAssignAttribute.cxx, line 275
vtkAssignAttribute (0xac66660): Data must be point or cell for vtkDataSet
ERROR: In /build/buildd/vtk-5.8.0/Filtering/vtkExecutive.cxx, line 756
vtkStreamingDemandDrivenPipeline (0xac8e6e0): Algorithm vtkAssignAttribute(0xac66660) returned failure for request: vtkInformation (0xa5721c0)
Debug: Off
Modified Time: 1073826
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0
FROM_OUTPUT_PORT: 0
ok
test_load_vtk_vtk (simphony_mayavi.tests.test_load.TestLoad) ... ERROR: In /build/buildd/vtk-5.8.0/Graphics/vtkAssignAttribute.cxx, line 275
vtkAssignAttribute (0xac66660): Data must be point or cell for vtkDataSet
ERROR: In /build/buildd/vtk-5.8.0/Filtering/vtkExecutive.cxx, line 756
vtkStreamingDemandDrivenPipeline (0xa9675a0): Algorithm vtkAssignAttribute(0xac66660) returned failure for request: vtkInformation (0xa571430)
Debug: Off
Modified Time: 1074970
Reference Count: 1
Registered Events: (none)
Request: REQUEST_DATA
ALGORITHM_AFTER_FORWARD: 1
FORWARD_DIRECTION: 0
FROM_OUTPUT_PORT: 0
ok
testing_utils
all over the place now. Need to reorganise them.
Trying to visualize mesh made of multiple blocks on OpenFoam. If some module is added in mayavi2 (for example Vectors) Segmentation fault is gained. Using simple one block mesh everything seems to work. Attached are files to reproduce the error
and remove the redundant definitions of other lattices
Assume Mayavi 4.4.3.
Possible implementations:
Signature:
snapshot(cuds, filename, data=None, restore_visualisation=None)
Usage:
snapshot(cuds=particles, filename="saved.png",
data=("TEMPERATURE", "VELOCITY"),
restore_visualisation="saved_scene.mv2") # saved_scene.mv2 is previously saved
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.