Code Monkey home page Code Monkey logo

simphony-mayavi's People

Contributors

dpinte avatar itziakos avatar kitchoi avatar stefanoborini avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

simphony-mayavi's Issues

Add a PartcleSource class to wrap a Cuds particle container

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.

        """

Mayavi Source for Simphony Engine

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)
engine_source_manager

@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.

Cleanup test code

The test codes needs to be cleaned-up

  • Remove in-class code duplication
  • Add comments on what is tested

Expose add-to-scene function to mayavi_tools

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.

Implement CUDSDataExtractor

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')

unittest failes

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)

CubaData should support lazy initialization

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.

Changing cell type using CellCollection leads to inconsistent result from unstructured_grid.get_cell

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?

Default snapshot size is not respected

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)

VTK Error for test_load_blowGeom_vtk and test_load_vtk_vtk

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.