I am trying to create a GUI interface that could do what Spy does through command line.Wx Python even handler works fine.But while loading the the HSi images takes infinite amount of time…with the message "Initializing graphic handlers"
Please help.
Regards
import wx
import os
from spectral import *
from spectral.graphics.hypercube import hypercube
import matplotlib
import OpenGL
import PIL
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close BBvw ?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
if result == wx.ID_OK:
self.Destroy()
app = wx.App(redirect=True)
top = Frame("BBvw")
top.Show()
app.MainLoop()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
SPy starts wx in a separate thread so that the python command line will still be available while displaying graphical windows. Starting the separate wx thread takes some time to complete so you may be experiencing a race condition. You can get around this by explicitly initializing the wx thread and adding a small delay to allow it to complete.
I replaced the line
fromspectralimport*
in your code with the following and it appeared to function properly:
It works.
I missed the trick ,
I was using initGraphics() method.(also mentioned in documentation)
Still, when i double click the opened image plot refuses to display .
Thnks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It works for me. Using the code you emailed, I made the changes I noted above, uncommented the lines in the OnButtonClick on Onview methods, and the image appeared as expected when I opened the 92AV3C.lan file. When I double-clicked on the image, the pixel spectrum was displayed in a matplotlib window.
If you haven't already done so perhaps try calling the same sequence of SPy calls from the python interpreter to see if you get any errors.
-thomas
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is "the IDLE"? The IDLE python IDE? If so, please check that you can open an image with SPy from a python terminal (console or xterm) and double-click to open a spectrum plot. If that doesn't work, then the problem is something related to your matplotlib installation (perhaps a problem with the backend installed).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
import matplotlib
import numpy
print matplotlib
data = numpy.loadtxt('C:\Users\zero\Desktop\example.fiat')
ra = data
dec = data
mag = data
color (scatter(ra,dec,c=mag,cmap=cm.hsv))
Error
Traceback (most recent call last):
File "C:/Users/zero/Desktop/New folder/mat.py", line 1, in <module>
import matplotlib
File "C:/Users/zero/Desktop/New folder\matplotlib.py", line 2, in <module>
import matplotlib.pyplot as plt
ImportError: No module named pyplot
I tried the above code.
Also , matplotlib seems to be installed.
print matplotlib
<module 'matplotlib' from 'C:\Python27\lib\site-packages\matplotlib\__init__.pyc'>
I will reinstall matplotlib.
Should I install pylab?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It looks like you have a problem with your matplotlib installation since pyplot should be included as a submodule. I suggest starting with a web search for "No module named pyplot". If your matplotlib is installed properly, you should be able to run any of the basic examples in the matplotlib tutorial (http://matplotlib.sourceforge.net/users/pyplot_tutorial.html).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
/Referring to code in post 1/
Once the image is opened I close the image window using the X mark .
I noticed that even though I do this,The image is still loaded in memory.
How to get around this?
After I use the above code for multiple times my entire memory is full of pythonw processes
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not able to reproduce that. I've tried opening the file multiple times, opening plots and hypercubes, then closing them. Memory usage always drops down to about 80 MB. I also tried with a 134 MB image and opened it (plus plots and hypercube) about a dozen times without exiting the app. The memory jumped up to about 400 MB with everything open but always went back down to about 80 MB after they were closed. There are only 4 threads running after I close the image windows (no additional pythonw processes), even after opening the file numerous times.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for checking with my problem.I have no clue why this is happening with my system.
I will try to thread the GUI.Or use PIL to display JPGs.
For the audio component I am using scipy over scikits.audiolabs.For 64 bit windows running 32 bit modules and python and finding the correct matches between them is quite demanding. easy_install runs into errors.
Could you suggest a way to save a child window(image window) from a button on the main panel?
When could I expect the spectral-cluster view…I am excited about that inclusion into Spec Py.
I am grateful for your kind support.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There must be a simple way to grab a wx frame's image buffer to save the data but I don't know off-hand how. I suggest searching the web for that. If you want to save a SPy raster image, there is a save_image function to do that. If you just want to get the pixel data to be displayed from SPy without using SPy to do the rendering, then you can use the get_image_display_data function after importing it as follows:
Sir,
I installed the MKL, numpy,scipy dependencies and then
I have reinstalled matplotlib, from Christopher Gohlke website.
The plot function refuses to run,I get to see a blank screen,
The hypercube fuction fails to exceute and indicates a problem in the self.read_band method in line 238 ,239
Please help.
this code is working.
import numpy
import pylab
t = numpy.arange(0.0, 1.0+0.01, 0.01)
s = numpy.cos(2*2*numpy.pi*t)
pylab.plot(t, s)
pylab.xlabel('time (s)')
pylab.ylabel('voltage (mV)')
pylab.title('About as simple as it gets, folks')
pylab.grid(True)
pylab.savefig('simple_plot')
pylab.show()
I have improved code , but It is more or less like the one in post 1
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You haven't given enough info for me to help you. I would need to see an actual error message (there are read_band functions in numerous files). Before doing anything with your wx app, determine whether the various SPy plotting functions work from the python command line (as in the User Guide); otherwise, it will be difficult to determine if the problem is with SPy, one of its dependencies, or your app.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding calling hypercube , I would call init_graphics first, as described in my initial reply. Regarding the image not displaying correctly, I don't know why you are having that problem. You could again try calling init_graphics first but I would be surprised if that was the problem. I also recommend selecting the RGB bands to display for that image:
view(I, [29, 19, 9])
If that doesn't work, I would try reading one of the bands and seeing if it will display with matplotlib (using its imshow function).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
called init_graphics as you mentioned but I get the same traceback.
Traceback (most recent call last):
File "C:/Users/zero/Desktop/t1.py", line 5, in <module>
hypercube(I, bands=)
File "C:\Python27\lib\site-packages\spectral\graphics\hypercube.py", line 457, in hypercube
from spectral.graphics.spywxpython import viewer
ImportError: cannot import name viewer
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are typing these commands interactively at the python command prompt, then the output you are showing doesn't make sense to me. Please start your python interpreter and type the following commands (one at a time) to see if you get the same output:
I am trying to create a GUI interface that could do what Spy does through command line.Wx Python even handler works fine.But while loading the the HSi images takes infinite amount of time…with the message "Initializing graphic handlers"
Please help.
Regards
import wx
import os
from spectral import *
from spectral.graphics.hypercube import hypercube
import matplotlib
import OpenGL
import PIL
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(1000,70),style=wx.MINIMIZE_BOX|wx.CLOSE_BOX|wx.RESIZE_BORDER|wx.SYSTEM_MENU|wx.CAPTION|wx.CLIP_CHILDREN)
self.Bind(wx.EVT_CLOSE, self.OnClose)
panel=wx.Panel(self,-1)
self.button=wx.Button(panel,label="Open",pos=(0,0),size=(50,30))
self.button1=wx.Button(panel,label="Save",pos=(51,0),size=(50,30))
self.button2=wx.Button(panel,label="ROI",pos=(102,0),size=(50,30))
self.button3=wx.Button(panel,label="Tone",pos=(153,0),size=(50,30))
self.slider=wx.Slider(panel,pos=(204,0))
self.button4=wx.Button(panel,label="Header",pos=(305,0),size=(50,30))
self.button5=wx.Button(panel,label="Cube",pos=(356,0),size=(50,30))
self.SetBackgroundColour((11, 11, 11))
self.Bind(wx.EVT_BUTTON, self.OnCubeClick,self.button5)
self.Bind(wx.EVT_BUTTON, self.OnHeadClick,self.button4)
self.Bind(wx.EVT_BUTTON, self.OnSaveClick,self.button1)
self.Bind(wx.EVT_BUTTON, self.OnButtonClick,self.button)
self.loc=wx.TextCtrl(panel,pos=(700,0), size=(300,-1))
def OnButtonClick(self,event):
wild="HSi Files|*.lan*|All Files|*.*"
dlg=wx.FileDialog(self,message="Choose a File",wildcard=wild,style=wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.loc.SetValue(dlg.GetPath())
dlg.Destroy()
#self.Onview()
def Onview(self):
filepath=self.loc.GetValue()
img=image(filepath)
view(img)
def OnHeadClick(self,event):
fileo=self.loc.GetValue()
img=image(fileo)
img.__class__
print img
def OnCubeClick(self,event):
fileo=self.loc.GetValue()
img= image(fileo).load()
(m, c) = cluster(img, 20)
view_indexed(m)
def OnSaveClick(self,event):
wild="HSi Files|*.lan*|All Files|*.*"
dlg=wx.FileDialog(self,message="Save AS",wildcard=wild,style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
path=dlg.GetPath()
self.Save(path)
self.file=path
dlg.Destroy()
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close BBvw ?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
if result == wx.ID_OK:
self.Destroy()
app = wx.App(redirect=True)
top = Frame("BBvw")
top.Show()
app.MainLoop()
SPy starts wx in a separate thread so that the python command line will still be available while displaying graphical windows. Starting the separate wx thread takes some time to complete so you may be experiencing a race condition. You can get around this by explicitly initializing the wx thread and adding a small delay to allow it to complete.
I replaced the line
in your code with the following and it appeared to function properly:
Also, since SPy depends on OpenGL, matplotlib, and PIL, you may want to import those prior to spectral. That may make the time delay unnecessary.
-thomas
It works.
I missed the trick ,
I was using initGraphics() method.(also mentioned in documentation)
Still, when i double click the opened image plot refuses to display .
Thnks
It works for me. Using the code you emailed, I made the changes I noted above, uncommented the lines in the OnButtonClick on Onview methods, and the image appeared as expected when I opened the 92AV3C.lan file. When I double-clicked on the image, the pixel spectrum was displayed in a matplotlib window.
If you haven't already done so perhaps try calling the same sequence of SPy calls from the python interpreter to see if you get any errors.
-thomas
I get a blank window when I double click the image when using the IDLE.
Windows7 64bit,64 bit hardware, 32bit python and everything else.
What is "the IDLE"? The IDLE python IDE? If so, please check that you can open an image with SPy from a python terminal (console or xterm) and double-click to open a spectrum plot. If that doesn't work, then the problem is something related to your matplotlib installation (perhaps a problem with the backend installed).
I guess you are right
import matplotlib
import numpy
print matplotlib
data = numpy.loadtxt('C:\Users\zero\Desktop\example.fiat')
ra = data
dec = data
mag = data
color (scatter(ra,dec,c=mag,cmap=cm.hsv))
Error
Traceback (most recent call last):
File "C:/Users/zero/Desktop/New folder/mat.py", line 1, in <module>
import matplotlib
File "C:/Users/zero/Desktop/New folder\matplotlib.py", line 2, in <module>
import matplotlib.pyplot as plt
ImportError: No module named pyplot
I tried the above code.
Also , matplotlib seems to be installed.
print matplotlib
<module 'matplotlib' from 'C:\Python27\lib\site-packages\matplotlib\__init__.pyc'>
I will reinstall matplotlib.
Should I install pylab?
It looks like you have a problem with your matplotlib installation since pyplot should be included as a submodule. I suggest starting with a web search for "No module named pyplot". If your matplotlib is installed properly, you should be able to run any of the basic examples in the matplotlib tutorial (http://matplotlib.sourceforge.net/users/pyplot_tutorial.html).
Dear thomas,
/Referring to code in post 1/
Once the image is opened I close the image window using the X mark .
I noticed that even though I do this,The image is still loaded in memory.
How to get around this?
After I use the above code for multiple times my entire memory is full of pythonw processes
I am not able to reproduce that. I've tried opening the file multiple times, opening plots and hypercubes, then closing them. Memory usage always drops down to about 80 MB. I also tried with a 134 MB image and opened it (plus plots and hypercube) about a dozen times without exiting the app. The memory jumped up to about 400 MB with everything open but always went back down to about 80 MB after they were closed. There are only 4 threads running after I close the image windows (no additional pythonw processes), even after opening the file numerous times.
Sir,
Thanks for checking with my problem.I have no clue why this is happening with my system.
I will try to thread the GUI.Or use PIL to display JPGs.
For the audio component I am using scipy over scikits.audiolabs.For 64 bit windows running 32 bit modules and python and finding the correct matches between them is quite demanding. easy_install runs into errors.
Could you suggest a way to save a child window(image window) from a button on the main panel?
When could I expect the spectral-cluster view…I am excited about that inclusion into Spec Py.
I am grateful for your kind support.
There must be a simple way to grab a wx frame's image buffer to save the data but I don't know off-hand how. I suggest searching the web for that. If you want to save a SPy raster image, there is a save_image function to do that. If you just want to get the pixel data to be displayed from SPy without using SPy to do the rendering, then you can use the get_image_display_data function after importing it as follows:
The ND data display will probably be available in a few weeks but I can't give a specific date.
Sir,
I installed the MKL, numpy,scipy dependencies and then
I have reinstalled matplotlib, from Christopher Gohlke website.
The plot function refuses to run,I get to see a blank screen,
The hypercube fuction fails to exceute and indicates a problem in the self.read_band method in line 238 ,239
Please help.
this code is working.
import numpy
import pylab
t = numpy.arange(0.0, 1.0+0.01, 0.01)
s = numpy.cos(2*2*numpy.pi*t)
pylab.plot(t, s)
pylab.xlabel('time (s)')
pylab.ylabel('voltage (mV)')
pylab.title('About as simple as it gets, folks')
pylab.grid(True)
pylab.savefig('simple_plot')
pylab.show()
I have improved code , but It is more or less like the one in post 1
Regards
You haven't given enough info for me to help you. I would need to see an actual error message (there are read_band functions in numerous files). Before doing anything with your wx app, determine whether the various SPy plotting functions work from the python command line (as in the User Guide); otherwise, it will be difficult to determine if the problem is with SPy, one of its dependencies, or your app.
I tried the same in command line and they dont seem to work.
Please see the attached images.
Regarding calling hypercube , I would call init_graphics first, as described in my initial reply. Regarding the image not displaying correctly, I don't know why you are having that problem. You could again try calling init_graphics first but I would be surprised if that was the problem. I also recommend selecting the RGB bands to display for that image:
If that doesn't work, I would try reading one of the bands and seeing if it will display with matplotlib (using its imshow function).
called init_graphics as you mentioned but I get the same traceback.
Traceback (most recent call last):
File "C:/Users/zero/Desktop/t1.py", line 5, in <module>
hypercube(I, bands=)
File "C:\Python27\lib\site-packages\spectral\graphics\hypercube.py", line 457, in hypercube
from spectral.graphics.spywxpython import viewer
ImportError: cannot import name viewer
If you are typing these commands interactively at the python command prompt, then the output you are showing doesn't make sense to me. Please start your python interpreter and type the following commands (one at a time) to see if you get the same output:
>>> import spectral
>>> from spectral.graphics.spywxpython import viewer
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from spectral.graphics.spywxpython import viewer
ImportError: cannot import name viewer
>>> spectral.init_graphics()
>>> from spectral.graphics.spywxpython import viewer
>>> viewer
<spectral.graphics.spywxpython.SpyWxPythonThreadStarter instance at 0x025A9AD0>
That seems OK.
If that last import returns a viewer object as shown, then displaying a hypercube should work after calling init_graphics.