Go to the documentation of this file.
3 __author__=
"Sean Bailey, Futuretech Corporation"
4 __date__ =
"$Apr 10, 2010 4:49:15 PM$"
11 Parameter processing class - build and parse par files
13 def __init__(self, params=None,parfile=None,parstr='',sensor=None,verbose=False):
15 Set up parameter processing methods
17 if params
is None: params = {}
26 """Build a parameter file from a dictionary of parameters.
27 Writes parfile if pfile is defined, else Returns parfile string."""
29 for k
in self.
params[prog].keys():
30 if re.match(
'ocproc',k):
33 filelst = [
'ifile',
'ofile',
'ofile1',
'ofile2',
'ofile3',
'geofile',
34 'spixl',
'dpixl',
'epixl',
'sline',
'eline',
'dline',
35 'north',
'south',
'west',
'east']
39 pstr =
'='.join([f, self.
params[prog][f]])
44 for k,v
in sorted(self.
params[prog].items()):
50 pstr =
'='.join([k, v])
57 print(
"Writing parfile %s" % self.
parfile)
58 logfile = open(self.
parfile,
'w')
67 Parse a parameter file, returning a dictionary listing
73 par_file = open(pfile,
'r')
75 print(
"File {0} not found!".format(self.
parfile))
83 lines = par_file.readlines()
85 if (len(line) == 0)
or re.match(
'^\s+$',line):
90 ix = parts.index(
'section')
91 prog = parts[ix + 1].strip()
100 if line.find(
'=') != -1:
101 line_parts = line.split(
'#')[0].strip().split(
'=')
103 if line_parts[0] ==
'par':
105 p2.parseParFile(prog=prog)
107 elif line_parts[0] ==
'ifile':
108 self.
params[prog][
'file'] = line_parts[1]
110 self.
params[prog][line_parts[0]] = line_parts[1]
112 err_msg =
'Error! Entry "{0}" is invalid in par file {1}'.format(line, self.
parfile)
117 """Given a program, derive a standard output filename"""
119 ifile = self.
params[prog][
'ifile']
120 modsen ={
'A':
'T',
'P':
'A'}
124 ofile = self.
params[prog][
'ofile']
126 fparts = ifile.split(
'.')
128 if re.search(
'L0',ifile):
129 ofile = ifile.replace(
'L0',
'L1A')
130 elif re.match(
'M?D*',ifile):
134 ofile =
''.join([modsen[type],yrdy,hrmn,
'00.L1A_LAC'])
135 elif prog ==
'l1brsgen':
136 ofile =
'.'.join([fparts[0],
'L1_BRS'])
137 elif prog ==
'l1mapgen':
138 ofile =
'.'.join([fparts[0],
'L1_MAP'])
139 elif prog ==
'l2gen':
140 if re.search(
'L1[AB]',ifile):
141 of = re.compile(
'(L1A|L1B)')
142 ofile = of.sub(
'L2', ifile)
144 ofile =
'.'.join([fparts[0],
'L2'])
145 elif prog ==
'l2brsgen':
147 prod = self.
params[prog][
'prod']
150 ofile =
'.'.join([fparts[0],prod,
'L2_BRS'])
151 elif prog ==
'l2mapgen':
153 prod = self.
params[prog][
'prod']
156 ofile =
'.'.join([fparts[0],prod,
'L2_MAP'])
157 elif prog ==
'l2bin':
158 ofile =
'output.file'
159 elif prog ==
'l3bin':
160 ofile =
'output.file'
161 elif prog ==
'smigen':
162 ofile =
'output.file'
163 elif prog ==
'smitoppm':
164 ofile =
'.'.join([ifile,
'ppm'])
165 elif prog ==
'l3gen':
166 ofile =
'output.file'
169 ofile =
'.'.join([prog,
'output_file'])
171 self.
params[prog][
'ofile'] = ofile
def buildParameterFile(self, prog)
def parseParFile(self, prog='main')
def __init__(self, params=None, parfile=None, parstr='', sensor=None, verbose=False)
def genOutputFilename(self, prog=None)