22 from __future__
import absolute_import, division, print_function
26 from builtins
import range
30 from .
import LeastSqFitter1dPoly
33 def clean(srcMatch, wcs, order=3, nsigma=3):
34 """Remove bad points from srcMatch 37 srcMatch : list of det::SourceMatch 38 order: Order of polynomial to use in robust fitting 39 nsigma: Sources more than this far away from the robust best fit 40 polynomial are removed 43 list of det::SourceMatch of the good data points 50 x, y = wcs.skyToPixel(srcMatch[i].first.getCoord())
56 x = np.array([s.second.getX()
for s
in srcMatch])
58 sigma = np.zeros_like(dx) + 0.1
64 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 range(maxiter):
80 rs = np.ones((len(rx)))
82 lsf = LeastSqFitter1dPoly(list(rx), list(ry), list(rs), order)
83 fit = [lsf.valueAt(value)
for value
in rx]
84 f = [lsf.valueAt(value)
for value
in x]
87 deviance = np.fabs((y - f) / sigma)
88 newidx = np.flatnonzero(deviance < nsigma)
91 import matplotlib.pyplot
as plt
93 plt.plot(rx, ry,
'b-')
94 plt.plot(rx, ry,
'bs')
95 plt.plot(rx, fit,
'ms')
96 plt.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 = list(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 = list(range(int(rSize*i), int(rSize*(i+1))))
128 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)