21 """Functions to help create jointcal tests by generating fake data.""" 23 __all__ = [
'createFakeCatalog',
'createTwoFakeCcdImages',
'getMeasuredStarsFromCatalog']
31 import lsst.obs.lsstSim
34 import lsst.jointcal.star
38 """Return two fake ccdImages built on CFHT Megacam metadata. 40 If ``num1 == num2``, the catalogs will align on-sky so each source will 41 have a match in the other catalog. 43 This uses the butler dataset stored in `tests/data/cfht_minimal` to 44 bootstrap the metadata. 48 num1, num2 : `int`, optional 49 Number of sources to put in the first and second catalogs. Should be 50 a square, to have sqrt(num) centroids on a grid. 51 seed : `int`, optional 52 Seed value for np.random. 56 struct : `lsst.pipe.base.Struct` 57 Result struct with components: 59 - `camera` : Camera representing these catalogs 60 (`lsst.afw.cameraGeom.Camera`). 61 - `catalogs` : Catalogs containing fake sources 62 (`list` of `lsst.afw.table.SourceCatalog`). 63 - `ccdImageList` : CcdImages containing the metadata and fake sources 64 (`list` of `lsst.jointcal.CcdImage`). 65 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 72 instFluxKeyName =
"SomeFlux" 76 inputDir = os.path.join(dataDir,
'tests/data/cfht_minimal')
77 butler = lsst.daf.persistence.Butler(inputDir)
80 camera = butler.get(
'camera', visit=visit1, ccd=ccdId)
83 photoCalibMean=100.0, photoCalibErr=1.0)
85 photoCalibMean=120.0, photoCalibErr=5.0)
87 return lsst.pipe.base.Struct(camera=camera,
88 catalogs=[struct1.catalog, struct2.catalog],
89 ccdImageList=[struct1.ccdImage, struct2.ccdImage],
94 photoCalibMean=100.0, photoCalibErr=1.0):
95 """Create a fake CcdImage by making a fake catalog. 99 butler : `lsst.daf.persistence.Butler` 100 Butler to load metadata from. 102 Visit identifier to build a butler dataId. 104 CCD identifier to build a butler dataId. 106 Number of sources to put in the catalogs. Should be 107 a square, to have sqrt(num) centroids on a grid. 108 instFluxKeyName : `str` 109 Name of the instFluxKey to populate in the catalog. 110 photoCalibMean : `float`, optional 111 Value to set for calibrationMean in the created PhotoCalib. 112 photoCalibErr : `float`, optional 113 Value to set for calibrationErr in the created PhotoCalib. 117 struct : `lsst.pipe.base.Struct` 118 Result struct with components: 120 - `catalog` : Catalogs containing fake sources 121 (`lsst.afw.table.SourceCatalog`). 122 - `ccdImage` : CcdImage containing the metadata and fake sources 123 (`lsst.jointcal.CcdImage`). 124 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 126 dataId = dict(visit=visit, ccd=ccdId)
127 skyWcs = butler.get(
'calexp_wcs', dataId=dataId)
128 visitInfo = butler.get(
'calexp_visitInfo', dataId=dataId)
129 bbox = butler.get(
'calexp_bbox', dataId=dataId)
130 detector = butler.get(
'calexp_detector', dataId=dataId)
131 filt = butler.get(
"calexp_filter", dataId=dataId).getName()
135 ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
136 detector, visit, ccdId, instFluxKeyName)
138 return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)
142 """Return a fake minimally-useful catalog for jointcal. 147 Number of sources to put in the catalogs. Should be 148 a square, to have sqrt(num) centroids on a grid. 149 bbox : `lsst.afw.geom.Box2I` 150 Bounding Box of the detector to populate. 151 instFluxKeyName : `str` 152 Name of the instFluxKey to populate in the catalog. 153 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 154 If supplied, use this to fill in coordinates from centroids. 155 refCat : `bool`, optional 156 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 160 catalog : `lsst.afw.table.SourceCatalog` 161 A populated source catalog. 165 centroidKey = lsst.afw.table.Point2DKey.addFields(schema,
"centroid",
"centroid",
"pixels")
166 xErrKey = schema.addField(
"centroid_xSigma", type=
"F")
167 yErrKey = schema.addField(
"centroid_ySigma", type=
"F")
170 lsst.afw.table.CoordinateType.PIXEL)
172 schema.addField(instFluxKeyName+
"_flux", type=
"D", doc=
"post-ISR instFlux")
173 schema.addField(instFluxKeyName+
"_fluxSigma", type=
"D", doc=
"post-ISR instFlux stddev")
174 schema.addField(instFluxKeyName+
"_calFlux", type=
"D", doc=
"maggies")
175 schema.addField(instFluxKeyName+
"_calFluxErr", type=
"D", doc=
"maggies stddev")
176 schema.addField(instFluxKeyName+
"_mag", type=
"D", doc=
"magnitude")
177 schema.addField(instFluxKeyName+
"_magErr", type=
"D", doc=
"magnitude stddev")
179 centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
180 skyWcs=skyWcs, refCat=refCat)
184 centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
185 skyWcs=None, fluxErrFraction=0.05, refCat=False):
186 """Return a catalog populated with fake, but reasonable, sources. 188 Centroids are placed on a uniform grid, errors are normally distributed. 192 schema : `lsst.afw.table.Schema` 193 Pre-built schema to make the catalog from. 195 Number of sources to put in the catalog. 196 bbox : `lsst.afw.geom.Box2I` 197 Bounding box of the ccd to put sources in. 198 centroidKey : `lsst.afw.table.Key` 199 Key for the centroid field to populate. 200 xErrKey : `lsst.afw.table.Key` 201 Key for the xErr field to populate. 202 yErrKey : `lsst.afw.table.Key` 203 Key for the yErr field to populate. 204 shapeKey : `lsst.afw.table.Key` 205 Key for the shape field to populate. 206 instFluxKeyName : `str` 207 Name of instFlux field to populate (i.e. instFluxKeyName+'_flux') 208 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 209 If supplied, use this to fill in coordinates from centroids. 210 fluxErrFraction : `float`, optional 211 Fraction of instFlux to use for the instFluxErr. 212 refCat : `bool`, optional 213 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 217 catalog : `lsst.afw.table.SourceCatalog` 221 table.defineCentroid(
'centroid')
222 table.defineShape(
'shape')
223 table.defineInstFlux(instFluxKeyName)
229 instFlux = np.random.random(num)
230 instFluxErr = instFlux * fluxErrFraction
231 xx = np.linspace(bbox.getMinX(), bbox.getMaxX(), int(np.sqrt(num)))
232 yy = np.linspace(bbox.getMinY(), bbox.getMaxY(), int(np.sqrt(num)))
233 xv, yv = np.meshgrid(xx, yy)
234 vx = np.random.normal(scale=0.1, size=num)
235 vy = np.random.normal(scale=0.1, size=num)
242 for i, (x, y)
in enumerate(zip(xv.ravel(), yv.ravel())):
243 record = catalog.addNew()
245 record.set(centroidKey, lsst.afw.geom.Point2D(x, y))
248 if skyWcs
is not None:
251 catalog[xErrKey] = vx
252 catalog[yErrKey] = vy
253 catalog[instFluxKeyName +
'_flux'] = instFlux
254 catalog[instFluxKeyName +
'_fluxSigma'] = instFluxErr
260 """Return a list of measuredStars built from a catalog. 264 catalog : `lsst.afw.table.SourceCatalog` 265 The table to get sources from. 266 pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2` 267 Transform that goes from pixel to focal plane coordinates, to set the 268 MeasuredStar x/y focal points. 272 stars : `list` of `lsst.jointcal.MeasuredStar` 273 MeasuredStars built from the catalog sources. 276 for record
in catalog:
277 star = lsst.jointcal.star.MeasuredStar()
278 star.x = record.getX()
279 star.y = record.getY()
280 star.setInstFlux(record.getInstFlux())
281 star.setInstFluxErr(record.getInstFluxErr())
283 point = lsst.afw.geom.Point2D(star.x, star.y)
284 pointFocal = pixToFocal.applyForward(point)
285 star.setXFocal(pointFocal.getX())
286 star.setYFocal(pointFocal.getY())
def createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=None, refCat=False)
def createFakeCcdImage(butler, visit, ccdId, num, instFluxKeyName, photoCalibMean=100.0, photoCalibErr=1.0)
def fillCatalog(schema, num, bbox, centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName, skyWcs=None, fluxErrFraction=0.05, refCat=False)
void updateSourceCoords(geom::SkyWcs const &wcs, SourceCollection &sourceList)
std::string getPackageDir(std::string const &packageName)
static QuadrupoleKey addFields(Schema &schema, std::string const &name, std::string const &doc, CoordinateType coordType=CoordinateType::PIXEL)
static Schema makeMinimalSchema()
static std::shared_ptr< SourceTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
def getMeasuredStarsFromCatalog(catalog, pixToFocal)
def createTwoFakeCcdImages(num1=4, num2=4, seed=100)