Modtran utility

Overview

This module provides MODTRAN tape7 file reading. Future development may include a class to write tape5 files, but that is a distant target at present.

See the __main__ function for examples of use.

This package was partly developed to provide additional material in support of students and readers of the book Electro-Optical System Analysis and Design: A Radiometry Perspective, Cornelius J. Willers, ISBN 9780819495693, SPIE Monograph Volume PM236, SPIE Press, 2013. http://spie.org/x648.html?product_id=2021423&origin_id=x646

Module classes

pyradi.rymodtran.fixHeaders(instr)

Modifies the column header string to be compatible with numpy column lookup.

Args:
list columns (string): column name.
Returns:
list columns (string): fixed column name.
Raises:
No exception is raised.
pyradi.rymodtran.loadtape7(filename, colspec=[])

Read the Modtran tape7 file. This function was tested with Modtran5 files.

Args:
filename (string): name of the input ASCII flatfile.
colspec ([string]): list of column names required in the output the spectral transmittance data.
Returns:
np.array: an array with the selected columns. Col[0] is the wavenumber.
Raises:
No exception is raised.

This function reads in the tape7 file from MODerate spectral resolution atmospheric TRANsmission (MODTRAN) code, that is used to model the propagation of the electromagnetic radiation through the atmosphere. tape7 is a primary file that contains all the spectral results of the MODTRAN run. The header information in the tape7 file contains portions of the tape5 information that will be deleted. The header section in tape7 is followed by a list of spectral points with corresponding transmissions. Each column has a different component of the transmission or radiance. For more detail, see the modtran documentation.

The user selects the appropriate columns by listing the column names, as listed below.

The format of the tape7 file changes for different IEMSCT values. For the most part the differences are hidden in the details. The various column headers used in the tape7 file are as follows:

IEMSCT = 0 has two column header lines. Different versions of modtran has different numbers of columns. In order to select the column, you must concatenate the two column headers with an underscore in between. All columns are available with the following column names: [‘FREQ_CM-1’, ‘COMBIN_TRANS’, ‘H2O_TRANS’, ‘UMIX_TRANS’, ‘O3_TRANS’, ‘TRACE_TRANS’, ‘N2_CONT’, ‘H2O_CONT’, ‘MOLEC_SCAT’, ‘AER+CLD_TRANS’, ‘HNO3_TRANS’, ‘AER+CLD_abTRNS’, ‘-LOG_COMBIN’, ‘CO2_TRANS’, ‘CO_TRANS’, ‘CH4_TRANS’, ‘N2O_TRANS’, ‘O2_TRANS’, ‘NH3_TRANS’, ‘NO_TRANS’, ‘NO2_TRANS’, ‘SO2_TRANS’, ‘CLOUD_TRANS’, ‘CFC11_TRANS’, ‘CFC12_TRANS’, ‘CFC13_TRANS’, ‘CFC14_TRANS’, ‘CFC22_TRANS’, ‘CFC113_TRANS’, ‘CFC114_TRANS’, ‘CFC115_TRANS’, ‘CLONO2_TRANS’, ‘HNO4_TRANS’, ‘CHCL2F_TRANS’, ‘CCL4_TRANS’, ‘N2O5_TRANS’,’H2-H2_TRANS’,’H2-HE_TRANS’,’H2-CH4_TRANS’, ‘CH4-CH4_TRANS’]

IEMSCT = 1 has single line column headers. A number of columns have headers, but with no column numeric data. In the following list the columns with header names ** are empty and hence not available: [‘FREQ’, ‘TOT_TRANS’, ‘PTH_THRML’, ‘THRML_SCT’, ‘SURF_EMIS’, SOL_SCAT, SING_SCAT, ‘GRND_RFLT’, DRCT_RFLT, ‘TOTAL_RAD’, REF_SOL, SOL@OBS, ‘DEPTH’, ‘DIR_EM’, TOA_SUN, ‘BBODY_T[K]’]. Hence, these columns do not have valid data: [‘SOL_SCAT’, ‘SING_SCAT’, ‘DRCT_RFLT’, ‘REF_SOL’, ‘SOL@OBS’, ‘TOA_SUN’]

IEMSCT = 2 has single line column headers. All the columns are available: [‘FREQ’, ‘TOT_TRANS’, ‘PTH_THRML’, ‘THRML_SCT’, ‘SURF_EMIS’, ‘SOL_SCAT’, ‘SING_SCAT’, ‘GRND_RFLT’, ‘DRCT_RFLT’, ‘TOTAL_RAD’, ‘REF_SOL’, ‘SOL@OBS’, ‘DEPTH’, ‘DIR_EM’, ‘TOA_SUN’, ‘BBODY_T[K]’]

IEMSCT = 3 has single line column headers. One of these seems to be two words, which, in this code must be concatenated with an underscore. There is also additional column (assumed to be depth in this code). The columns available are [‘FREQ’, ‘TRANS’, ‘SOL_TR’, ‘SOLAR’, ‘DEPTH’]

The tape7.scn file has missing columns, so this function does not work for tape7.scn files. If you need a tape7.scn file with all the columns populated you would have to use the regular tape7 file and convolve this to lower resolution.

UPDATE: Different versions of Modtran have different columns present in the tape7 file, also not all the columns are necessarily filled, some have headings but no data. To further complicate matters, the headings are not always separated by spaces, sometime (not often) heading text runs into each other with no separator.

It seems that the column headings are right aligned with the column data itself, so if we locate the right most position of the column data, we can locate the headings with valid data - even in cases with connected headings.

The algorithm used is as follows:

  1. step down to a data line beyond the heading lines (i.e., the data)
  2. locate the position of the last character of every discrete colummn
  3. From the last column of the previous col, find start of next col
  4. move up into the header again and isolate the header column text for each column

In sptite of all the attempts to isolate special cases, reading of tape7 files remain a challange and may fail in newer versions of Modtran, until fixed.

pyradi.rymodtran.fixHeadersList(headcol)

Modifies the column headers to be compatible with numpy column lookup.

Args:
list columns ([string]): list of column names.
Returns:
list columns ([string]): fixed list of column names.
Raises:
No exception is raised.
pyradi.rymodtran.runModtranAndCopy(root, research, pathToModtranBin, execname)

Look for input files in directories, run modtran and copy results to dir.

Finds all files below the root directory that matches the regex pattern in research. Then runs modtran on these files and write the tape5/6/7/8 back to where the input file was.

Each input file must be in a separate directory, because the results are all written to files with the names ‘tape5’, etc.

Args:
root ([string]): path to root dir containing the dirs with modtran input files.
research ([string]): regex to use when searching for input files (‘.*.ltn’ or ‘tape5’)
pathToModtranBin ([string]): path to modtran executable directory.
execname ([string]): modtran executable filename.
Returns:
List of all the files processed.
Raises:
No exception is raised.