ProcessEnviFile

Class and functions to process envi file.

The package spectral is used in this repository with permission by the authors (see spectralpython/spectral/issues/103).

class hprocessing.ProcessEnviFile.ProcessEnviFile(image, wavelengths: list, bbl: list, zone_list: list, positions: dict, index_of_meas: int, mask=None, grid: tuple = (1, 1), stat_mode: str = 'median', spectralon_factor: float = 0.95)[source]

Class to process ENVI files.

Parameters
  • image (spectral image) – Image file of the hyperspectral image

  • wavelengths (list of int) – List of measured wavelength bands

  • bbl (list of str/int/bool) – List of bbl values that say which wavelengths are measured in good quality (1) and which are not (0)

  • zone_list (list) – List of measurement zones in the image. That does not include the spectralon (white reference). If a zone needs to be ignored, it needs to be removed from this list.

  • positions (dict) – Dictionary with information of the positions config file

  • index_of_meas (int) – Index of dataset in positions CSV file

  • mask (numpy array, optional (default=None)) – Zero = pixel to be masked, One = good pixel

  • grid (tuple (int, int), optional (default=(1, 1))) – Size of the grid (rows, columns). If row/column zero, every pixel is one row/column.

  • stat_mode (str) – Mode for calculating the “mean spectrum”. Possible values: median, mean, max, max10 (= maximum of the top 10 pixels), std.

  • spectralon_factor (float, optional (default=0.95)) – Factor of how much solar radiation the spectralon reflects.

getCalibratedSpectra(spectra: pandas.core.frame.DataFrame, spectralon: pandas.core.frame.DataFrame)pandas.core.frame.DataFrame[source]

Get calibrated spectra.

Parameters
  • spectra (pd.DataFrame) – Not-calibrated spectra

  • spectralon (pd.DataFrame) – Spectrum of the spectralon (white reference)

Returns

Calibrated spectra

Return type

pd.DataFrame

getEdgesFromPrefix(prefix: str)[source]

Get start and end values of edges in rows and columns.

These four values describe a rectangle on the hyperspectral image.

Parameters

prefix (str) – Name of the rectangle which corresponds to the resulting edges

Returns

edges – Edges of the resulting rectangle

Return type

list of [int, int, int, int]

getMeanSpectraFromSquareGrid(edges, mode: str = 'median')[source]

Get mean spectra from squared grid area (region of interest, ROI).

Parameters
  • edges (list of 4 int) – Edges of the square (row_start, row_end, col_start, col_end)

  • mode (str) – Mode for calculating the “mean spectrum”. Possible values: median, mean, max, max10 (= maximum of the top 10 pixels), std.

Returns

df – DataFrame with all spectra as rows.

Return type

pd.DataFrame

getMeanSpectrumFromRectangle(edges: list, mode: str = 'median')pandas.core.frame.DataFrame[source]

Get mean spectrum from rectangle area (region of interest, ROI).

Parameters
  • edges (list of 4 int) – Edges of the square (row_start, row_end, col_start, col_end)

  • mode (str) – Mode for calculating the “mean spectrum”. Possible values: median, mean, max, max10 (= maximum of the top 10 pixels), std.

Returns

df_spectrum – Dataframe with the spectrum as row, wavelengths as columns

Return type

pd.DataFrame

Todo

  • implement statsmodels.robust.scale.Huber as robust mean

getMultipleSpectra()[source]

Get soil spectrum for measurements with multiple soil spectra.

In these measurements, there are multiple spectra measured: the one of the spectralon and the multiple soil spectra. The soil spectra are combined with the spectralon spectrum to get the reflectance spectra of the soil measurements.

Returns

zones_fields_df – DataFrame containing the reflectance spectra of the soil measurements

Return type

DataFrame

Todo

  • Replace pandas by numpy

getRealGridSize(edges: list)[source]

Calculate grid size.

Parameters

edges (list of 4 int) – Edges of the square (row_start, row_end, col_start, col_end)

Returns

Number of grid rows and columns

Return type

(int, int)

hprocessing.ProcessEnviFile.convertWavelength(wavelength)str[source]

Convert wavelength into string in nano meter.

Parameters

wavelength (str, int, float) – Wavelength in nano meters or micro meters

Returns

Wavelength as string

Return type

str

Raises

ValueError – If wavelegnth between 5 and 200

hprocessing.ProcessEnviFile.formatTime(time, ampm)[source]

Format time from 6:02PM to 18:02 (or 10:02PM to 22:02).

Parameters
  • time (str) – Time formated as “6:02:24” (or 10:02:24)

  • ampm (str) – Formatted as “A” or “P” for AM or PM

Returns

newtime – Time formatted as “18:02:24” (or 22:02:24)

Return type

str

hprocessing.ProcessEnviFile.getCalibratedSpectrum(soil, spectralon, spectralon_factor: float = 0.95)[source]

Calibrate hyperspectral spectrum from soil via spectralon.

Calibrate each bin of the soil spectrum on the respective bin in the spectralon (= white reference) spectrum.

Parameters
  • soil (list of float) – Spectrum of the soil.

  • spectralon (list of float) – Spectrum of the spectralon.

  • spectralon_factor (float) – Factor of how much solar radiation the spectralon reflects.

Returns

List of reflectance values for each band of the soil image.

Return type

np.array of floats

hprocessing.ProcessEnviFile.getEdgesForGrid(edges: list, grid_real)[source]

Calculate the grid geometry (edges).

Parameters
  • edges (list of 4 int) – Edges of the square (row_start, row_end, col_start, col_end)

  • grid_real ((int, int)) – Number of grid rows and columns

Returns

new_edges – New edges of the grid inside the rectangle.

Return type

list of int

hprocessing.ProcessEnviFile.getEnviFile(filepath)[source]

Read from envi file.

The envi files consist of one header file (.hdr) and one image file (.cue). The documentation for the ENVI functions can be found here: https://github.com/spectralpython/spectral/blob/master/spectral/io/envi.py The documentation for the ENVI header files can be found here: https://www.harrisgeospatial.com/docs/ENVIHeaderFiles.html

Parameters

filepath (str) – Path to header file

Returns

  • header (spectral header) – Contains description, samples, lines, bands, header offset, file type, data type, interleave, sensor type, z plot average, z plot range, default stretch, plot titles, reflectance, byte order, bbl, wavelength, wavelength units.

  • image (spectral image) – Image file of the hyperspectral image. Order of the indices: image[row, column], image[row, column, band] See here: http://www.spectralpython.net/fileio.html

hprocessing.ProcessEnviFile.getEnviHeader(filepath)[source]

Read envi header file.

Parameters

filepath (str) – Path to header file

Returns

header – Contains description, samples, lines, bands, header offset, file type, data type, interleave, sensor type, z plot average, z plot range, default stretch, plot titles, reflectance, byte order, bbl, wavelength, wavelength units.

Return type

spectral header

hprocessing.ProcessEnviFile.getGridElements(grid: tuple)list[source]

Get elements of a 2-dimensional grid.

Parameters

grid (tuple (int, int), optional (default=(1, 1))) – Size of the grid (rows, columns). If row/column zero, every pixel is one row/column.

Returns

List of grid elements

Return type

list of tuples (int, int)

hprocessing.ProcessEnviFile.readEnviHeader(header)[source]

Read out the header of the ENVI file.

The documentation of the ENVI Header Files can be found here: https://www.harrisgeospatial.com/docs/ENVIHeaderFiles.html

Parameters

header (envi header format) – Header of the ENVI file

Returns

  • date_formatted (str) – Date formatted as yyyymmdd

  • time_formatted (str) – Time formatted as hh:mm:ss

hprocessing.ProcessEnviFile.removeBadBands(spectrum, wavelengths, bbl)[source]

Remove bands that are marked as bad in bbl list.

Parameters
  • spectrum (list of int) – Spectrum as a list.

  • wavelengths (list of int) – List of measured wavelength bands

  • bbl (list of str/int/bool) – List of bbl values that say which wavelengths are measured in good quality (1) and which are not (0)

Returns

  • newwavelengths (list of int) – List of “good” wavelength bands

  • newspectrum (list of int) – Spectrum of all “good” bands as a list

hprocessing.ProcessEnviFile.validateWavelengths(wavelengths: list, bbl: list)[source]

Validate wavelengths and bbl.

Parameters
  • wavelengths (list of int) – List of measured wavelength bands

  • bbl (list of str/int/bool) – List of bbl values that say which wavelengths are measured in good quality (1) and which are not (0)

Returns

  • list of int – Validated wavelengths list

  • list of int – Validated bbl list

Raises

ValueError: – Raised if wavelengths and bbl are of a different length.