28 from .
import LeastSqFitter1dPoly
31 def clean(srcMatch, wcs, order=3, nsigma=3):
32 """Remove bad points from srcMatch 35 srcMatch : list of det::SourceMatch 36 order: Order of polynomial to use in robust fitting 37 nsigma: Sources more than this far away from the robust best fit 38 polynomial are removed 41 list of det::SourceMatch of the good data points 48 x, y = wcs.skyToPixel(srcMatch[i].first.getCoord())
54 x = np.array([s.second.getX()
for s
in srcMatch])
56 sigma = np.zeros_like(dx) + 0.1
62 clean.append(srcMatch[i])
67 """Return a list of indices in the range [0, len(x)] 68 of points that lie less than nsigma away from the robust 75 for niter
in range(maxiter):
78 rs = np.ones((len(rx)))
80 lsf = LeastSqFitter1dPoly(list(rx), list(ry), list(rs), order)
81 fit = [lsf.valueAt(value)
for value
in rx]
82 f = [lsf.valueAt(value)
for value
in x]
85 deviance = np.fabs((y - f) / sigma)
86 newidx = np.flatnonzero(deviance < nsigma)
89 import matplotlib.pyplot
as plt
91 plt.plot(rx, ry,
'b-')
92 plt.plot(rx, ry,
'bs')
93 plt.plot(rx, fit,
'ms')
94 plt.plot(rx, fit,
'm-')
99 if len(newidx) == len(idx):
109 """Create order+1 values of the ordinate based on the median of groups of elements of x""" 110 rSize = len(idx)/float(order+1)
111 rx = np.zeros((order+1))
113 for i
in range(order+1):
114 rng = list(range(int(rSize*i), int(rSize*(i+1))))
115 rx[i] = np.mean(x[idx[rng]])
120 """Create order+1 values of the ordinate based on the median of groups of elements of y""" 121 rSize = len(idx)/float(order+1)
122 ry = np.zeros((order+1))
124 for i
in range(order+1):
125 rng = list(range(int(rSize*i), int(rSize*(i+1))))
126 ry[i] = np.median(y[idx[rng]])
def indicesOfGoodPoints(x, y, s, order=1, nsigma=3, maxiter=100)
def clean(srcMatch, wcs, order=3, nsigma=3)
def chooseRx(x, idx, order)
def chooseRy(y, idx, order)