# Path: arsf_envi_reader/numpy_bin_reader.py
# HAVE_ARSF_BINARYREADER = False
#     HAVE_ARSF_BINARYREADER = True
# class _BinaryReader(collections.Iterator):
# class BilReader(_BinaryReader):
# class BsqReader(_BinaryReader):
#     def __init__(self, input_file):
#     def __next__(self): pass
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
#     def next(self):
#     def get_hdr_dict(self):
#     def get_num_samples(self):
#     def get_num_lines(self):
#     def get_num_bands(self):
#     def have_arsf_binaryreader(self):
#     def check_interleave(self, interleave):
#     def check_size(binary_file):
#     def __del__(self):
#     def __next__(self):
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
#     def __next__(self):
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
# 
# Path: arsf_envi_reader/envi_header.py
# ENVI_TO_NUMPY_DTYPE = {'1':  numpy.uint8,
#                        '2':  numpy.int16,
#                        '3':  numpy.int32,
#                        '4':  numpy.float32,
#                        '5':  numpy.float64,
#                        '6':  numpy.complex64,
#                        '9':  numpy.complex128,
#                        '12': numpy.uint16,
#                        '13': numpy.uint32,
#                        '14': numpy.int64,
#                        '15': numpy.uint64}
# def find_hdr_file(rawfilename):
# def read_hdr_file(hdrfilename, keep_case=False):
# def write_envi_header(filename, header_dict):


import argparse
import time
import numpy
from arsf_envi_reader import numpy_bin_reader
from arsf_envi_reader import envi_header
                                   field_spectra["black"])

        # Perform linear fit
        ax, bx = numpy.polyfit([image_black, image_grey, image_white],
                               [field_black, field_grey, field_white],
                               1)
        elc_coefficients.append([ax, bx])

    elc_coefficients = numpy.array(elc_coefficients)

    return elc_coefficients

def apply_elc(input_image, output_image, image_spectra_file,
              field_spectra_file,
              scale_factor=DEFAULT_SCALE_FACTOR):
    """
    Derive coefficients for an emprical line calibration and apply
    to a BIL file.
    """

    print("Getting coefficients")
    elc_coefficients = get_elc_coefficients(image_spectra_file,
                                            field_spectra_file)

    print("Applying to image")
    # Read ENVI header
    input_header_file = envi_header.find_hdr_file(input_image)
    input_header_dict = envi_header.read_hdr_file(input_header_file)

    # Open input file

# Path: arsf_envi_reader/numpy_bin_reader.py
# HAVE_ARSF_BINARYREADER = False
#     HAVE_ARSF_BINARYREADER = True
# class _BinaryReader(collections.Iterator):
# class BilReader(_BinaryReader):
# class BsqReader(_BinaryReader):
#     def __init__(self, input_file):
#     def __next__(self): pass
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
#     def next(self):
#     def get_hdr_dict(self):
#     def get_num_samples(self):
#     def get_num_lines(self):
#     def get_num_bands(self):
#     def have_arsf_binaryreader(self):
#     def check_interleave(self, interleave):
#     def check_size(binary_file):
#     def __del__(self):
#     def __next__(self):
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
#     def __next__(self):
#     def read_line(self, line_number):
#     def read_band(self, band_number):
#     def read_pixel(self, sample_number, line_number):
# 
# Path: arsf_envi_reader/envi_header.py
# ENVI_TO_NUMPY_DTYPE = {'1':  numpy.uint8,
#                        '2':  numpy.int16,
#                        '3':  numpy.int32,
#                        '4':  numpy.float32,
#                        '5':  numpy.float64,
#                        '6':  numpy.complex64,
#                        '9':  numpy.complex128,
#                        '12': numpy.uint16,
#                        '13': numpy.uint32,
#                        '14': numpy.int64,
#                        '15': numpy.uint64}
# def find_hdr_file(rawfilename):
# def read_hdr_file(hdrfilename, keep_case=False):
# def write_envi_header(filename, header_dict):


# Path: apply_elc_to_bil.py
import argparse
import time
import numpy
from arsf_envi_reader import numpy_bin_reader
from arsf_envi_reader import envi_header

                                   field_spectra["black"])

        # Perform linear fit
        ax, bx = numpy.polyfit([image_black, image_grey, image_white],
                               [field_black, field_grey, field_white],
                               1)
        elc_coefficients.append([ax, bx])

    elc_coefficients = numpy.array(elc_coefficients)

    return elc_coefficients

def apply_elc(input_image, output_image, image_spectra_file,
              field_spectra_file,
              scale_factor=DEFAULT_SCALE_FACTOR):
    """
    Derive coefficients for an emprical line calibration and apply
    to a BIL file.
    """

    print("Getting coefficients")
    elc_coefficients = get_elc_coefficients(image_spectra_file,
                                            field_spectra_file)

    print("Applying to image")
    # Read ENVI header
    input_header_file = envi_header.find_hdr_file(input_image)
    input_header_dict = envi_header.read_hdr_file(input_header_file)

    # Open input file

    in_data = numpy_bin_reader.BilReader(input_image)