Skip to content

Instantly share code, notes, and snippets.

@danclewley
Created May 1, 2018 13:22
Show Gist options
  • Save danclewley/61807ea764f80647151333fd1e31bb0c to your computer and use it in GitHub Desktop.
Save danclewley/61807ea764f80647151333fd1e31bb0c to your computer and use it in GitHub Desktop.
Example of reading a spectra from a BIL file
"""
Example of reading the spectra from a single pixel using
arsf_envi_reader (https://github.com/pmlrsg/arsf_tools)
Dan Clewley, NERC-ARF-DAN
2018-05-01
"""
from arsf_envi_reader import numpy_bin_reader
from arsf_envi_reader import envi_header
from matplotlib import pyplot as plt
# Open header file
header = envi_header.read_hdr_file("f168051b.bil.hdr")
# Read wavelengths and convert to a list of floats
wavelengths = [float(w) for w in header["wavelength"].split(",")]
# Open bil file
bil = numpy_bin_reader.BilReader("f168051b.bil")
# Read in spectra
spectra = bil.read_pixel(332, 4658)
# Plot spectra
plt.plot(wavelengths, spectra)
plt.show()
# Close bil
bil = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment