Debian Codegraph @

commissioning/convert/convertcases.py

raw symbols SCIP
1 import sys,os
2 import sqlite3
3
4 def run():
5 """ Generate TestCases from cmdfile according to the pattern in patternfile"""
6 #Define the import statements
7 impheader = """import sys
8 import conv_base
9
10 """
11 #Define the test case pattern
12 pattern="""class Test%d(conv_base.%sCase):
13 @classmethod
14 def setUpClass(cls):
15 cls.obsmode="%s"
16 cls.spectrum="%s"
17 cls.fname="C%s_%s.fits"
18 cls.setup2()\n\n"""
19
20
21 #We're going to split these by obsmode.
22 outfiles = {'None':'sponly/sponly.py',
23 'acs':'acs/acs.py',
24 'nicmos':'nicmos/nicmos.py',
25 'stis':'stis/stis.py',
26 'wfc3,ir':'wfc3_ir/wfc3_ir.py',
27 'wfc3,uvis1':'wfc3_uvis1/wfc3_uvis1.py',
28 'wfc3,uvis2':'wfc3_uvis2/wfc3_uvis2.py',
29 'oops':'oops/oops.py'
30 }
31
32 #And subclass for spectrum-only and thermal cases based on obsmode.
33 casetype = {"None": "Spec",
34 "nicmos": "Therm",
35 "wfc3,ir": "Therm"}
36 #Use with default=Comm
37
38 #Open the database
39 db = sqlite3.connect("/ssbwebv1/data1/pandokia/old/pdk/c3/db/pdk.db")
40
41
42 #Open and initialize the output files
43 setdirs(outfiles)
44 for k in outfiles:
45 outfiles[k] = open(outfiles[k], 'w')
46 outfiles[k].write(impheader)
47
48 count=0
49
50 #Select unique (obsmode,spectrum) pairs from our database table of
51 #commissioning tests. Sort them by obsmode.
52
53 #Omit cases where spectrum is None, because we've verified that all
54 #those obsmodes are duplicated elsewhere.
55
56 #First the bp only. The purpose of these is thermal.
57 c = db.execute(""" SELECT DISTINCT obsmode, spectrum
58 FROM synpysyn
59 WHERE spectrum != "None"
60 ORDER BY obsmode""")
61
62 #Now loop over them, and define test cases.
63 for x in c:
64 obsmode, spectrum = x
65 count+=1
66 outkey=pickname(obsmode,outfiles)
67 defn=pattern%(count,
68 casetype.get(outkey, "Comm"),
69 obsmode,spectrum,count,"%s")
70 outfiles[outkey].write(defn)
71
72 #Close all the files
73 for k in outfiles:
74 outfiles[k].close()
75
76 def setdirs(outfiles):
77 """Create the directories if need be"""
78 for k in outfiles:
79 fname=outfiles[k]
80 dname= os.path.dirname(fname)
81 if not os.path.isdir(dname):
82 os.mkdir(dname)
83
84 def pickname(obsmode, outfiles):
85 """The obsmode string starts with one of the keys of outfiles.
86 Pick the right one and return it."""
87
88 for k in outfiles:
89 if obsmode.startswith(k):
90 return k
91
92 return 'oops'
93
94 if __name__ == '__main__':
95 run()
96