22 """Functions to help create jointcal tests by generating fake data.""" 24 __all__ = [
'createFakeCatalog',
'createTwoFakeCcdImages',
'getMeasuredStarsFromCatalog']
34 import lsst.jointcal.star
38 photoCalibMean1=1e-2, photoCalibMean2=1.2e-2):
39 """Return two fake ccdImages built on CFHT Megacam metadata. 41 If ``num1 == num2``, the catalogs will align on-sky so each source will 42 have a match in the other catalog. 44 This uses the butler dataset stored in `tests/data/cfht_minimal` to 45 bootstrap the metadata. 49 num1, num2 : `int`, optional 50 Number of sources to put in the first and second catalogs. Should be 51 a square, to have sqrt(num) centroids on a grid. 52 seed : `int`, optional 53 Seed value for np.random. 54 fakeCcdId : `int`, optional 55 Sensor identifier to use for both CcdImages. The wcs, bbox, calib, etc. 56 will still be drawn from the CFHT ccd=12 files, as that is the only 57 testdata that is included in this simple test dataset. 58 photoCalibMean1, photoCalibMean2: `float`, optional 59 The mean photometric calibration to pass to each ccdImage construction. 60 Note: this value is 1/instFluxMag0, so it should be less than 1. 64 struct : `lsst.pipe.base.Struct` 65 Result struct with components: 67 - `camera` : Camera representing these catalogs 68 (`lsst.afw.cameraGeom.Camera`). 69 - `catalogs` : Catalogs containing fake sources 70 (`list` of `lsst.afw.table.SourceCatalog`). 71 - `ccdImageList` : CcdImages containing the metadata and fake sources 72 (`list` of `lsst.jointcal.CcdImage`). 73 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 74 - 'fluxFieldName' : name of the instFlux field in the catalogs ('str'). 80 fluxFieldName =
"SomeFlux" 84 inputDir = os.path.join(dataDir,
'tests/data/cfht_minimal')
85 butler = lsst.daf.persistence.Butler(inputDir)
88 camera = butler.get(
'camera', visit=visit1)
91 photoCalibMean=photoCalibMean1, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
93 photoCalibMean=photoCalibMean2, photoCalibErr=5.0, fakeCcdId=fakeCcdId)
95 return lsst.pipe.base.Struct(camera=camera,
96 catalogs=[struct1.catalog, struct2.catalog],
97 ccdImageList=[struct1.ccdImage, struct2.ccdImage],
99 fluxFieldName=fluxFieldName)
103 photoCalibMean=1e-2, photoCalibErr=1.0, fakeCcdId=12):
104 """Create a fake CcdImage by making a fake catalog. 108 butler : `lsst.daf.persistence.Butler` 109 Butler to load metadata from. 111 Visit identifier to build a butler dataId. 113 Number of sources to put in the catalogs. Should be 114 a square, to have sqrt(num) centroids on a grid. 115 fluxFieldName : `str` 116 Name of the flux field to populate in the catalog, without `_instFlux` 117 (e.g. "slot_CalibFlux"). 118 photoCalibMean : `float`, optional 119 Value to set for calibrationMean in the created PhotoCalib. 120 Note: this value is 1/instFluxMag0, so it should be less than 1. 121 photoCalibErr : `float`, optional 122 Value to set for calibrationErr in the created PhotoCalib. 123 fakeCcdId : `int`, optional 124 Use this as the ccdId in the returned CcdImage. 128 struct : `lsst.pipe.base.Struct` 129 Result struct with components: 131 - `catalog` : Catalogs containing fake sources 132 (`lsst.afw.table.SourceCatalog`). 133 - `ccdImage` : CcdImage containing the metadata and fake sources 134 (`lsst.jointcal.CcdImage`). 135 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 139 dataId = dict(visit=visit, ccd=ccdId)
140 skyWcs = butler.get(
'calexp_wcs', dataId=dataId)
141 visitInfo = butler.get(
'calexp_visitInfo', dataId=dataId)
142 bbox = butler.get(
'calexp_bbox', dataId=dataId)
143 detector = butler.get(
'calexp_detector', dataId=dataId)
144 filt = butler.get(
"calexp_filter", dataId=dataId).getName()
148 ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
149 detector, visit, fakeCcdId, fluxFieldName)
151 return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)
155 """Return a fake minimally-useful catalog for jointcal. 160 Number of sources to put in the catalogs. Should be 161 a square, to have sqrt(num) centroids on a grid. 162 bbox : `lsst.afw.geom.Box2I` 163 Bounding Box of the detector to populate. 164 fluxFieldName : `str` 165 Name of the flux field to populate in the catalog, without `_instFlux` 166 (e.g. "slot_CalibFlux"). 167 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 168 If supplied, use this to fill in coordinates from centroids. 169 refCat : `bool`, optional 170 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 174 catalog : `lsst.afw.table.SourceCatalog` 175 A populated source catalog. 179 centroidKey = lsst.afw.table.Point2DKey.addFields(schema,
"centroid",
"centroid",
"pixels")
180 xErrKey = schema.addField(
"centroid_xErr", type=
"F")
181 yErrKey = schema.addField(
"centroid_yErr", type=
"F")
184 lsst.afw.table.CoordinateType.PIXEL)
186 schema.addField(fluxFieldName+
"_instFlux", type=
"D", doc=
"post-ISR instFlux")
187 schema.addField(fluxFieldName+
"_instFluxErr", type=
"D", doc=
"post-ISR instFlux stddev")
188 schema.addField(fluxFieldName+
"_flux", type=
"D", doc=
"maggies")
189 schema.addField(fluxFieldName+
"_fluxErr", type=
"D", doc=
"maggies stddev")
190 schema.addField(fluxFieldName+
"_mag", type=
"D", doc=
"magnitude")
191 schema.addField(fluxFieldName+
"_magErr", type=
"D", doc=
"magnitude stddev")
193 centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
194 skyWcs=skyWcs, refCat=refCat)
198 centroidKey, xErrKey, yErrKey, shapeKey, fluxFieldName,
199 skyWcs=None, fluxErrFraction=0.05, refCat=False):
200 """Return a catalog populated with fake, but reasonable, sources. 202 Centroids are placed on a uniform grid, errors are normally distributed. 206 schema : `lsst.afw.table.Schema` 207 Pre-built schema to make the catalog from. 209 Number of sources to put in the catalog. 210 bbox : `lsst.afw.geom.Box2I` 211 Bounding box of the ccd to put sources in. 212 centroidKey : `lsst.afw.table.Key` 213 Key for the centroid field to populate. 214 xErrKey : `lsst.afw.table.Key` 215 Key for the xErr field to populate. 216 yErrKey : `lsst.afw.table.Key` 217 Key for the yErr field to populate. 218 shapeKey : `lsst.afw.table.Key` 219 Key for the shape field to populate. 220 fluxFieldName : `str` 221 Name of the flux field to populate in the catalog, without `_instFlux` 222 (e.g. "slot_CalibFlux"). 223 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 224 If supplied, use this to fill in coordinates from centroids. 225 fluxErrFraction : `float`, optional 226 Fraction of instFlux to use for the instFluxErr. 227 refCat : `bool`, optional 228 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 232 catalog : `lsst.afw.table.SourceCatalog` 236 table.defineCentroid(
'centroid')
237 table.defineShape(
'shape')
238 table.defineCalibFlux(fluxFieldName)
244 instFlux = np.random.random(num)*10000
245 instFluxErr = np.abs(instFlux * np.random.normal(fluxErrFraction, scale=0.1, size=num))
246 xx = np.linspace(bbox.getMinX(), bbox.getMaxX(), int(np.sqrt(num)))
247 yy = np.linspace(bbox.getMinY(), bbox.getMaxY(), int(np.sqrt(num)))
248 xv, yv = np.meshgrid(xx, yy)
249 vx = np.random.normal(scale=0.1, size=num)
250 vy = np.random.normal(scale=0.1, size=num)
257 for i, (x, y)
in enumerate(zip(xv.ravel(), yv.ravel())):
258 record = catalog.addNew()
260 record.set(centroidKey, lsst.afw.geom.Point2D(x, y))
263 if skyWcs
is not None:
266 catalog[xErrKey] = vx
267 catalog[yErrKey] = vy
268 catalog[fluxFieldName +
'_instFlux'] = instFlux
269 catalog[fluxFieldName +
'_instFluxErr'] = instFluxErr
275 """Return a list of measuredStars built from a catalog. 279 catalog : `lsst.afw.table.SourceCatalog` 280 The table to get sources from. 281 pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2` 282 Transform that goes from pixel to focal plane coordinates, to set the 283 MeasuredStar x/y focal points. 287 stars : `list` of `lsst.jointcal.MeasuredStar` 288 MeasuredStars built from the catalog sources. 291 for record
in catalog:
292 star = lsst.jointcal.star.MeasuredStar()
293 star.x = record.getX()
294 star.y = record.getY()
295 star.setInstFluxAndErr(record.getCalibInstFlux(), record.getCalibInstFluxErr())
297 point = lsst.afw.geom.Point2D(star.x, star.y)
298 pointFocal = pixToFocal.applyForward(point)
299 star.setXFocal(pointFocal.getX())
300 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)