4 * DESCRIPTION: Executable program to automate running of afrt (radiative
5 * transfer) application in configurable increments of the inputs and outputs
7 * USAGE: python afrt.py -p [PCF file path] -wl [wavelength range]
8 -sd [particle model range] -tau [optical depth range]
9 -wnd [wind speed range]
11 * Created on October 09, 2018
13 * Author: Samuel Anderson
18 from datetime
import datetime
as dt
19 import optparse
as optparse
21 LOG = logging.getLogger(
'afrt')
32 description =
'''Execute afrt and generate NetCDF output files.'''
33 usage =
"usage: python afrt.py -p [PCF] -wl [wavelength id range] -sd [model id range] -tau [tau id range] -wnd [wind id range] -o [output directory] [options]"
36 parser = optparse.OptionParser(description=description,usage=usage,version=version)
39 mandatoryGroup = optparse.OptionGroup(parser,
"Mandatory Arguments",
40 "At a minimum these arguments must be specified")
42 parser.add_option_group(mandatoryGroup)
44 mandatoryGroup.add_option(
'-p',
'--par',
48 help=
"The full path of the parameters file")
51 optionalGroup = optparse.OptionGroup(parser,
"Extra Options",
52 "These options may be used to customize behavior of this program.")
54 optionalGroup.add_option(
'-l',
'--wl',
59 help=
"Range of wavelength indices")
61 optionalGroup.add_option(
'-s',
'--sd',
66 help=
"Range of particle model indices")
68 optionalGroup.add_option(
'-t',
'--tau',
73 help=
"Range of optical depth indices")
75 optionalGroup.add_option(
'-w',
'--wnd',
80 help=
"Range of optical depth indices")
82 optionalGroup.add_option(
'-o',
'--odir',
86 help=
"The full path of the output directories")
88 parser.add_option(
'-v',
'--verbose',
92 help=
'each occurrence increases verbosity 1 level from ERROR: -v=WARNING -vv=INFO -vvv=DEBUG')
94 parser.add_option_group(optionalGroup)
97 (opt, args) = parser.parse_args()
100 levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
101 logging.basicConfig(level = levels[opt.verbosity])
107 isMissingMand =
False
108 for m,m_err
in zip(mandatories,mand_errors):
109 if not opt.__dict__[m]:
113 parser.error(
"Incomplete mandatory arguments, aborting...")
117 opt.odir = os.path.expanduser(opt.odir)
120 LOG.info(
'Generating radiative transfer tables in %s' % (opt.odir) )
122 if os.path.isdir(opt.odir):
124 elif os.path.isdir(os.path.dirname(opt.odir)):
128 print (
"Output path invalid")
139 for isd
in range(opt.sd[0],opt.sd[1]+1):
140 for iwl
in range(opt.wl[0],opt.wl[1]+1):
141 for itau
in range(opt.tau[0],opt.tau[1]+1):
142 for iwnd
in range(opt.wnd[0],opt.wnd[1]+1):
143 print (
"wl:" +
str(iwl) +
" sd:" +
str(isd) +
" tau:" +
str(itau) +
" wnd:" +
str(iwnd))
144 wl_istr =
" wave_id=" +
str(iwl) +
"," +
str(iwl)
145 sd_istr =
" model_id=" +
str(isd) +
"," +
str(isd)
146 tau_istr =
" tau_id=" +
str(itau) +
"," +
str(itau)
147 wnd_istr =
" wind_id=" +
str(iwnd) +
"," +
str(iwnd)
148 ofile_istr =
" ofile=" + opt.odir +
"/RT" +
str(rid) +
"_MD" +
str(isd) +
"_WL" +
str(iwl) +
"_TA" +
str(itau) +
"_WD" +
str(iwnd) +
".nc"
149 command =
"afrt_nc4 " + spcf + sd_istr + wl_istr + tau_istr + wnd_istr + ofile_istr
151 result = os.system(command)
154 print(
'Processing completed')
155 LOG.info(
'Exiting...')
158 if __name__==
'__main__':