Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'RasterWindow' object has no attribute 'SetClientSizeWH' #169

Open
afk-moneymaker opened this issue Aug 29, 2024 · 1 comment

Comments

@afk-moneymaker
Copy link

Hello, I have been trying to familiarize myself with the library. However, I encountered a problem.
The spectral library calls SetClientSizeWH. If the call is changed to SetClientSize, the error does not occur anymore, but others are raised. I therefore assume that the library versions I am using are incompatible with each other. But which combination works?

Code

import os

from spectral import *
import spectral.io.envi as envi

if __name__ == "__main__":
    path = os.path.dirname(__file__) + "/../../data/raw/"
    header = path + "ENVIDATA.hdr"
    data = path + "ENVIDATA.dat"
    img = envi.open(header, data)

    view_indexed(img)

Error message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\source\repos\hyperspectral-imaging\src\core\__init__.py:12
      9     data = path + "ENVIDATA.dat"
     10     img = envi.open(header, data)
---> 12     view_indexed(img)
     13     # view = imshow(img, colors=spy_colors)
     14     # gt = img.read_band(0)
     15     # view = imshow(classes=gt, colors=spy_colors)
   (...)
     20
     21 # Run with: & PROJECT/.venv/Scripts/ipython.exe PROJECT/src/core/__init__.py --pylab=WX -i

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\graphics.py:277, in view_indexed(*args, **kwargs)
    274 if 'colors' not in kwargs:
    275     kwargs['colors'] = spy_colors
--> 277 return view(*args, **kwargs)

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\graphics.py:97, in view(*args, **kwargs)
     94 else:
     95     rgb = rgb.astype(np.uint8)
---> 97 frame = RasterWindow(None, -1, rgb, **kwargs)
     98 frame.Raise()
     99 frame.Show()

File ~\source\repos\hyperspectral-imaging\.venv\Lib\site-packages\spectral\graphics\rasterwindow.py:36, in RasterWindow.__init__(self, parent, index, rgb, **kwargs)
     33 self.kwargs = kwargs
     34 wx.Frame.__init__(self, parent, index, title,
     35                   wx.DefaultPosition)
---> 36 self.SetClientSizeWH(self.bmp.GetWidth(), self.bmp.GetHeight())
     37 wx.EVT_PAINT(self, self.on_paint)
     38 wx.EVT_LEFT_DCLICK(self, self.left_double_click)

AttributeError: 'RasterWindow' object has no attribute 'SetClientSizeWH'

Technical details

  • Windows 10
  • x86_64

Dependency Versions

  • numpy: 2.1.0
  • pillow: 10.4.0
  • wxPython: 4.2.1
  • matplotlib: 3.9.2
  • ipython: 8.26.0 (Which I use as the interpreter)
  • PyOpenGL: 3.1.7
  • spectral: 0.23.1
@tboggs
Copy link
Member

tboggs commented Aug 29, 2024

Hello,

view_indexed is now deprecated (I should add a warning for that). Please use the display functions here. So in your case, you would want to do something like

import spectral as spy
gt = img.read_band(0)
spy.imshow(classes=gt, interpolation='nearest')

Note that the classes keyword is primarily intended for displaying ground truth or classification masks (not actual image data).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants