isofit.core.common

class VectorInterpolator(grid_input, data_input, lut_interp_types, version='nds-1')[source]

Bases: object

Linear look up table interpolator. Support linear interpolation through radial space by expanding the look up tables with sin and cos dimensions.

Parameters:
  • grid_input (List[List[float]]) – list of lists of floats, indicating the gridpoint elements in each grid dimension

  • data_input (array) – n dimensional array of radiative transfer engine outputs (each dimension size corresponds to the given grid_input list length, with the last dimensions equal to the number of sensor channels)

  • lut_interp_types (List[str]) – a list indicating if each dimension is in radiance (r), degrees (r), or normal (n) units.

  • version – version to use: ‘rg’ for scipy RegularGridInterpolator, ‘mlg’ for multilinear grid interpolator

load_wavelen(wavelength_file)[source]

Load a wavelength file, and convert to nanometers if needed.

Parameters:

wavelength_file (str) – file to read wavelengths from

Returns:

wavelengths, full-width-half-max

Return type:

(np.array, np.array)

emissive_radiance(emissivity, T, wl)[source]

Calcluate the radiance of a surface due to emission.

Parameters:
  • emissivity (array) – surface emissivity.

  • T (array) – surface temperature [K]

  • wl (array) – emmissivity wavelengths [nm]

Returns:

surface upwelling radiance in uW $cm^{-2} sr^{-1} nm^{-nm}$ np.array: partial derivative of radiance with respect to temperature uW $cm^{-2} sr^{-1} nm^{-1} k^{-1}$

Return type:

np.array

svd_inv(C, hashtable=None, max_hash_size=None)[source]

Matrix inversion, based on decomposition. Built to be stable, and positive.

Parameters:
  • C (array) – matrix to invert

  • hashtable (Optional[OrderedDict]) – if used, the hashtable to store/retrieve results in/from

  • max_hash_size (Optional[int]) – maximum size of hashtable

Returns:

inverse of C

Return type:

np.array

svd_inv_sqrt(C, hashtable=None, max_hash_size=None)[source]

Matrix inversion, based on decomposition. Built to be stable, and positive.

Parameters:
  • C (array) – matrix to invert

  • hashtable (Optional[OrderedDict]) – if used, the hashtable to store/retrieve results in/from

  • max_hash_size (Optional[int]) – maximum size of hashtable

Returns:

inverse of C and square root of the inverse of C

Return type:

(np.array, np.array)

expand_path(directory, subpath)[source]

Expand a path variable to an absolute path, if it is not one already.

Parameters:
  • directory (str) – absolute location

  • subpath (str) – path to expand

Returns:

expanded path

Return type:

str

recursive_replace(obj, key, val)[source]

Find and replace a vector in a nested (mutable) structure.

Parameters:
  • obj – object to replace within

  • key – key to replace

  • val – value to replace with

Return type:

None

get_absorption(wl, absfile)[source]

Calculate water and ice absorption coefficients using indices of refraction, and interpolate them to new wavelengths (user specifies nm).

Parameters:
  • wl (array) – wavelengths to interpolate to

  • absfile (str) – file containing indices of refraction

Returns:

interpolated, wavelength-specific water absorption coefficients np.array: interpolated, wavelength-specific ice absorption coefficients

Return type:

np.array

get_refractive_index(k_wi, a, b, col_wvl, col_k)[source]

Convert refractive index table entries to numpy array.

Parameters:
  • k_wi – variable

  • a – start line

  • b – end line

  • col_wvl – wavelength column in pandas table

  • col_k – k column in pandas table

Returns:

array of wavelengths k_arr: array of imaginary parts of refractive index

Return type:

wvl_arr

recursive_reencode(j, shell_replace=True)[source]

Recursively re-encode a mutable object (ascii->str).

Parameters:
  • j – object to reencode

  • shell_replace (bool) – boolean helper for recursive calls

Returns:

expanded, reencoded object

Return type:

Object

json_load_ascii(filename, shell_replace=True)[source]

Load a hierarchical structure, convert all unicode to ASCII and expand environment variables.

Parameters:
  • filename (str) – json file to load from

  • shell_replace (bool) – boolean

Returns:

encoded dictionary

Return type:

dict

expand_all_paths(to_expand, absdir)[source]
Expand any dictionary entry containing the string ‘file’ into

an absolute path, if needed.

Parameters:
  • to_expand (dict) – dictionary to expand

  • absdir (str) – path to expand with (absolute directory)

Returns:

dictionary with expanded paths

Return type:

dict

find_header(imgfile)[source]

Safely return the header associated with an image file.

Parameters:

imgfile (str) – file name of base image

Returns:

header filename if one exists

Return type:

str

resample_spectrum(x, wl, wl2, fwhm2, fill=False)[source]
Resample a spectrum to a new wavelength / FWHM.

Assumes Gaussian SRFs.

Parameters:
  • x (array) – radiance vector

  • wl (array) – sample starting wavelengths

  • wl2 (array) – wavelengths to resample to

  • fwhm2 (array) – full-width-half-max at resample resolution

  • fill (bool) – boolean indicating whether to fill in extrapolated regions

Returns:

interpolated radiance vector

Return type:

np.array

load_spectrum(spectrum_file)[source]
Load a single spectrum from a text file with initial columns giving

wavelength and magnitude, respectively.

Parameters:

spectrum_file (str) – file to load spectrum from

Returns:

spectrum values np.array: wavelengths, if available in the file

Return type:

np.array

spectral_response_function(response_range, mu, sigma)[source]

Calculate the spectral response function.

Parameters:
  • response_range (array) – signal range to calculate over

  • mu (float) – mean signal value

  • sigma (float) – signal variation

Returns:

spectral response function

Return type:

np.array

combos(inds)[source]

Return all combinations of indices in a list of index sublists. For example, the call:

combos([[1, 2], [3, 4, 5]])
...[[1, 3], [2, 3], [1, 4], [2, 4], [1, 5], [2, 5]]

This is used for interpolation in the high-dimensional LUT.

Parameters:

inds (List[List[float]]) – list of lists of values to expand

Returns:

meshgrid array of combinations

Return type:

np.array

conditional_gaussian(mu, C, window, remain, x)[source]

Define the conditional Gaussian distribution for convenience.

len(window)+len(remain)=len(x)

Parameters:
  • mu (array) – mean values

  • C (array) – matrix for conditioning

  • window (array) – contains all indices not in remain

  • remain (array) – contains indices of the observed part x1

  • x (array) – values to condition with

Returns:

conditional mean, conditional covariance

Return type:

(np.array, np.array)

envi_header(inputpath)[source]

Convert a envi binary/header path to a header, handling extensions :type inputpath: :param inputpath: path to envi binary file

Returns:

the header file associated with the input reference.

Return type:

str

ray_start(num_cores, num_cpus=2, memory_b=-1)[source]
class Track(total, step=5, print=<built-in function print>, reverse=False, message='complete')[source]

Bases: object

Tracks and reports the percentage complete for some arbitrary sized iterable.

Borrowed from mlky