32 def clean(srcMatch, wcs, order=3, nsigma=3):
33 """Remove bad points from srcMatch
36 srcMatch : std::vector<det::SourceMatch>
37 order: Order of polynomial to use in robust fitting
38 nsigma: Sources more than this far away from the robust best fit
39 polynomial are removed
42 std::vector<det::SourceMatch> of the good data points
49 x,y = wcs.skyToPixel(srcMatch[i].first.getCoord())
55 x = np.array([s.second.getX()
for s
in srcMatch])
57 sigma = np.zeros_like(dx) + 0.1
63 clean.append(srcMatch[i])
69 """Return a list of indices in the range [0, len(x)]
70 of points that lie less than nsigma away from the robust
77 for niter
in xrange(maxiter):
80 rs = np.ones((len(rx)))
82 lsf = sip.LeastSqFitter1dPoly(list(rx), list(ry), list(rs), order)
83 fit = map(
lambda x: lsf.valueAt(x), rx)
84 f = map(
lambda x: lsf.valueAt(x), x)
87 deviance = np.fabs( (y - f) /sigma)
88 newidx = np.flatnonzero(deviance < nsigma)
91 import matplotlib.pyplot
as mpl
93 mpl.plot(rx, ry,
'b-')
94 mpl.plot(rx, ry,
'bs')
95 mpl.plot(rx, fit,
'ms')
96 mpl.plot(rx, fit,
'm-')
101 if len(newidx) == len(idx):
111 """Create order+1 values of the ordinate based on the median of groups of elements of x"""
112 rSize = len(idx)/float(order+1)
113 rx = np.zeros((order+1))
115 for i
in range(order+1):
116 rng = range(int(rSize*i), int(rSize*(i+1)))
117 rx[i] = np.mean(x[idx[rng]])
122 """Create order+1 values of the ordinate based on the median of groups of elements of y"""
123 rSize = len(idx)/float(order+1)
124 ry = np.zeros((order+1))
126 for i
in range(order+1):
127 rng = range(int(rSize*i), int(rSize*(i+1)))
128 ry[i] = np.median(y[idx[rng]])