isofit.core.common
Attributes
Classes
Linear look up table interpolator. Support linear interpolation through radial space by expanding the look |
|
Tracks and reports the percentage complete for some arbitrary sized iterable. |
Functions
|
Load a wavelength file, and convert to nanometers if needed. |
|
Calcluate the radiance of a surface due to emission. |
|
Matrix inversion, based on decomposition. Built to be stable, and positive. |
|
Matrix inversion, based on decomposition. Built to be stable, and positive. |
|
Expand a path variable to an absolute path, if it is not one already. |
|
Find and replace a vector in a nested (mutable) structure. |
|
Calculate water and ice absorption coefficients using indices of |
|
Recursively re-encode a mutable object (ascii->str). |
|
Load a hierarchical structure, convert all unicode to ASCII and |
|
Expand any dictionary entry containing the string 'file' into |
|
Safely return the header associated with an image file. |
|
Calculate the resampling matrix for a given set of wavelengths and FWHM. |
|
Resample a spectrum to a new wavelength / FWHM. |
|
Load a single spectrum from a text file with initial columns giving |
|
Calculate the spectral response function. |
|
Return all combinations of indices in a list of index sublists. |
|
Define the conditional Gaussian distribution for convenience. |
|
Convert a envi binary/header path to a header, handling extensions |
|
|
|
Compares strings in a to strings in b |
Module Contents
- 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
- 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:
- 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:
- 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:
- 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:
- 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:
- 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
- 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: