Converting hyperspectral .HDR files into raster arrays in Python to create a mirror image

24 Views Asked by At

I am trying to parse through my hyperspectral bands, band by band, to create raster files of each of my bandwidth slices. However, I keep getting the error, "EOFError: read() didn't return enough bytes" whenever I use the spectral command .read_band(). Overall, I am trying to create a mirror image of my .HDR files, and I figured that flipping the raster matrix would be the most direct way.

Thanks!

I tried the following code:

import spectral.io.envi as envi
import os 
import numpy as np
import matplotlib.pyplot as plt
import rasterio
from rasterio.transform import Affine

os.environ['SPECTRAL_DATA']='C:/Users/Desktop/HyperspectralData'
import spectral as sp
hdr_file_path = 'C:/Users/Desktop/HyperspectralData'
hdr_data = envi.open(hdr_file_path, image="raw_rd_rf.hdr")
wvl = hdr_data.bands.centers
rows, cols, bands = hdr_data.nrows, hdr_data.ncols, hdr_data.nbands
meta = hdr_data.metadata

for z in range(bands):
   band_img = hdr_data.read_band(z)
  

I expected to get a raster array, where every element codes for the pixels in my bands.

0

There are 0 best solutions below