{Mayavi} Random points in a cube

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

{Mayavi} Random points in a cube

Gökhan SEVER
Hello,

Any ideas why I can't change color of the points?

I[1]: from enthought.mayavi import mlab

I[2]: r = np.random.uniform(0,5,size=[3,1,300])

I[3]: mlab.points3d(r[0],r[1],r[2], scale_factor=0.5)
O[3]: <enthought.mayavi.modules.glyph.Glyph object at 0xc48774c>

I[4]: ---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)

/home/gsever/Desktop/python-repo/ETS_3.3.1/TraitsBackendWX_3.2.1/enthought/traits/ui/wx/color_editor.pyc in color_selected(self, event)
    140         color = event.GetColour()
    141         try:
--> 142             self.value = color
    143         except ValueError:
    144             pass

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in _set_value(self, value)
    240     def _set_value ( self, value ):
    241         if self.name != 'None':
--> 242             self.ui.do_undoable( self.__set_value, value )
    243
    244     def __set_value ( self, value ):

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/ui.pyc in do_undoable(self, action, *args, **kw)
    707                 self._undoable = self.history.now
    708
--> 709             action( *args, **kw )
    710         finally:
    711             if undoable == -1:

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in __set_value(self, value)
    253                             getattr( handler, '%s_setattr' % name, None ) or
    254                             getattr( handler, 'setattr' ))
--> 255                 method( self.ui.info, self.object, name, value )
    256             except TraitError, excp:
    257                 self.error( excp )

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/handler.pyc in setattr(self, info, object, name, value)
    274
    275         """
--> 276         setattr( object, name, value )
    277
    278     #---------------------------------------------------------------------------


/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/trait_handlers.pyc in error(self, object, name, value)
    173         """
    174         raise TraitError( object, name, self.full_info( object, name, value ),
--> 175                           value )
    176
    177     def arg_error ( self, method, arg_num, object, name, value ):

TraitError: The 'color' trait of a CameraLight instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(226, 37, 37, 255) <class 'wx._gdi.Colour'> was specified.


Trying to set the foreground via the GUI yields similar result:

TraitError: The 'foreground' trait of a MayaviScene instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(255, 255, 255, 255) <class 'wx._gdi.Colour'> was specified.

Should be rev_25196
https://svn.enthought.com/svn/enthought/Mayavi/trunk

This is Fedora 12
Linux ccn 2.6.31.9-174.fc12.i686.PAE #1 SMP Mon Dec 21 06:04:56 UTC 2009 i686 i686 i386 GNU/Linux

Thanks

--
Gökhan

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: {Mayavi} Random points in a cube

Gökhan SEVER


On Sat, Feb 6, 2010 at 4:37 PM, Gökhan Sever <[hidden email]> wrote:
Hello,

Any ideas why I can't change color of the points?

I[1]: from enthought.mayavi import mlab

I[2]: r = np.random.uniform(0,5,size=[3,1,300])

I[3]: mlab.points3d(r[0],r[1],r[2], scale_factor=0.5)
O[3]: <enthought.mayavi.modules.glyph.Glyph object at 0xc48774c>

I[4]: ---------------------------------------------------------------------------
TraitError                                Traceback (most recent call last)

/home/gsever/Desktop/python-repo/ETS_3.3.1/TraitsBackendWX_3.2.1/enthought/traits/ui/wx/color_editor.pyc in color_selected(self, event)
    140         color = event.GetColour()
    141         try:
--> 142             self.value = color
    143         except ValueError:
    144             pass

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in _set_value(self, value)
    240     def _set_value ( self, value ):
    241         if self.name != 'None':
--> 242             self.ui.do_undoable( self.__set_value, value )
    243
    244     def __set_value ( self, value ):

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/ui.pyc in do_undoable(self, action, *args, **kw)
    707                 self._undoable = self.history.now
    708
--> 709             action( *args, **kw )
    710         finally:
    711             if undoable == -1:

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc in __set_value(self, value)
    253                             getattr( handler, '%s_setattr' % name, None ) or
    254                             getattr( handler, 'setattr' ))
--> 255                 method( self.ui.info, self.object, name, value )
    256             except TraitError, excp:
    257                 self.error( excp )

/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/handler.pyc in setattr(self, info, object, name, value)
    274
    275         """
--> 276         setattr( object, name, value )
    277
    278     #---------------------------------------------------------------------------


/home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/trait_handlers.pyc in error(self, object, name, value)
    173         """
    174         raise TraitError( object, name, self.full_info( object, name, value ),
--> 175                           value )
    176
    177     def arg_error ( self, method, arg_num, object, name, value ):

TraitError: The 'color' trait of a CameraLight instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(226, 37, 37, 255) <class 'wx._gdi.Colour'> was specified.


Trying to set the foreground via the GUI yields similar result:

TraitError: The 'foreground' trait of a MayaviScene instance must be a tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of wx.Colour(255, 255, 255, 255) <class 'wx._gdi.Colour'> was specified.

Should be rev_25196
https://svn.enthought.com/svn/enthought/Mayavi/trunk

This is Fedora 12
Linux ccn 2.6.31.9-174.fc12.i686.PAE #1 SMP Mon Dec 21 06:04:56 UTC 2009 i686 i686 i386 GNU/Linux

Thanks

--
Gökhan

Additional question,

I want to be able to scale my sphere glyphs scaled by vector components to get some oblate looking particles. So far, I haven't figure out how to add vector source into my scalar data. advanced_visualization/glyph.py example gives a demonstration but there it reads an xml file which I want to go with numpy created arrays. Setting the theta resolution lower gives somewhat an oblate view but not with full control.

Any pointers how to do this?

PS: See my gamma size-distributed uniformly placed particles at my blog http://pycloud.blogspot.com/2010/02/random-particles-in-cube.html
I like it so much and made it my desktop background, and I like RandomState functionality from the numpy.random to reproduce the same look each time I instantiated the script --thanks for R. Kern's wonderful Stats tutorial for this.

These particles represent a sample rain-distribution in a cloud. Their distribution is also not much different than what you see in your bathroom curtain when you are taking a hot shower. Look closely you will see many small condensed water droplets and only a few big drops --where Gamma and alike distributions nicely represent a natural phenomenon. Of course they are warped spheres on one axis -not in 3D. 


Thanks.

--
Gökhan

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

Gael Varoquaux
In reply to this post by Gökhan SEVER
Hi there,

I can confirm that on trunk, the color choosing editor seems broken for
Wx.

Cheers,

Gaël

On Sat, Feb 06, 2010 at 04:37:36PM -0600, Gökhan Sever wrote:
>    Hello,

>    Any ideas why I can't change color of the points?

>    I[1]: from enthought.mayavi import mlab

>    I[2]: r = np.random.uniform(0,5,size=[3,1,300])

>    I[3]: mlab.points3d(r[0],r[1],r[2], scale_factor=0.5)
>    O[3]: <enthought.mayavi.modules.glyph.Glyph object at 0xc48774c>

>    I[4]:
>    ---------------------------------------------------------------------------
>    TraitError                               
>    Traceback (most recent call last)

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/TraitsBackendWX_3.2.1/enthought/traits/ui/wx/color_editor.pyc
>    in color_selected(self, event)
>        140         color = event.GetColour()
>        141         try:
>    --> 142             self.value = color
>        143         except ValueError:
>        144             pass

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc
>    in _set_value(self, value)
>        240     def _set_value ( self, value ):
>        241         if [1]self.name != 'None':
>    --> 242             self.ui.do_undoable( self.__set_value,
>    value )
>        243
>        244     def __set_value ( self, value ):

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/ui.pyc
>    in do_undoable(self, action, *args, **kw)
>        707                 self._undoable =
>    self.history.now
>        708
>    --> 709             action( *args, **kw )
>        710         finally:
>        711             if undoable == -1:

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc
>    in __set_value(self, value)
>        253                            
>    getattr( handler, '%s_setattr' % name, None ) or
>        254                            
>    getattr( handler, 'setattr' ))
>    --> 255                 method( [2]self.ui.info,
>    self.object, name, value )
>        256             except TraitError, excp:
>        257                 self.error( excp )

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/handler.pyc
>    in setattr(self, info, object, name, value)
>        274
>        275         """
>    --> 276         setattr( object, name, value )
>        277
>        278    
>    #---------------------------------------------------------------------------

>    /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/trait_handlers.pyc
>    in error(self, object, name, value)
>        173         """
>        174         raise TraitError( object, name, self.full_info(
>    object, name, value ),
>    --> 175                           value )
>        176
>        177     def arg_error ( self, method, arg_num, object, name,
>    value ):

>    TraitError: The 'color' trait of a CameraLight instance must be a tuple of
>    the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a floating point
>    number <= 1.0, 0.0 <= a floating point number <= 1.0), but a value of
>    wx.Colour(226, 37, 37, 255) <class 'wx._gdi.Colour'> was specified.

>    Trying to set the foreground via the GUI yields similar result:

>    TraitError: The 'foreground' trait of a MayaviScene instance must be a
>    tuple of the form: (0.0 <= a floating point number <= 1.0, 0.0 <= a
>    floating point number <= 1.0, 0.0 <= a floating point number <= 1.0), but
>    a value of wx.Colour(255, 255, 255, 255) <class 'wx._gdi.Colour'> was
>    specified.

>    Should be rev_25196
>    [3]https://svn.enthought.com/svn/enthought/Mayavi/trunk

>    This is Fedora 12
>    Linux ccn 2.6.31.9-174.fc12.i686.PAE #1 SMP Mon Dec 21 06:04:56 UTC 2009
>    i686 i686 i386 GNU/Linux

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: {Mayavi} Random points in a cube

Gael Varoquaux
In reply to this post by Gökhan SEVER
Hi Gokhan,

>    I want to be able to scale my sphere glyphs scaled by vector
> components to get some oblate looking particles. So far, I haven't figure
> out how to add vector source into my scalar data.
> advanced_visualization/glyph.py example gives a demonstration but there
> it reads an xml file which I want to go with numpy created arrays.
> Setting the theta resolution lower gives somewhat an oblate view but not
> with full control.

>   Any pointers how to do this?

To have scalars and vectors together, all you need is to create vectors,
with additional scalars:

    from enthought.mayavi import mlab
    import numpy as np

    x, y, z, s, u, v, w = np.random.random((7, 10))
    src = mlab.pipeline.vector_scatter(x, y, z, u, v, w, scalars=s)

You could also use quiver3d for that.

But anyhow, what you want to do won't work here, because you want objects
that are very asymetric. Your best option is to use tensors and the
TensorGlyph module. The idea is that you give a tensor (3x3 matrix) for
each glyph, the eigen values of the tensor give the scaling, and the
eigven vectors give the corresponding directions.  It's your lucky day, I
have done all the calculations this morning to have closed formulas with
tensor to have the direction set by (u, v, w) vectors, and some
flattening in this direction:

    from enthought.mayavi import mlab
    mlab.clf()

    import numpy as np

    x, y, z, s, u, v, w = np.random.random((7, 10))
    src = mlab.pipeline.scalar_scatter(x, y, z, s)

    scale = np.sqrt(u**2 + v**2 + w**2)
    u /= scale
    v /= scale
    w /= scale

    # Add tensor data
    o = np.zeros_like(x)
    i = np.ones_like(x)
    src.mlab_source.dataset.point_data.tensors = \
        np.c_[.5*u, .5*v, .5*w,
            w/np.sqrt(w**2+u**2), o, -u/np.sqrt(w**2+u**2),
            -v*u/np.sqrt(v**2*(u**2 + w**2)
                + w**4 + u**4 + 2*u**2*w**2),
                        (w**2+u**2)/np.sqrt(v**2*(u**2 + w**2)
                            + w**4 + u**4 + 2*u**2*w**2),
                                -v*w/np.sqrt(v**2*(u**2 + w**2)
                                                   + w**4 + u**4 + 2*u**2*w**2)]


    t_glyph = mlab.pipeline.tensor_glyph(src)
    t_glyph.glyph.glyph.extract_eigenvalues = False

    mlab.quiver3d(x, y, z, u, v, w)

    mlab.show()

The ugly closed formula for the tensors is simply obtained by creating an
orthogonal basis with (u, v, w) as a first vector, and scaling this first
vector by .5.

It would be nice to have a function that does pretty much that: take a
set of (u, v, w) vectors to give a direction and main-axis scaling, a set
of scalings 's' to give a lateral scaling, and create the corresponding
tensors and TensorGlyph. Do you feel like writing one?

HTH,

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

bryce hendrix-2
In reply to this post by Gael Varoquaux
On 02/08/2010 12:17 AM, Gael Varoquaux wrote:
> Hi there,
>
> I can confirm that on trunk, the color choosing editor seems broken for
> Wx.
>
>    

Seems to work in the demo, but I'll take a look at it today.


Bryce

> Cheers,
>
> Gaël
>
> On Sat, Feb 06, 2010 at 04:37:36PM -0600, Gökhan Sever wrote:
>    
>>     Hello,
>>      
>    
>>     Any ideas why I can't change color of the points?
>>      
>    
>>     I[1]: from enthought.mayavi import mlab
>>      
>    
>>     I[2]: r = np.random.uniform(0,5,size=[3,1,300])
>>      
>    
>>     I[3]: mlab.points3d(r[0],r[1],r[2], scale_factor=0.5)
>>     O[3]:<enthought.mayavi.modules.glyph.Glyph object at 0xc48774c>
>>      
>    
>>     I[4]:
>>     ---------------------------------------------------------------------------
>>     TraitError                              
>>     Traceback (most recent call last)
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/TraitsBackendWX_3.2.1/enthought/traits/ui/wx/color_editor.pyc
>>     in color_selected(self, event)
>>         140         color = event.GetColour()
>>         141         try:
>>     -->  142             self.value = color
>>         143         except ValueError:
>>         144             pass
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc
>>     in _set_value(self, value)
>>         240     def _set_value ( self, value ):
>>         241         if [1]self.name != 'None':
>>     -->  242             self.ui.do_undoable( self.__set_value,
>>     value )
>>         243
>>         244     def __set_value ( self, value ):
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/ui.pyc
>>     in do_undoable(self, action, *args, **kw)
>>         707                 self._undoable =
>>     self.history.now
>>         708
>>     -->  709             action( *args, **kw )
>>         710         finally:
>>         711             if undoable == -1:
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/editor.pyc
>>     in __set_value(self, value)
>>         253                            
>>     getattr( handler, '%s_setattr' % name, None ) or
>>         254                            
>>     getattr( handler, 'setattr' ))
>>     -->  255                 method( [2]self.ui.info,
>>     self.object, name, value )
>>         256             except TraitError, excp:
>>         257                 self.error( excp )
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/ui/handler.pyc
>>     in setattr(self, info, object, name, value)
>>         274
>>         275         """
>>     -->  276         setattr( object, name, value )
>>         277
>>         278    
>>     #---------------------------------------------------------------------------
>>      
>    
>>     /home/gsever/Desktop/python-repo/ETS_3.3.1/Traits_3.2.1/enthought/traits/trait_handlers.pyc
>>     in error(self, object, name, value)
>>         173         """
>>         174         raise TraitError( object, name, self.full_info(
>>     object, name, value ),
>>     -->  175                           value )
>>         176
>>         177     def arg_error ( self, method, arg_num, object, name,
>>     value ):
>>      
>    
>>     TraitError: The 'color' trait of a CameraLight instance must be a tuple of
>>     the form: (0.0<= a floating point number<= 1.0, 0.0<= a floating point
>>     number<= 1.0, 0.0<= a floating point number<= 1.0), but a value of
>>     wx.Colour(226, 37, 37, 255)<class 'wx._gdi.Colour'>  was specified.
>>      
>    
>>     Trying to set the foreground via the GUI yields similar result:
>>      
>    
>>     TraitError: The 'foreground' trait of a MayaviScene instance must be a
>>     tuple of the form: (0.0<= a floating point number<= 1.0, 0.0<= a
>>     floating point number<= 1.0, 0.0<= a floating point number<= 1.0), but
>>     a value of wx.Colour(255, 255, 255, 255)<class 'wx._gdi.Colour'>  was
>>     specified.
>>      
>    
>>     Should be rev_25196
>>     [3]https://svn.enthought.com/svn/enthought/Mayavi/trunk
>>      
>    
>>     This is Fedora 12
>>     Linux ccn 2.6.31.9-174.fc12.i686.PAE #1 SMP Mon Dec 21 06:04:56 UTC 2009
>>     i686 i686 i386 GNU/Linux
>>      
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>    

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

bryce hendrix-2
In reply to this post by Gael Varoquaux
On 02/08/2010 12:17 AM, Gael Varoquaux wrote:
> Hi there,
>
> I can confirm that on trunk, the color choosing editor seems broken for
> Wx.
>
>    

Okay, give it another shot please.

Bryce
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

Gael Varoquaux
On Mon, Feb 08, 2010 at 05:55:54PM -0600, bryce hendrix wrote:
> On 02/08/2010 12:17 AM, Gael Varoquaux wrote:
> > Hi there,

> > I can confirm that on trunk, the color choosing editor seems broken for
> > Wx.


> Okay, give it another shot please.

It works. Thank you Brice, the new Wx editor is much better than the old
one, IMHO.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

fred-2
Gael Varoquaux a écrit :

> It works. Thank you Brice, the new Wx editor is much better than the old
> one, IMHO.

I still get this issue, though:
https://mail.enthought.com/pipermail/enthought-dev/2010-January/025287.html


Cheers,

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

bryce hendrix-2
Fred, I thought of you when I was fixing the bug, so I haven't
completely forgot. I was going to look at it again today to try &
resolve some inconsistencies with the ColorEditor and RGBColorEditor.

Bryce

On 2/9/2010 3:38 AM, fred wrote:

> Gael Varoquaux a écrit :
>
>    
>> It works. Thank you Brice, the new Wx editor is much better than the old
>> one, IMHO.
>>      
> I still get this issue, though:
> https://mail.enthought.com/pipermail/enthought-dev/2010-January/025287.html
>
>
> Cheers,
>
>    

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Traits] color picker broken

fred-2
Bryce Hendrix a écrit :
> Fred, I thought of you when I was fixing the bug, so I haven't
> completely forgot. I was going to look at it again today to try &
> resolve some inconsistencies with the ColorEditor and RGBColorEditor.
Thanks Bryce!

Cheers,

--
Fred
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev