23 from __future__
import absolute_import, division, print_function
24 from builtins
import range
39 pixelScale = lsst.pex.config.Field(
40 dtype=float, default=0.2, optional=
False,
41 doc=
"Pixel scale for mock WCSs in arcseconds/pixel" 43 doRotate = lsst.pex.config.Field(
44 dtype=bool, default=
True, optional=
False,
45 doc=
"Whether to randomly rotate observations relative to the tract Wcs" 47 fluxMag0 = lsst.pex.config.Field(
48 dtype=float, default=1E11, optional=
False,
49 doc=
"Flux at zero magnitude used to define Calibs." 51 fluxMag0Sigma = lsst.pex.config.Field(
52 dtype=float, default=100.0, optional=
False,
53 doc=
"Error on flux at zero magnitude used to define Calibs; used to add scatter as well." 55 expTime = lsst.pex.config.Field(
56 dtype=float, default=60.0, optional=
False,
57 doc=
"Exposure time set in generated Calibs (does not affect flux or noise level)" 59 psfImageSize = lsst.pex.config.Field(
60 dtype=int, default=21, optional=
False,
61 doc=
"Image width and height of generated Psfs." 63 psfMinSigma = lsst.pex.config.Field(
64 dtype=float, default=1.5, optional=
False,
65 doc=
"Minimum radius for generated Psfs." 67 psfMaxSigma = lsst.pex.config.Field(
68 dtype=float, default=3.0, optional=
False,
69 doc=
"Maximum radius for generated Psfs." 71 apCorrOrder = lsst.pex.config.Field(
72 dtype=int, default=1, optional=
False,
73 doc=
"Polynomial order for aperture correction fields" 75 seed = lsst.pex.config.Field(dtype=int, default=1, doc=
"Seed for numpy random number generator")
79 """Task to generate mock Exposure parameters (Wcs, Psf, Calib), intended for use as a subtask 83 - document "pa" in detail; angle of what to what? 84 - document the catalog parameter of the run method 87 ConfigClass = MockObservationConfig
90 lsst.pipe.base.Task.__init__(self, **kwds)
92 self.
ccdKey = self.
schema.addField(
"ccd", type=np.int32, doc=
"CCD number")
93 self.
visitKey = self.
schema.addField(
"visit", type=np.int32, doc=
"visit number")
95 self.
filterKey = self.
schema.addField(
"filter", type=str, doc=
"Bandpass filter name", size=16)
96 self.
rng = np.random.RandomState(self.config.seed)
98 def run(self, butler, n, tractInfo, camera, catalog=None):
99 """Driver that generates an ExposureCatalog of mock observations. 101 @param[in] butler: a data butler 102 @param[in] n: number of pointings 103 @param[in] camera: camera geometry (an lsst.afw.cameraGeom.Camera) 104 @param[in] catalog: catalog to which to add observations (an ExposureCatalog); 105 if None then a new catalog is created. 107 @todo figure out what `pa` is and use that knowledge to set `boresightRotAng` and `rotType` 112 if not catalog.getSchema().contains(self.
schema):
113 raise ValueError(
"Catalog schema does not match Task schema")
118 exposureTime = self.config.expTime,
120 boresightRaDec = position,
122 for detector
in camera:
124 record = catalog.addNew()
125 record.setI(self.
ccdKey, detector.getId())
129 record.setWcs(self.buildWcs(position, pa, detector)) 130 record.setCalib(calib) 131 record.setVisitInfo(visitInfo) 132 record.setPsf(self.buildPsf(detector)) 134 record.setBBox(detector.getBBox()) 135 detectorId = detector.getId() 136 obj = butler.get("ccdExposureId", visit=visit, ccd=detectorId, immediate=
True)
142 """Generate (celestial) positions and rotation angles that define field locations. 144 Default implementation draws random pointings that are uniform in the tract's image 147 @param[in] n: number of pointings 148 @param[in] tractInfo: skymap tract (a lsst.skymap.TractInfo) 149 @return a Python iterable over (coord, angle) pairs: 150 - coord is an object position (an lsst.afw.coord.Coord) 151 - angle is a position angle (???) (an lsst.afw.geom.Angle) 153 The default implementation returns an iterator (i.e. the function is a "generator"), 154 but derived-class overrides may return any iterable. 156 wcs = tractInfo.getWcs()
160 x = self.
rng.rand() * bbox.getWidth() + bbox.getMinX()
161 y = self.
rng.rand() * bbox.getHeight() + bbox.getMinY()
162 pa = 0.0 * lsst.afw.geom.radians
163 if self.config.doRotate:
164 pa = self.
rng.rand() * 2.0 * np.pi * lsst.afw.geom.radians
165 yield wcs.pixelToSky(x, y), pa
168 """Build a simple TAN Wcs with no distortion and exactly-aligned CCDs. 170 @param[in] position: object position on sky (an lsst.afw.coord.Coord) 171 @param[in] pa: position angle (an lsst.afw.geom.Angle) 172 @param[in] detector: detector information (an lsst.afw.cameraGeom.Detector) 175 pixelScale = (self.config.pixelScale * lsst.afw.geom.arcseconds).asDegrees()
179 crpix = detector.transform(fpCtr, PIXELS).getPoint()
185 """Build a simple Calib object with exposure time fixed by config, fluxMag0 drawn from 186 a Gaussian defined by config, and mid-time set to DateTime.now(). 190 self.
rng.randn() * self.config.fluxMag0Sigma + self.config.fluxMag0,
191 self.config.fluxMag0Sigma
196 """Build a simple Gaussian Psf with linearly-varying ellipticity and size. 198 The Psf pattern increases sigma_x linearly along the x direction, and sigma_y 199 linearly along the y direction. 201 @param[in] detector: detector information (an lsst.afw.cameraGeom.Detector) 202 @return a psf (an instance of lsst.meas.algorithms.KernelPsf) 204 bbox = detector.getBBox()
205 dx = (self.config.psfMaxSigma - self.config.psfMinSigma) / bbox.getWidth()
206 dy = (self.config.psfMaxSigma - self.config.psfMinSigma) / bbox.getHeight()
207 sigmaXFunc = lsst.afw.math.PolynomialFunction2D(1)
208 sigmaXFunc.setParameter(0, self.config.psfMinSigma - dx * bbox.getMinX() - dy * bbox.getMinY())
209 sigmaXFunc.setParameter(1, dx)
210 sigmaXFunc.setParameter(2, 0.0)
211 sigmaYFunc = lsst.afw.math.PolynomialFunction2D(1)
212 sigmaYFunc.setParameter(0, self.config.psfMinSigma)
213 sigmaYFunc.setParameter(1, 0.0)
214 sigmaYFunc.setParameter(2, dy)
215 angleFunc = lsst.afw.math.PolynomialFunction2D(0)
217 spatialFuncList.append(sigmaXFunc)
218 spatialFuncList.append(sigmaYFunc)
219 spatialFuncList.append(angleFunc)
221 self.config.psfImageSize, self.config.psfImageSize,
222 lsst.afw.math.GaussianFunction2D(self.config.psfMinSigma, self.config.psfMinSigma),
228 """Build an ApCorrMap with random linearly-varying fields for all 229 flux fields registered for aperture correction. 231 These flux field names are used only as strings; there is no 232 connection to any actual algorithms with those names or the PSF model. 234 order = self.config.apCorrOrder
236 def makeRandomBoundedField():
237 """Make an upper-left triangular coefficient array appropriate 238 for a 2-d polynomial.""" 239 array = np.zeros((order + 1, order + 1), dtype=float)
240 for n
in range(order + 1):
241 array[n, 0:order + 1 - n] = self.
rng.randn(order + 1 - n)
244 bbox = detector.getBBox()
246 for name
in getApCorrNameSet():
247 apCorrMap.set(name +
"_flux", makeRandomBoundedField())
248 apCorrMap.set(name +
"_fluxSigma", makeRandomBoundedField())
std::shared_ptr< Wcs > makeWcs(coord::Coord const &crval, geom::Point2D const &crpix, double CD11, double CD12, double CD21, double CD22)
static Schema makeMinimalSchema()
static CoordKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
def buildApCorrMap(self, detector)
def buildPsf(self, detector)
static DateTime now(void)
def run(self, butler, n, tractInfo, camera, catalog=None)
def makePointings(self, n, tractInfo)
def buildWcs(self, position, pa, detector)