21 """Functions to help create jointcal tests by generating fake data.""" 23 __all__ = [
'createFakeCatalog',
'createTwoFakeCcdImages',
'getMeasuredStarsFromCatalog']
33 import lsst.jointcal.star
37 photoCalibMean1=1e-2, photoCalibMean2=1.2e-2):
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. 53 fakeCcdId : `int`, optional 54 Sensor identifier to use for both CcdImages. The wcs, bbox, calib, etc. 55 will still be drawn from the CFHT ccd=12 files, as that is the only 56 testdata that is included in this simple test dataset. 57 photoCalibMean1, photoCalibMean2: `float`, optional 58 The mean photometric calibration to pass to each ccdImage construction. 59 Note: this value is 1/instFluxMag0, so it should be less than 1. 63 struct : `lsst.pipe.base.Struct` 64 Result struct with components: 66 - `camera` : Camera representing these catalogs 67 (`lsst.afw.cameraGeom.Camera`). 68 - `catalogs` : Catalogs containing fake sources 69 (`list` of `lsst.afw.table.SourceCatalog`). 70 - `ccdImageList` : CcdImages containing the metadata and fake sources 71 (`list` of `lsst.jointcal.CcdImage`). 72 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 73 - 'fluxFieldName' : name of the instFlux field in the catalogs ('str'). 79 fluxFieldName =
"SomeFlux" 83 inputDir = os.path.join(dataDir,
'tests/data/cfht_minimal')
84 butler = lsst.daf.persistence.Butler(inputDir)
87 camera = butler.get(
'camera', visit=visit1)
90 photoCalibMean=photoCalibMean1, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
92 photoCalibMean=photoCalibMean2, photoCalibErr=5.0, fakeCcdId=fakeCcdId)
94 return lsst.pipe.base.Struct(camera=camera,
95 catalogs=[struct1.catalog, struct2.catalog],
96 ccdImageList=[struct1.ccdImage, struct2.ccdImage],
98 fluxFieldName=fluxFieldName)
102 photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12):
103 """Create a fake CcdImage by making a fake catalog. 107 butler : `lsst.daf.persistence.Butler` 108 Butler to load metadata from. 110 Visit identifier to build a butler dataId. 112 Number of sources to put in the catalogs. Should be 113 a square, to have sqrt(num) centroids on a grid. 114 fluxFieldName : `str` 115 Name of the flux field to populate in the catalog, without `_instFlux` 116 (e.g. "slot_CalibFlux"). 117 photoCalibMean : `float`, optional 118 Value to set for calibrationMean in the created PhotoCalib. 119 Note: this value is 1/instFluxMag0, so it should be less than 1. 120 photoCalibErr : `float`, optional 121 Value to set for calibrationErr in the created PhotoCalib. 122 fakeCcdId : `int`, optional 123 Use this as the ccdId in the returned CcdImage. 127 struct : `lsst.pipe.base.Struct` 128 Result struct with components: 130 - `catalog` : Catalogs containing fake sources 131 (`lsst.afw.table.SourceCatalog`). 132 - `ccdImage` : CcdImage containing the metadata and fake sources 133 (`lsst.jointcal.CcdImage`). 134 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 138 dataId = dict(visit=visit, ccd=ccdId)
139 skyWcs = butler.get(
'calexp_wcs', dataId=dataId)
140 visitInfo = butler.get(
'calexp_visitInfo', dataId=dataId)
141 bbox = butler.get(
'calexp_bbox', dataId=dataId)
142 detector = butler.get(
'calexp_detector', dataId=dataId)
143 filt = butler.get(
"calexp_filter", dataId=dataId).getName()
147 ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
148 detector, visit, fakeCcdId, fluxFieldName)
150 return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)
154 """Return a fake minimally-useful catalog for jointcal. 159 Number of sources to put in the catalogs. Should be 160 a square, to have sqrt(num) centroids on a grid. 161 bbox : `lsst.afw.geom.Box2I` 162 Bounding Box of the detector to populate. 163 fluxFieldName : `str` 164 Name of the flux field to populate in the catalog, without `_instFlux` 165 (e.g. "slot_CalibFlux"). 166 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 167 If supplied, use this to fill in coordinates from centroids. 168 refCat : `bool`, optional 169 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 173 catalog : `lsst.afw.table.SourceCatalog` 174 A populated source catalog. 178 centroidKey = lsst.afw.table.Point2DKey.addFields(schema,
"centroid",
"centroid",
"pixels")
179 xErrKey = schema.addField(
"centroid_xErr", type=
"F")
180 yErrKey = schema.addField(
"centroid_yErr", type=
"F")
183 lsst.afw.table.CoordinateType.PIXEL)
185 schema.addField(fluxFieldName+
"_instFlux", type=
"D", doc=
"post-ISR instFlux")
186 schema.addField(fluxFieldName+
"_instFluxErr", type=
"D", doc=
"post-ISR instFlux stddev")
187 schema.addField(fluxFieldName+
"_flux", type=
"D", doc=
"maggies")
188 schema.addField(fluxFieldName+
"_fluxErr", type=
"D", doc=
"maggies stddev")
189 schema.addField(fluxFieldName+
"_mag", type=
"D", doc=
"magnitude")
190 schema.addField(fluxFieldName+
"_magErr", type=
"D", doc=
"magnitude stddev")
192 centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
193 skyWcs=skyWcs, refCat=refCat)
197 centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
198 skyWcs=None, fluxErrFraction=0.05, refCat=False):
199 """Return a catalog populated with fake, but reasonable, sources. 201 Centroids are placed on a uniform grid, errors are normally distributed. 205 schema : `lsst.afw.table.Schema` 206 Pre-built schema to make the catalog from. 208 Number of sources to put in the catalog. 209 bbox : `lsst.afw.geom.Box2I` 210 Bounding box of the ccd to put sources in. 211 centroidKey : `lsst.afw.table.Key` 212 Key for the centroid field to populate. 213 xErrKey : `lsst.afw.table.Key` 214 Key for the xErr field to populate. 215 yErrKey : `lsst.afw.table.Key` 216 Key for the yErr field to populate. 217 shapeKey : `lsst.afw.table.Key` 218 Key for the shape field to populate. 219 fluxFieldName : `str` 220 Name of the flux field to populate in the catalog, without `_instFlux` 221 (e.g. "slot_CalibFlux"). 222 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 223 If supplied, use this to fill in coordinates from centroids. 224 fluxErrFraction : `float`, optional 225 Fraction of instFlux to use for the instFluxErr. 226 refCat : `bool`, optional 227 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 231 catalog : `lsst.afw.table.SourceCatalog` 235 table.defineCentroid(
'centroid')
236 table.defineShape(
'shape')
237 table.defineCalibFlux(fluxFieldName)
243 instFlux = np.random.random(num)*10000
244 instFluxErr = np.abs(instFlux * np.random.normal(fluxErrFraction, scale=0.1, size=num))
245 xx = np.linspace(bbox.getMinX(), bbox.getMaxX(), int(np.sqrt(num)))
246 yy = np.linspace(bbox.getMinY(), bbox.getMaxY(), int(np.sqrt(num)))
247 xv, yv = np.meshgrid(xx, yy)
248 vx = np.random.normal(scale=0.1, size=num)
249 vy = np.random.normal(scale=0.1, size=num)
256 for i, (x, y)
in enumerate(zip(xv.ravel(), yv.ravel())):
257 record = catalog.addNew()
259 record.set(centroidKey, lsst.afw.geom.Point2D(x, y))
262 if skyWcs
is not None:
265 catalog[xErrKey] = vx
266 catalog[yErrKey] = vy
267 catalog[fluxFieldName +
'_instFlux'] = instFlux
268 catalog[fluxFieldName +
'_instFluxErr'] = instFluxErr
274 """Return a list of measuredStars built from a catalog. 278 catalog : `lsst.afw.table.SourceCatalog` 279 The table to get sources from. 280 pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2` 281 Transform that goes from pixel to focal plane coordinates, to set the 282 MeasuredStar x/y focal points. 286 stars : `list` of `lsst.jointcal.MeasuredStar` 287 MeasuredStars built from the catalog sources. 290 for record
in catalog:
291 star = lsst.jointcal.star.MeasuredStar()
292 star.x = record.getX()
293 star.y = record.getY()
294 star.setInstFluxAndErr(record.getCalibInstFlux(), record.getCalibInstFluxErr())
296 point = lsst.afw.geom.Point2D(star.x, star.y)
297 pointFocal = pixToFocal.applyForward(point)
298 star.setXFocal(pointFocal.getX())
299 star.setYFocal(pointFocal.getY())
def createFakeCcdImage(butler, visit, num, fluxFieldName, photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12)
def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12, photoCalibMean1=1e-2, photoCalibMean2=1.2e-2)
def createFakeCatalog(num, bbox, fluxFieldName, skyWcs=None, refCat=False)
void updateSourceCoords(geom::SkyWcs const &wcs, SourceCollection &sourceList)
std::string getPackageDir(std::string const &packageName)
def fillCatalog(schema, num, bbox, centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName, skyWcs=None, fluxErrFraction=0.05, refCat=False)
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)