spectralpython / spectral

Python module for hyperspectral image processing
MIT License
571 stars 139 forks source link

'BipFile' object does not support item assignment #70

Closed prkyprky closed 6 years ago

prkyprky commented 6 years ago

Hi everyone,

Could you please help me? I wanna open hyperspectral image as ENVI file (.hdr + .dat) and rewrite some bands. after that save file in same format. Most of the problems I solved, but now. I have problem with this "TypeError: 'BipFile' object does not support item assignment" I've got this response when I wanna use rewriting of the band or if I wanna change the file. Do you know some solution or some advice which help me, please?

Thank you so much. ;-)

#open file 
src = envi.open("C:\soubory_pix\SASI_1.pix.hdr", "C:\soubory_pix\SASI_1.pix")
src_band = src
#rewrite band
src_band[:, 0:319, 96] = src[:, 0:319, 96] * koef_men
#Result 
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: 'BipFile' object does not support item assignment
tboggs commented 6 years ago

There are two ways you can go about modifying a file:

  1. Use the load method of the BiPFile object to load the image data into and ndarray, edit the array, then call envi.save_image.
  2. Use the open_memmap method (pass writable=True) to return a writable memmap, which acts just like a numpy array and will write your edits to disk.