1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """
26 This programs plots data files handled or produced by data reduction.
27 """
28
30 """
31 This method is where the data reduction process gets done.
32
33 @param config: Object containing the data reduction configuration
34 information.
35 @type config: L{hlr_utils.Configure}
36 """
37 import dr_lib
38
39 if config.data is None:
40 raise RuntimeError("Need to pass a data filename(s) to the driver "\
41 +"script.")
42
43 dst_type = hlr_utils.file_peeker(config.data[0])
44
45 if config.verbose:
46 print "Initial file type (data set):", dst_type
47
48 d_som = dr_lib.add_files(config.data, dst_type=dst_type,
49 Signal_ROI=config.roi_file,
50 Verbose=config.verbose)
51
52 if dst_type == "text/Spec":
53 __plot_a3c(d_som, config)
54 elif dst_type == "text/Dave2d":
55 if config.projx:
56 drplot.plot_1D_slice(d_som, "y", config.range, (None, None),
57 logx=config.logx, logy=config.logy,
58 line=config.line)
59 elif config.projy:
60 drplot.plot_1D_slice(d_som, "x", (None, None), config.range,
61 logx=config.logx, logy=config.logy,
62 line=config.line)
63 elif config.slicex:
64 drplot.plot_1D_slices(d_som, "y", config.range,
65 logx=config.logx, logy=config.logy,
66 line=config.line)
67 elif config.slicey:
68 drplot.plot_1D_slices(d_som, "x", config.range,
69 logx=config.logx, logy=config.logy,
70 line=config.line)
71 else:
72 drplot.plot_2D_so(d_som, logz=config.logz, box=config.box)
73 elif dst_type == "text/num-info":
74 drplot.plot_numinfo(d_som)
75 else:
76 raise RuntimeError("Do not know how to plot file type %s" % dst_type)
77
78 pylab.show()
79
81 """
82 This subroutine is responsible for plotting a 3-column ASCII file.
83 """
84 len_som = len(som)
85
86 if len_som > 1:
87
88 num_figs = len_som / 10 + 1
89
90 left_over = len_som % 10
91 else:
92 num_figs = 1
93 left_over = 1
94
95 for i in xrange(num_figs):
96 if len_som > 1:
97 pylab.figure(i+1)
98 if i+1 == num_figs:
99 extent = left_over
100 else:
101 extent = 10
102
103 for j in xrange(extent):
104 if len_som > 1:
105 pylab.subplot(2, 5, j+1)
106 index = (i*10) + j
107
108 pid = som[index].id
109
110 try:
111 drplot.plot_1D_so(som, pid, title=pid, logy=conf.logy,
112 logx=conf.logx, line=conf.line)
113 except ValueError:
114
115 pass
116
117 if __name__ == "__main__":
118 import drplot
119 import hlr_utils
120
121 import pylab
122
123
124 description = []
125 description.append("")
126
127
128 parser = hlr_utils.BasicOptions("usage: %prog [options]", None, None,
129 hlr_utils.program_version(), 'error',
130 " ".join(description))
131
132 parser.add_option("", "--roi-file", dest="roi_file",
133 help="Specify a file that contains a list of pixel "\
134 +"ids to be read from the data")
135
136 parser.add_option("", "--logy", dest="logy", action="store_true",
137 help="Set the y-axis to logarithmic scale.")
138 parser.set_defaults(logy=False)
139
140 parser.add_option("", "--logx", dest="logx", action="store_true",
141 help="Set the x-axis to logarithmic scale.")
142 parser.set_defaults(logx=False)
143
144 parser.add_option("", "--logz", dest="logz", action="store_true",
145 help="Set the z-axis to logarithmic scale.")
146 parser.set_defaults(logz=False)
147
148 parser.add_option("", "--projx", dest="projx", action="store_true",
149 help="Project a 2D distribution along x.")
150 parser.set_defaults(projx=False)
151
152 parser.add_option("", "--projy", dest="projy", action="store_true",
153 help="Project a 2D distribution along y.")
154 parser.set_defaults(projy=False)
155
156 parser.add_option("", "--range", dest="range", type="float", nargs=2,
157 help="Set the range to filter on the opposite "\
158 +"axis when projecting or slicing a 2D distribution.")
159
160 parser.add_option("", "--slicex", dest="slicex", action="store_true",
161 help="Show x distributions for each y from a 2D "\
162 +"distribution.")
163 parser.set_defaults(slicex=False)
164
165 parser.add_option("", "--slicey", dest="slicey", action="store_true",
166 help="Show y distributions for each x from a 2D "\
167 +"distribution.")
168 parser.set_defaults(slicey=False)
169
170 parser.add_option("-l", "--line", dest="line", action="store_true",
171 help="Draw a line connecting points for 1D plots.")
172
173 parser.add_option("-b", "--box", dest="box", action="store_true",
174 help="Plot 2D distribution as a box plot.")
175 parser.set_defaults(box=False)
176
177
178 parser.remove_option("--config")
179 parser.remove_option("--data")
180 parser.remove_option("--output")
181
182 (options, args) = parser.parse_args()
183
184
185 configure = hlr_utils.Configure()
186
187
188 configure.inst = None
189
190
191 configure.facility = None
192
193
194 old_verbosity = options.verbose
195 options.verbose = False
196
197
198 hlr_utils.BasicConfiguration(parser, configure, options, args)
199
200
201 configure.verbose = old_verbosity
202
203
204 configure.roi_file = hlr_utils.determine_files(options.roi_file,
205 one_file=True)
206
207
208 configure.logy = options.logy
209
210
211 configure.logx = options.logx
212
213
214 configure.logz = options.logz
215
216
217 configure.projx = options.projx
218
219
220 configure.projy = options.projy
221
222
223
224 if options.range is None:
225 configure.range = (None, None)
226 else:
227 configure.range = options.range
228
229
230 configure.slicex = options.slicex
231
232
233 configure.slicey = options.slicey
234
235
236 configure.line = options.line
237
238
239 configure.box = options.box
240
241
242 run(configure)
243