Skip to content

Commit

Permalink
calibs: optimise pixel-by-pixel mask
Browse files Browse the repository at this point in the history
Calculating the focal-plane offset of each pixel is very slow (it always
has been, but it seems slower with the new Transform API), but the new
Transform API allows us to vectorise the calculation.
  • Loading branch information
PaulPrice committed Dec 7, 2017
1 parent 8e16056 commit 3d4fc28
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions python/lsst/obs/hsc/calibs.py
Expand Up @@ -78,17 +78,16 @@ def maskVignetting(self, mask, detector):
mask |= bitMask
return
# We have to go pixel by pixel
x = np.empty((h, w))
y = np.empty_like(x)
for j in range(mask.getHeight()):
for i in range(mask.getWidth()):
x[j, i], y[j, i] = transform.applyForward(afwGeom.Point2D(i, j))
R = np.hypot(x - self.config.vignette.xCenter, y - self.config.vignette.yCenter)
isBad = R > self.config.vignette.radius
numPixels = w*h
xx, yy = np.meshgrid(np.arange(0, w, dtype=int), np.arange(0, h, dtype=int))
xyDetector = [afwGeom.Point2D(x, y) for x, y in zip(xx.reshape(numPixels), yy.reshape(numPixels))]
xyFocalPlane = transform.applyForward(xyDetector)
origin = afwGeom.Point2D(self.config.vignette.xCenter, self.config.vignette.yCenter)
r2 = np.array([pp.distanceSquared(origin) for pp in xyFocalPlane])
isBad = (r2 > self.config.vignette.radius**2).reshape((h, w))
self.log.info("Detector %d has %f%% pixels vignetted" %
(detector.getId(), isBad.sum()/float(isBad.size)*100.0))
maskArray = mask.getArray()
xx, yy = np.meshgrid(np.arange(w), np.arange(h))
maskArray[yy[isBad], xx[isBad]] |= bitMask

def maskBadAmps(self, mask, detector):
Expand Down

0 comments on commit 3d4fc28

Please sign in to comment.