binary input and memory address passing

2006-12-12 Thread Eric Carlson
Hello,

I can open, read, and convert data to a numeric (double) array from a 
binary file using

nc = #something given
nr = #something given
f_o=open('junk.bin','rb')
x=reshape(array('d',f_o.read()),(nr,nc))

Is there a way in python that gives better performance? These commands 
take three to 4 times longer than loading the data into an array in (for 
example) octave.

Also, is there a way to pass the address of a block of memory, and then 
access the data located there (pass by reference and let the python 
program know what data type to use)?

My situation: I have two programs that can not communicate directly, but 
I can get memory addresses for any data in my programs. I currently save 
to a file, then load the data from file into my other program. Clearly 
it would be much faster if I could access the block of memory directly 
rather than making a copy.

Any suggestions greatly appreciated.

Cheers,

Eric Carlson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: binary input and memory address passing

2006-12-13 Thread Eric Carlson

Thanks Dennis and Scott for both responses. Since Dennis has slam dunked 
my notion of sharing memory addresses (my ignorance in computing is 
pretty much unbounded), I guess I will need to continue on with sharing 
through files.

Opening up and loading the binary info into a string variable is very 
fast. The process bogs when changing the representation to float. So it 
appears that Scott's Block module might do what I need.

My original:

nc = #something given
nr = #something given
f_o=open('junk.bin','rb')
x=reshape(array('d',f_o.read()),(nr,nc))

gives me any array with nr rows and nc columns. Using Block I think I 
would use:

f_o=open('junk.bin','rb')
x = View('d', Block(f_o.read()))

Okay, so now how can I use this? Is this like an array type so that

x = reshape(x,(nr,nc))

makes sense?

Regards,
Eric
-- 
http://mail.python.org/mailman/listinfo/python-list


Issues with nonfunctioning VTK under python 2.5

2007-06-21 Thread Eric Carlson
Hello,

I have tried to install the entire stash of eggs in the svn repository 
at enthought using enthought enstaller on Windows XP,and it mostly seems 
to have been successful for my python2.5 installation. Unfortunately, I 
can not seem to load up my vtk modules. Every time I try to import vtk 
from anywhere using python2.5, I get the message

"import vtk
Traceback (most recent call last):
   File "", line 1, in 
   File 
"c:\python25\lib\site-packages\VTK-5.0.1-py2.5-win32.egg\vtk\__init__.py"
, line 29, in 
 from common import *
   File 
"c:\python25\lib\site-packages\VTK-5.0.1-py2.5-win32.egg\vtk\common.py",
line 9, in 
 from vtkCommonPython import *
ImportError: No module named vtkCommonPython"

I have checked my path, unistalled vtk, reinstalled vtk, added a vtk.pth 
file with various plausible paths, changed the name of 
vtkCommonPython.dll to vtkCommonPython.pyd (which changes the message to 
"ImportError: Module use of python24.dll conflicts with this version of 
Python"), but nothing seems to work.

I have a version of enthought sumo python 2.4 installed also which might 
cause some conflicts, but so far vtk seems to be the only package that 
has not worked correctly (scipy, numpy, matplotlib, PyOpengl, PyODE, and 
wxpython2.8 demos all work)

Any suggestions would be greatly appreciated.

Regards,
Eric Carlson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen on Windows

2008-10-20 Thread Eric Carlson

Werner F. Bruhin wrote:

I am trying to use subprocess - it basically works but.

   command =  'ping ' + '-n '+ str(count) + ' -l ' + 
str(size) + ' ' + str(node)

   print command
   p = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
   pout = p.stdout.read()

This works for me but I see the Windows command window, is there a way 
to call subprocess without a command window showing?


I am trying to replace:

fdout, fdin = popen2.popen4('ping -n '+ str(count)+ ' -l '+ str(size) +' 
'+node)


Which did not show the command window.

I did quit a bit of googling bug so far did not find an answer to my 
problem.


Appreciate any hints on how this can be accomplished.

Werner


Try:

p = subprocess.Popen(command, shell=True, tdin=subprocess.PIPE, 
stdout=subprocess.PIPE)


was working on xp and osx
--
http://mail.python.org/mailman/listinfo/python-list


Re: CAD.py

2008-11-03 Thread Eric Carlson

Hello,

I have pondered this notion of a 3d sketcher a bit myself. Before I go 
on, here is a quote from writer Neil Gaiman, author of some very good books:


"Every Published writer has had it - the people who come up to you and 
tell you that they've Got An Idea. And boy, is it a Doozy. It's such a 
Doozy that they want to Cut You In On It. The proposal is always the 
same - they'll tell you the idea (the hard bit), you write it down and 
turn it into a novel (the easy bit), the two of you split the money 
fifty-fifty"


In this spirit, let me offer the following observations/suggestions:


Mayavi, the open source data visualization system from enthought.com, 
does a very nice job of high-level wrapping of The Visualization 
Toolkit. VTK has both high-level wrappings of OpenGL for display, as 
well as many modules to import/export various 3D file formats, merging 
or clipping 3D objects, constructive solid geometry, etc. All of the 
lower-level VTK routines can be accessed through the traited VTK wrapper 
(TVTK) from enthought. Once you have a Mayavi scene, it is a simple 
matter to add anything to it, or to modify any of the objects in the scene.


Although Mayavi has evolved to be reasonably backend independent, the 
current version interacts most easily with the wxpython GUI toolkit. 
Given that they work well together, I would say that a combination of 
wxpython, Mayavi, and enthought Traits (recent stable versions and 
Python 2.5) could lead to a very interesting 3d sketching application.


If you install the wxpython demos and samples (an absolute necessity if 
you program with wxpython), you can dig through the installation 
directory and find a "samples" subdirectory, and in there you can find 
another folder called "pySketch." This app is a nice 2D sketching 
program with everything I really need for simple 2D sketches, except 
rotating objects (and I had to hack it to get a button to save an image 
and copy to clipboard) - it could probably also use buttons for various 
common drawing objects. If nothing else, this example might give an idea 
of a possible layout, and source for how to set it up.


For the 3d sketching, you would have to have some buttons for object 
creation (various polyhedra, sphere, ellipse, arbitrary explicit 
function, implicit function, constructive solid geometry surface, maybe 
a library of predefined widgets), extruding, surfaces of rotations, 
button or menu for importing/exporting an object, some buttons for 
clipping and merging objects (additive and subtractive merges), some 
buttons for object transformations (scaling, rotations, precise 
placement in a scene, parametric stretching, twisting/turning, mirroring 
objects), button for duplications, and buttons for setting object 
materials/colors/properties.


There are many examples of embedding a mayavi scene in other 
applications given in the examples directory at the mayavi/tvtk 
developer repository.


Also, I have come to appreciate very much the wxpython AUI managed 
frame, which lets you move panels, toolbars, whatever, to pretty much 
any location within your frame. This means that anyone using your 
application can customize their layout with trivial effort.


I doubt that I can get around to any of this until late next year, but I 
would be happy to assist if you want to take a shot at it...


Cheers,
Eric Carlson

--
http://mail.python.org/mailman/listinfo/python-list


Re: 3D plotting in a GUI

2009-04-07 Thread Eric Carlson

Baris Demir wrote:

Hi all,

I need to develop a GUI for some scientific data processing operations 
and this GUI should work well with a 3D plotting module, also with NumPy 
and SciPy for sure. I made a search about packages but, there are plenty 
of these modules available. What kind of a package or a package of 
packages might be the best way  for this  work. BTW I do not want to use 
MayaVi. It is too much actually.


Thanks in advance.
BD




The attached example should give you some idea of embedding mayavi (and 
then using the very high-level mlab) and vtk in wxpython apps. This 
example requires wxpython, vtk, numpy, and ETS. If you are really after 
visualization of data, you will need to spend years to get even a 
fraction of the capability of mayavi. On the other hand, rolling out a 
py2exe'd version of a program is currently a major challenge if you need 
ETS.


The mayavi.mlab module is so easy to use and embed that I would 
recommend using it to create a rapid software prototype to compare 
against whatever system you decide to go with. It is designed with a 
seamless interface to numpy/scipy, and provides high-level routines to 
modify low-level properties.


Cheers,
Eric
"""
This example show how to embedded Mayavi in a wx aui notebook, and
also shows how to embed a generic vtk window 

This is a slightly more complex example than the wx_embedding.py one, and
can be used to see how a large wx application can use different
Mayavi views.
"""

from numpy import ogrid, sin

from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import View, Item

from enthought.mayavi.sources.api import ArraySource
from enthought.mayavi.modules.api import IsoSurface

from enthought.tvtk.pyface.scene_editor import SceneEditor
from enthought.mayavi.tools.mlab_scene_model import MlabSceneModel

class MayaviView(HasTraits):

scene = Instance(MlabSceneModel, ())

view = View(Item('scene', editor=SceneEditor(), resizable=True,
show_label=False),
resizable=True)

def __init__(self):
HasTraits.__init__(self)
x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
scalars = sin(x*y*z)/(x*y*z)
src = ArraySource(scalar_data=scalars)
self.scene.engine.add_source(src)
src.add_module(IsoSurface())
#
# Wx Code
import wx
import vtk
from vtk.wx import *
from enthought.mayavi import mlab 
class MainWindow(wx.Frame):

def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Mayavi in a Wx notebook')
self.notebook = wx.aui.AuiNotebook(self, id=-1, 
style=wx.aui.AUI_NB_TAB_SPLIT | wx.aui.AUI_NB_CLOSE_ON_ALL_TABS
| wx.aui.AUI_NB_LEFT)
sizer = wx.BoxSizer()
sizer.Add(self.notebook,1, wx.EXPAND)
self.SetSizer(sizer)

self.mayavi_view = MayaviView()

self.control = self.mayavi_view.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control, caption='Display 1')
self.mayavi_view2 = MayaviView()

self.control2 = self.mayavi_view2.edit_traits(
parent=self,
kind='subpanel').control
self.notebook.AddPage(page=self.control2, caption='Display 2')
#the following clears the second panel, 
#then shows the output of test_contour3d in the same panel
mlab.clf() #clear the figure in Display 2
mlab.test_contour3d() #add some stuff there
mlab.show_pipeline() #display the mayavi pipeline viewer


#the following creates a VTK window and embeds in our notebook

self.notebook.AddPage(page=wxVTKRenderWindowInteractor.wxVTKRenderWindowInteractor(self,
 -1), caption='VTK Panel')

widget =  self.notebook.GetPage(2)   
widget.Enable(1)   
widget.AddObserver('ExitEvent', lambda o,e,f=self: f.Close())   
ren = vtk.vtkRenderer()   
widget.GetRenderWindow().AddRenderer(ren)   
cone = vtk.vtkConeSource()
cone.SetResolution(8)   
coneMapper = vtk.vtkPolyDataMapper()   
coneMapper.SetInput(cone.GetOutput())   
coneActor = vtk.vtkActor()   
coneActor.SetMapper(coneMapper)   
ren.AddActor(coneActor)   
style = vtk.vtkInteractorStyleTrackballCamera()   
widget._Iren.SetInteractorStyle(style)  

self.Show(True)

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY)
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list