LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Functions
lsst.meas.astrom.sip.cleanBadPoints Namespace Reference

Functions

def clean
 
def indicesOfGoodPoints
 
def chooseRx
 
def chooseRy
 

Function Documentation

def lsst.meas.astrom.sip.cleanBadPoints.chooseRx (   x,
  idx,
  order 
)
Create order+1 values of the ordinate based on the median of groups of elements of x

Definition at line 110 of file cleanBadPoints.py.

111 def chooseRx(x, idx, order):
112  """Create order+1 values of the ordinate based on the median of groups of elements of x"""
113  rSize = len(idx)/float(order+1) #Note, a floating point number
114  rx = np.zeros((order+1))
115 
116  for i in range(order+1):
117  rng = range(int(rSize*i), int(rSize*(i+1)))
118  rx[i] = np.mean(x[idx[rng]])
119  return rx
120 
def lsst.meas.astrom.sip.cleanBadPoints.chooseRy (   y,
  idx,
  order 
)
Create order+1 values of the ordinate based on the median of groups of elements of y

Definition at line 121 of file cleanBadPoints.py.

122 def chooseRy(y, idx, order):
123  """Create order+1 values of the ordinate based on the median of groups of elements of y"""
124  rSize = len(idx)/float(order+1) #Note, a floating point number
125  ry = np.zeros((order+1))
126 
127  for i in range(order+1):
128  rng = range(int(rSize*i), int(rSize*(i+1)))
129  ry[i] = np.median(y[idx[rng]])
130  return ry
131 
def lsst.meas.astrom.sip.cleanBadPoints.clean (   srcMatch,
  wcs,
  order = 3,
  nsigma = 3 
)
Remove bad points from srcMatch

Input:
srcMatch : std::vector<det::SourceMatch>
order:      Order of polynomial to use in robust fitting
nsigma:    Sources more than this far away from the robust best fit
            polynomial are removed
            
Return:
std::vector<det::SourceMatch> of the good data points

Definition at line 32 of file cleanBadPoints.py.

32 
33 def clean(srcMatch, wcs, order=3, nsigma=3):
34  """Remove bad points from srcMatch
35 
36  Input:
37  srcMatch : std::vector<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
41 
42  Return:
43  std::vector<det::SourceMatch> of the good data points
44  """
45 
46  N = len(srcMatch)
47  catX = np.zeros(N)
48  #catY = np.zeros(N)
49  for i in range(N):
50  x,y = wcs.skyToPixel(srcMatch[i].first.getCoord())
51  catX[i] = x
52  #catY[i] = y
53 
54  ## FIXME -- why does this only use X?
55 
56  x = np.array([s.second.getX() for s in srcMatch])
57  dx = x - catX
58  sigma = np.zeros_like(dx) + 0.1
59 
60  idx = indicesOfGoodPoints(x, dx, sigma, order=order, nsigma=nsigma)
61 
62  clean = []
63  for i in idx:
64  clean.append(srcMatch[i])
65  return clean
66 
67 
def lsst.meas.astrom.sip.cleanBadPoints.indicesOfGoodPoints (   x,
  y,
  s,
  order = 1,
  nsigma = 3,
  maxiter = 100 
)
Return a list of indices in the range [0, len(x)]
of points that lie less than nsigma away from the robust
best fit polynomial

Definition at line 68 of file cleanBadPoints.py.

68 
69 def indicesOfGoodPoints(x, y, s, order=1, nsigma=3, maxiter=100):
70  """Return a list of indices in the range [0, len(x)]
71  of points that lie less than nsigma away from the robust
72  best fit polynomial
73  """
74 
75  #Indices of elements of x sorted in order of increasing value
76  idx = x.argsort()
77  newidx=[]
78  for niter in xrange(maxiter):
79  rx = chooseRx(x, idx, order)
80  ry = chooseRy(y, idx, order)
81  rs = np.ones((len(rx)))
82 
83  lsf = sip.LeastSqFitter1dPoly(list(rx), list(ry), list(rs), order)
84  fit = map(lambda x: lsf.valueAt(x), rx)
85  f = map(lambda x: lsf.valueAt(x), x)
86 
87  sigma = (y-f).std()
88  deviance = np.fabs( (y - f) /sigma)
89  newidx = np.flatnonzero(deviance < nsigma)
90 
91  if False:
92  import matplotlib.pyplot as mpl
93  mpl.plot(x, y, 'ks')
94  mpl.plot(rx, ry, 'b-')
95  mpl.plot(rx, ry, 'bs')
96  mpl.plot(rx, fit, 'ms')
97  mpl.plot(rx, fit, 'm-')
98  #mpl.plot(x[newidx], y[newidx], 'rs')
99  mpl.show()
100 
101  # If we haven't culled any points we're finished cleaning
102  if len(newidx) == len(idx):
103  break
104 
105  # We get here because we either a) stopped finding bad points
106  # or b) ran out of iterations. Either way, we just return our
107  # list of indices of good points.
108  return newidx
109 
STL namespace.