Skip to content

Commit

Permalink
Add code to build validPolygon for each image.
Browse files Browse the repository at this point in the history
The settings for the vignetted region was broken out into a
separate config file to be used in different places in the code.
  • Loading branch information
rearmstr committed Nov 5, 2014
1 parent 52733a7 commit e3012f5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
4 changes: 1 addition & 3 deletions config/hsc/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

from lsst.obs.hsc.detrends import HscFlatCombineTask
root.combination.retarget(HscFlatCombineTask)
root.combination.xCenter = -100
root.combination.yCenter = 100
root.combination.radius = 17500
root.combination.load(os.path.join(os.environ['OBS_SUBARU_DIR'], 'config', 'hsc', 'vignette.py'))
4 changes: 3 additions & 1 deletion config/hsc/isr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Configuration for HSC ISR

import os
from lsst.obs.subaru.isr import SubaruIsrTask
root.isr.retarget(SubaruIsrTask)
from lsst.obs.subaru.crosstalk import CrosstalkTask
Expand All @@ -22,3 +22,5 @@
-171.0e-6, -134.0e-6, 0.0e-6, -153.0e-6,
-157.0e-6, -151.0e-6, -137.0e-6, 0.0e-6,
]

root.isr.vignette.load(os.path.join(os.environ['OBS_SUBARU_DIR'], 'config', 'hsc', 'vignette.py'))
4 changes: 4 additions & 0 deletions config/hsc/vignette.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

root.xCenter = -100
root.yCenter = 100
root.radius = 17500
12 changes: 5 additions & 7 deletions python/lsst/obs/hsc/detrends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

from lsst.pex.config import Field, ListField
from hsc.pipe.tasks.detrends import FlatCombineConfig, FlatCombineTask
from lsst.obs.hsc.vignette import VignetteConfig
import lsst.afw.image as afwImage
import lsst.afw.geom as afwGeom
import lsst.afw.cameraGeom as afwcg

class HscFlatCombineConfig(FlatCombineConfig):
xCenter = Field(dtype=float, default=0, doc="Center of vignetting pattern, in x (focal plane coords)")
yCenter = Field(dtype=float, default=0, doc="Center of vignetting pattern, in y (focal plane coords)")
radius = Field(dtype=float, default=18300, doc="Radius of vignetting pattern, in focal plane coords",
check=lambda x: x >= 0)
vignette = ConfigField(dtype=VignetteConfig, doc="Vignetting parameters in focal plane coordinates")
badAmpCcdList = ListField(dtype=int, default=[], doc="List of CCD serial numbers for bad amplifiers")
badAmpList = ListField(dtype=int, default=[], doc="List of amp serial numbers in CCD")
maskPlane = Field(dtype=str, default="NO_DATA", doc="Mask plane to set")
Expand Down Expand Up @@ -58,7 +56,7 @@ def maskVignetting(self, mask, detector):
numCorners = 0 # Number of corners outside radius
for i, j in ((0, 0), (0, h-1), (w-1, 0), (w-1, h-1)):
x,y = detector.getPositionFromPixel(afwGeom.PointD(i, j)).getMm()
if math.hypot(x - self.config.xCenter, y - self.config.yCenter) > self.config.radius:
if math.hypot(x - self.config.vignette.xCenter, y - self.config.vignette.yCenter) > self.config.radius:
numCorners += 1
if numCorners == 0:
# Nothing to be masked
Expand All @@ -76,8 +74,8 @@ def maskVignetting(self, mask, detector):
for j in range(mask.getHeight()):
for i in range(mask.getWidth()):
x[j, i], y[j, i] = detector.getPositionFromPixel(afwGeom.PointD(i, j)).getMm()
R = np.hypot(x - self.config.xCenter, y - self.config.yCenter)
isBad = R > self.config.radius
R = np.hypot(x - self.config.vignette.xCenter, y - self.config.vignette.yCenter)
isBad = R > self.config.vignette.radius
self.log.info("Detector %s has %f%% pixels vignetted" %
(detector.getId().getSerial(), isBad.sum()/float(isBad.size)*100.0))
maskArray = mask.getArray()
Expand Down
11 changes: 11 additions & 0 deletions python/lsst/obs/hsc/vignette.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from lsst.pex.config import Config, Field

class VignetteConfig(Config):
"""
Settings to define vignetting pattern
"""
xCenter = Field(dtype=float, default=0, doc="Center of vignetting pattern, in x (focal plane coords)")
yCenter = Field(dtype=float, default=0, doc="Center of vignetting pattern, in y (focal plane coords)")
radius = Field(dtype=float, default=18300, doc="Radius of vignetting pattern, in focal plane coords",
check=lambda x: x >= 0)

22 changes: 22 additions & 0 deletions python/lsst/obs/subaru/isr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import lsst.afw.math as afwMath
from lsst.obs.subaru.crosstalkYagi import YagiCrosstalkTask
import lsst.meas.algorithms as measAlg
from lsst.obs.hsc.vignette import VignetteConfig
from lsst.afw.geom.polygon import Polygon

try:
import hsc.fitsthumb as fitsthumb
Expand Down Expand Up @@ -127,6 +129,17 @@ class SubaruIsrConfig(IsrTask.ConfigClass):
default=False)
overscanMaxDev = pexConfig.Field(dtype=float, doc="Maximum deviation from the median for overscan",
default=1000.0, check=lambda x: x > 0)
vignette = pexConfig.ConfigField(dtype=VignetteConfig, doc="Vignetting parameters in focal plane coordinates")
numPolygonPoints = pexConfig.Field(
dtype = int,
doc = "Number of points to define the Vignette polygon",
default = 100,
)
doWriteVignettePolygon = pexConfig.Field(
dtype = bool,
doc = "Persist Polygon used to define vignetted region?",
default = True,
)

def validate(self):
super(SubaruIsrConfig, self).validate()
Expand All @@ -145,6 +158,12 @@ class SubaruIsrTask(IsrTask):
def __init__(self, *args, **kwargs):
super(SubaruIsrTask, self).__init__(*args, **kwargs)
self.makeSubtask("crosstalk")
if self.config.doWriteVignettePolygon:
theta = numpy.linspace(0, 2*numpy.pi, num= self.config.numPolygonPoints, endpoint=False)
x = self.config.vignette.radius*numpy.cos(theta) + self.config.vignette.xCenter
y = self.config.vignette.radius*numpy.sin(theta) + self.config.vignette.yCenter
points = numpy.array([x, y]).transpose()
self.vignettePolygon = Polygon([afwGeom.Point2D(x,y) for x,y in reversed(points)])

def run(self, sensorRef):
self.log.log(self.log.INFO, "Performing ISR on sensor %s" % (sensorRef.dataId))
Expand Down Expand Up @@ -248,6 +267,9 @@ def run(self, sensorRef):
if self.config.doGuider:
self.guider(ccdExposure)

if self.config.doWriteVignettePolygon:
self.setValidPolygonIntersect(ccdExposure, self.vignettePolygon)

if self.config.doWrite:
sensorRef.put(ccdExposure, "postISRCCD")

Expand Down

0 comments on commit e3012f5

Please sign in to comment.