isofit.core.common

Attributes

eps

Cache

Classes

VectorInterpolator

Linear look up table interpolator. Support linear interpolation through radial space by expanding the look

Track

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

Functions

load_wavelen(wavelength_file)

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

emissive_radiance(emissivity, T, wl, numpy.array)

Calcluate the radiance of a surface due to emission.

svd_inv(C[, hashtable, max_hash_size])

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

svd_inv_sqrt(C, hashtable, max_hash_size, numpy.array)

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

expand_path(→ str)

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

recursive_replace(→ None)

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

get_absorption(wl, absfile, numpy.array)

Calculate water and ice absorption coefficients using indices of

recursive_reencode(j[, shell_replace])

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

json_load_ascii(→ dict)

Load a hierarchical structure, convert all unicode to ASCII and

expand_all_paths(to_expand, absdir)

Expand any dictionary entry containing the string 'file' into

find_header(→ str)

Safely return the header associated with an image file.

calculate_resample_matrix(→ numpy.array)

Calculate the resampling matrix for a given set of wavelengths and FWHM.

resample_spectrum(→ numpy.array)

Resample a spectrum to a new wavelength / FWHM.

load_spectrum(spectrum_file, numpy.array)

Load a single spectrum from a text file with initial columns giving

spectral_response_function(response_range, mu, sigma)

Calculate the spectral response function.

combos(→ numpy.array)

Return all combinations of indices in a list of index sublists.

conditional_gaussian(mu, C, window, remain, x, numpy.array)

Define the conditional Gaussian distribution for convenience.

envi_header(inputpath)

Convert a envi binary/header path to a header, handling extensions

ray_start(num_cores[, num_cpus, memory_b])

compare(a, b[, threshold, not_same])

Compares strings in a to strings in b

Module Contents

eps = 1e-05[source]
Cache[source]
class VectorInterpolator(grid_input: List[List[float]], data_input: numpy.array, version='mlg')[source]

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 of lists of floats, indicating the gridpoint elements in each grid dimension

  • data_input – 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)

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

single_point_data = None[source]
n[source]
_interpolate(points)[source]

Supports style ‘rg’

_lookup(i, point)[source]

Calculates the slicing for the cube in _multilinear_grid

_multilinear_grid(points)[source]

Cached version of Jouni’s implementation

Parameters:

points – The point being interpolated. If at the limit, the extremal value in the grid is returned.

Returns:

np.ndarray

Return type:

cube

__call__(*args, **kwargs)[source]

Passes args to the appropriate interpolation method defined by the version at object init.

load_wavelen(wavelength_file: str)[source]

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

Parameters:

wavelength_file – file to read wavelengths from

Returns:

wavelengths, full-width-half-max

Return type:

(np.array, np.array)

emissive_radiance(emissivity: numpy.array, T: numpy.array, wl: numpy.array)[source]

Calcluate the radiance of a surface due to emission.

Parameters:
  • emissivity – surface emissivity.

  • T – surface temperature [K]

  • wl – 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: numpy.array, hashtable: collections.OrderedDict = None, max_hash_size: int = None)[source]

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

Parameters:
  • C – matrix to invert

  • hashtable – if used, the hashtable to store/retrieve results in/from

  • max_hash_size – maximum size of hashtable

Returns:

inverse of C

Return type:

np.array

svd_inv_sqrt(C: numpy.array, hashtable: collections.OrderedDict = None, max_hash_size: int = None)[source]

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

Parameters:
  • C – matrix to invert

  • hashtable – if used, the hashtable to store/retrieve results in/from

  • max_hash_size – 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: str, subpath: str) str[source]

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

Parameters:
  • directory – absolute location

  • subpath – path to expand

Returns:

expanded path

Return type:

str

recursive_replace(obj, key, val) None[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

get_absorption(wl: numpy.array, absfile: str)[source]

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

Parameters:
  • wl – wavelengths to interpolate to

  • absfile – file containing indices of refraction. Wavelength unts are in nm.

Returns:

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

Return type:

np.array

recursive_reencode(j, shell_replace: bool = True)[source]

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

Parameters:
  • j – object to reencode

  • shell_replace – boolean helper for recursive calls

Returns:

expanded, reencoded object

Return type:

Object

json_load_ascii(filename: str, shell_replace: bool = True) dict[source]

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

Parameters:
  • filename – json file to load from

  • shell_replace – boolean

Returns:

encoded dictionary

Return type:

dict

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

an absolute path, if needed.

Parameters:
  • to_expand – dictionary to expand

  • absdir – path to expand with (absolute directory)

Returns:

dictionary with expanded paths

Return type:

dict

find_header(imgfile: str) str[source]

Safely return the header associated with an image file.

Parameters:

imgfile – file name of base image

Returns:

header filename if one exists

Return type:

str

calculate_resample_matrix(wl: numpy.array, wl2: numpy.array, fwhm2: numpy.array, srf_file: str = None) numpy.array[source]

Calculate the resampling matrix for a given set of wavelengths and FWHM. Once calculated, resmpling is just the dot product of this matrix with the vector to be resampled.

Parameters:
  • wl – sample starting wavelengths

  • wl2 – wavelengths to resample to

  • fwhm2 – full-width-half-max at resample resolution

  • srf_file – SRF for the sensor if not assuming Gaussian

Returns:

transformation matrix (H)

Return type:

np.array

resample_spectrum(x: numpy.array, wl: numpy.array, wl2: numpy.array, fwhm2: numpy.array, fill: bool = False, srf_file: str = None, H: numpy.array = None) numpy.array[source]
Resample a spectrum to a new wavelength / FWHM.

Assumes Gaussian SRFs.

Parameters:
  • x – radiance vector

  • wl – sample starting wavelengths

  • wl2 – wavelengths to resample to

  • fwhm2 – full-width-half-max at resample resolution

  • fill – boolean indicating whether to fill in extrapolated regions

  • ### (### sc Adding for non-Gaussian SRF)

  • srf_file – SRF for the sensor if not assuming Gaussian

  • H – pre-computed transformation matrix, to enable caching

Returns:

interpolated radiance vector

Return type:

np.array

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

wavelength and magnitude, respectively.

Parameters:

spectrum_file – 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: numpy.array, mu: float, sigma: float)[source]

Calculate the spectral response function.

Parameters:
  • response_range – signal range to calculate over

  • mu – mean signal value

  • sigma – signal variation

Returns:

spectral response function

Return type:

np.array

combos(inds: List[List[float]]) numpy.array[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 of lists of values to expand

Returns:

meshgrid array of combinations

Return type:

np.array

conditional_gaussian(mu: numpy.array, C: numpy.array, window: numpy.array, remain: numpy.array, x: numpy.array)[source]

Define the conditional Gaussian distribution for convenience.

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

Parameters:
  • mu – mean values

  • C – matrix for conditioning

  • window – contains all indices not in remain

  • remain – contains indices of the observed part x1

  • x – 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 :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=print, reverse=False, message='complete')[source]

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

Borrowed from mlky

step = 5[source]
total[source]
print[source]
start[source]
percent = 5[source]
reverse = False[source]
message = 'complete'[source]
__call__(count)[source]
Parameters:

count (int, iterable) – The current count of items finished. If iterable, will call len() on it

Returns:

True if a percentage step was just crossed, False otherwise

Return type:

bool

compare(a, b, threshold=0.8, not_same=True)[source]

Compares strings in a to strings in b

Parameters:
  • a (str | list[str]) – A string or list of strings to compare with b

  • a – A string or list of strings to compare with a

  • threshold (float, default=0.8) – Ratio threshold to meet to be considered matching. Must be between 0 and 1.

  • not_same (bool, default=True) – Only include matches in which the two strings are not the same

Returns:

matching – For each string in a, return a list of strings in b that meet the matching threshold

Return type:

dict