isofit.utils.template_construction
- class Pathnames(args)[source]
Bases:
object
Class to determine and hold the large number of relative and absolute paths that are needed for isofit and MODTRAN configuration files.
- Parameters:
args – an argparse Namespace object with all inputs
- class LUTConfig(lut_config_file=None, emulator=False)[source]
Bases:
object
- A look up table class, containing default grid options. All properties may be overridden with the optional
input configuration file path
- get_angular_grid(angle_data_input, spacing, min_spacing, units='d')[source]
Find either angular data ‘center points’ (num_points = 1), or a lut set that spans angle variation in a systematic fashion.
- Parameters:
angle_data_input (
array
) – set of angle data to use to find center pointsspacing (
float
) – the desired angular spacing between points, or mean if -1min_spacing (
float
) – the minimum angular spacing between points allowed (if less, no grid)units (
str
) – specifies if data are in degrees (default) or radians
- Returns:
angular data center point or lut set spanning space
- class SerialEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Bases:
JSONEncoder
Encoder for json to help ensure json objects can be passed to the workflow manager.
- default(obj)[source]
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- get_angular_grid(angle_data_input, spacing, min_spacing, units='d')[source]
Find either angular data “center points” (num_points = 1), or a lut set that spans angle variation in a systematic fashion.
- Parameters:
angle_data_input (
array
) – set of angle data to use to find center pointsspacing (
float
) – the desired angular spacing between points, or mean if -1min_spacing (
float
) – the minimum angular spacing between points allowed (if less, no grid)units (
str
) – specifies if data are in degrees (default) or radians
- Returns:
angular data center point or lut set spanning space
- build_surface_config(macro_config, flight_id, output_path, wvl_file)[source]
Write a surface config file, using the specified pathnames and all given info.
- build_presolve_config(paths, h2o_lut_grid, n_cores=-1, use_emp_line=False, surface_category='multicomponent_surface', emulator_base=None, uncorrelated_radiometric_uncertainty=0.0, segmentation_size=400, debug=False, inversion_windows=[[350.0, 1360.0], [1410, 1800.0], [1970.0, 2500.0]], prebuilt_lut_path=None)[source]
Write an isofit config file for a presolve, with limited info.
- Parameters:
paths (
Pathnames
) – object containing references to all relevant file locationsh2o_lut_grid (
array
) – the water vapor look up table grid isofit should use for this solven_cores (
int
) – number of cores to use in processinguse_emp_line (
bool
) – flag whether or not to set up for the empirical line estimationsurface_category – type of surface to use
emulator_base (
Optional
[str
]) – the basename of the emulator, if useduncorrelated_radiometric_uncertainty (
float
) – uncorrelated radiometric uncertainty parameter for isofitsegmentation_size (
int
) – image segmentation size if empirical line is useddebug (
bool
) – flag to enable debug_mode in the config.implementationlut_path – lut path to use; if none, presolve config will create a new file
- Return type:
- build_main_config(paths, lut_params, h2o_lut_grid=None, elevation_lut_grid=None, to_sensor_zenith_lut_grid=None, to_sun_zenith_lut_grid=None, relative_azimuth_lut_grid=None, mean_latitude=None, mean_longitude=None, dt=None, use_emp_line=True, n_cores=-1, surface_category='multicomponent_surface', emulator_base=None, uncorrelated_radiometric_uncertainty=0.0, multiple_restarts=False, segmentation_size=400, pressure_elevation=False, debug=False, inversion_windows=[[350.0, 1360.0], [1410, 1800.0], [1970.0, 2500.0]], prebuilt_lut_path=None)[source]
Write an isofit config file for the main solve, using the specified pathnames and all given info
- Parameters:
paths (
Pathnames
) – object containing references to all relevant file locationslut_params (
LUTConfig
) – configuration parameters for the lut gridh2o_lut_grid (
Optional
[array
]) – the water vapor look up table grid isofit should use for this solveelevation_lut_grid (
Optional
[array
]) – the ground elevation look up table grid isofit should use for this solveto_sensor_zenith_lut_grid (
Optional
[array
]) – the to-sensor zenith angle look up table grid isofit should use for this solveto_sun_zenith_lut_grid (
Optional
[array
]) – the to-sun zenith angle look up table grid isofit should use for this solverelative_azimuth_lut_grid (
Optional
[array
]) – the relative to-sun azimuth angle look up table grid isofit should use for this solvemean_latitude (
Optional
[float
]) – the latitude isofit should use for this solvemean_longitude (
Optional
[float
]) – the longitude isofit should use for this solvedt (
Optional
[datetime
]) – the datetime object corresponding to this flightline to use for this solveuse_emp_line (
bool
) – flag whether or not to set up for the empirical line estimationn_cores (
int
) – the number of cores to use during processingsurface_category – type of surface to use
emulator_base (
Optional
[str
]) – the basename of the emulator, if useduncorrelated_radiometric_uncertainty (
float
) – uncorrelated radiometric uncertainty parameter for isofitmultiple_restarts (
bool
) – if true, use multiple restartssegmentation_size – image segmentation size if empirical line is used
pressure_elevation (
bool
) – if true, retrieve pressure elevationdebug (
bool
) – if true, run ISOFIT in debug mode
- Return type:
- get_lut_subset(vals)[source]
Populate lut_names for the appropriate style of subsetting
- Parameters:
vals – the values to use for subsetting
- write_modtran_template(atmosphere_type, fid, altitude_km, dayofyear, to_sun_zenith, to_sensor_azimuth, to_sensor_zenith, relative_azimuth, gmtime, elevation_km, output_file, ihaze_type='AER_RURAL')[source]
Write a MODTRAN template file for use by isofit look up tables
- Parameters:
atmosphere_type (
str
) – label for the type of atmospheric profile to use in modtranfid (
str
) – flight line id (name)altitude_km (
float
) – altitude of the sensor in kmdayofyear (
int
) – the current day of the given yearto_sun_zenith (
float
) – final altitude solar zenith angle (0→180°)to_sensor_azimuth (
float
) – azimuth view angle to the sensor, in degrees (AVIRIS convention)to_sensor_zenith (
float
) – sensor/observer zenith angle, in degrees (MODTRAN convention: 180 - AVIRIS convention)relative_azimuth (
float
) – final altitude relative solar azimuth (0→360°)gmtime (
float
) – greenwich mean timeelevation_km (
float
) – elevation of the land surface in kmoutput_file (
str
) – location to write the modtran template file toihaze_type (
str
) – type of extinction and default meteorological range for the boundary-layer aerosol model
- load_climatology(config_path, latitude, longitude, acquisition_datetime, isofit_path, lut_params)[source]
Load climatology data, based on location and configuration
- Parameters:
config_path (
str
) – path to the base configuration directory for isofitlatitude (
float
) – latitude to set for the segment (mean of acquisition suggested)longitude (
float
) – latitude to set for the segment (mean of acquisition suggested)acquisition_datetime (
datetime
) – datetime to use for the segment( mean of acquisition suggested)isofit_path (
str
) – base path to isofit installation (needed for data path references)lut_params (
LUTConfig
) – parameters to use to define lut grid
- :Returns
- tuple containing:
aerosol_state_vector - A dictionary that defines the aerosol state vectors for isofit aerosol_lut_grid - A dictionary of the aerosol lookup table (lut) grid to be explored aerosol_model_path - A path to the location of the aerosol model to use with MODTRAN.
- calc_modtran_max_water(paths)[source]
- MODTRAN may put a ceiling on “legal” H2O concentrations. This function calculates that ceiling. The intended
use is to make sure the LUT does not contain useless gridpoints above it.
- copy_file_subset(matching_indices, pathnames)[source]
Copy over subsets of given files to new locations
- Parameters:
matching_indices (np.array) – indices to select from (y dimension) from source dataset
pathnames (List) – list of tuples (input_filename, output_filename) to read/write to/from
- get_metadata_from_obs(obs_file, lut_params, trim_lines=5, max_flight_duration_h=8, nodata_value=-9999)[source]
Get metadata needed for complete runs from the observation file (bands: path length, to-sensor azimuth, to-sensor zenith, to-sun azimuth, to-sun zenith, phase, slope, aspect, cosine i, UTC time).
- Parameters:
obs_file (
str
) – file name to pull data fromlut_params (
LUTConfig
) – parameters to use to define lut gridtrim_lines (
int
) – number of lines to ignore at beginning and end of file (good if lines contain values that are erroneous but not nodatamax_flight_duration_h (
int
) – maximum length of the current acquisition, used to check if we’ve lapped a UTC daynodata_value (
float
) – value to ignore from location file
- Returns:
- tuple containing:
h_m_s - list of the mean-time hour, minute, and second within the line increment_day - indicator of whether the UTC day has been changed since the beginning of the line time mean_path_km - mean distance between sensor and ground in km for good data mean_to_sensor_azimuth - mean to-sensor azimuth for good data mean_to_sensor_zenith - mean to-sensor zenith for good data mean_to_sun_zenith - mean to-sun zenith for good data mean_relative_azimuth - mean relative to-sun azimuth for good data valid - boolean array indicating which pixels were NOT nodata to_sensor_zenith_lut_grid - the to-sensor zenith look up table grid for good data to_sun_zenith_lut_grid - the to-sun zenith look up table grid for good data relative_azimuth_lut_grid - the relative to-sun azimuth look up table grid for good data
- Return type:
- get_metadata_from_loc(loc_file, lut_params, trim_lines=5, nodata_value=-9999, pressure_elevation=False)[source]
Get metadata needed for complete runs from the location file (bands long, lat, elev).
- Parameters:
loc_file (
str
) – file name to pull data fromlut_params (
LUTConfig
) – parameters to use to define lut gridtrim_lines (
int
) – number of lines to ignore at beginning and end of file (good if lines contain values that are erroneous but not nodatanodata_value (
float
) – value to ignore from location filepressure_elevation (
bool
) – retrieve pressure elevation (requires expanded ranges)
- Returns:
- tuple containing:
mean_latitude - mean latitude of good values from the location file mean_longitude - mean latitude of good values from the location file mean_elevation_km - mean ground estimate of good values from the location file elevation_lut_grid - the elevation look up table, based on globals and values from location file
- Return type: