225 def solve(self, science, fringes):
226 """Solve (with iterative clipping) for the scale factors
228 @param science Array of science exposure fringe amplitudes
229 @param fringes Array of arrays of fringe frame fringe amplitudes
230 @return Array of scale factors for the fringe frames
235 origNum = len(science)
237 good = numpy.where(numpy.logical_and(numpy.isfinite(science), numpy.any(numpy.isfinite(fringes), 1)))
238 science = science[good]
239 fringes = fringes[good]
240 oldNum = len(science)
242 for i
in range(self.config.iterations):
243 solution = self.
_solve(science, fringes)
244 resid = science - numpy.sum(solution * fringes, 1)
246 good = numpy.logical_not(abs(resid) > self.config.clip * rms)
247 self.log.logdebug(
"Iteration %d: RMS=%f numGood=%d" % (i, rms, good.sum()))
248 self.log.logdebug(
"Solution %d: %s" % (i, solution))
252 import matplotlib.pyplot
as plot
253 for j
in range(fringes.shape[1]):
257 fig.canvas._tkcanvas._root().lift()
260 ax = fig.add_axes((0.1, 0.1, 0.8, 0.8))
261 adjust = science.copy()
262 others = set(range(fringes.shape[1]))
265 adjust -= solution[k] * fringes[:,k]
266 ax.plot(fringes[:,j], adjust,
'r.')
267 xmin = fringes[:,j].min()
268 xmax = fringes[:,j].max()
269 ymin = solution[j] * xmin
270 ymax = solution[j] * xmax
271 ax.plot([xmin, xmax], [ymin, ymax],
'b-')
272 ax.set_title(
"Fringe %d: %f" % (j, solution[j]))
273 ax.set_xlabel(
"Fringe amplitude")
274 ax.set_ylabel(
"Science amplitude")
275 ax.set_autoscale_on(
False)
276 ax.set_xbound(lower=xmin, upper=xmax)
277 ax.set_ybound(lower=ymin, upper=ymax)
280 ans = raw_input(
"Enter or c to continue [chp]").lower()
281 if ans
in (
"",
"c",):
284 import pdb; pdb.set_trace()
286 print "h[elp] c[ontinue] p[db]"
292 good = numpy.where(good)
293 science = science[good]
294 fringes = fringes[good]
297 solution = self.
_solve(science, fringes)
298 self.log.info(
"Fringe solution: %s RMS: %f Good: %d/%d" % (solution, rms, len(science), origNum))