spectralpython / spectral

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

EOFError: read() didn't return enough bytes in read_band or read_bands method #61

Closed Bulva closed 7 years ago

Bulva commented 7 years ago

Hi,

maybe half year ago I wrote a short script for me which extracts bands from hyperspectral data. It is .pix file with .hdr file in ENVI format. I am sure that it worked when I finished the script. Now I have problem with read_band (or read_bands) method. When I call this method I get this error and I don't know why. I tried more images, but every image (even older images) get the same error.

I tried it on python 2.7 and 3.5. Version of spectral is 0.18 (installed via pip) and version of numpy 1.11.0. All test have passed.

I am totally desperate and I will be glad for any help. I don't know if it is a bug (when something was updated) or it is my fault.

SPy part of my code:

img = envi.open(filename + '.hdr', filename)
reader = envi.read_envi_header(filename + '.hdr')
md = {'lines': lines,
          'samples': samples,
          'bands': len(listOfBands),
          'data type': 12}
img_save = envi.create_image('new_image.hdr', md, force=True, ext="dat", interleave=interleave)
mm = img_save.open_memmap(writable=True)

for band in listOfBands:   #list of integers
        #print(img[:, :, 1])
        #print(img.read_band(1, use_memmap=False))
        mm[:, :, j] = img.read_band(band-1, use_memmap=True)
        j += 1
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__
    return self.func(*args)
  File "select3.py", line 69, in extractBands
    mm[:, :, j] = img.read_band(band-1, use_memmap=True)
  File "/usr/local/lib/python3.5/dist-packages/spectral/io/bipfile.py", line 111, in read_band
    vals.fromfile(f, sample_size)
EOFError: read() didn't return enough bytes
tboggs commented 7 years ago

The EOFError indicates that you hit the end of the file while trying to read data. Take a look at the image file size and make sure it is consistent with what is in the hdr file. The size of the data file should be

S = offset + lines samples bands *

If the file size is correct, then maybe the interleave specified in the hdr file is incorrect.

On Thu, Feb 2, 2017 at 1:31 PM, Petr Šilhák notifications@github.com wrote:

Hi,

maybe half year ago I write a short script for me which extracts bands from hyperspectral data. It is .pix file with .hdr file in ENVI format. I am sure that it worked when I finished the script. Now I have problem with read_band (or read_bands) method. When I call this method I get this error and I don't know why. I tried more images, but every image (even older images) get the same error.

I tried it on python 2.7 and 3.5. Version of spectral is 0.18 (installed via pip) and version of numpy 1.11.0

I am totally desperate and I will be glad for any help. I don't know if it is a bug (when something was updated) or it is my fault.

SPy part of my code:

img = envi.open(filename + '.hdr', filename) reader = envi.read_envi_header(filename + '.hdr') md = {'lines': lines, 'samples': samples, 'bands': len(listOfBands), 'data type': 12} img_save = envi.create_image('new_image.hdr', md, force=True, ext="dat", interleave=interleave) mm = img_save.open_memmap(writable=True)

for band in listOfBands: #list of integers print(img[:, :, 1]) print(img.read_band(1, use_memmap=False)) mm[:, :, j] = img.read_band(band-1, use_memmap=True) j += 1

Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.5/tkinter/init.py", line 1553, in call return self.func(*args) File "select3.py", line 69, in extractBands mm[:, :, j] = img.read_band(band-1, use_memmap=True) File "/usr/local/lib/python3.5/dist-packages/spectral/io/bipfile.py", line 111, in read_band vals.fromfile(f, sample_size) EOFError: read() didn't return enough bytes

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spectralpython/spectral/issues/61, or mute the thread https://github.com/notifications/unsubscribe-auth/AEvuIRRoXM94lztQWTdaiTjzY-L8eEaDks5rYiEIgaJpZM4L1eEU .

Bulva commented 7 years ago

Thank you very much. You were right. The data was edited in some way. It is working with totally different dataset.