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. 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. 60 struct : `lsst.pipe.base.Struct` 61 Result struct with components: 63 - `camera` : Camera representing these catalogs 64 (`lsst.afw.cameraGeom.Camera`). 65 - `catalogs` : Catalogs containing fake sources 66 (`list` of `lsst.afw.table.SourceCatalog`). 67 - `ccdImageList` : CcdImages containing the metadata and fake sources 68 (`list` of `lsst.jointcal.CcdImage`). 69 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 70 - 'instFluxKeyName' : name of the instFlux field in the catalogs ('str'). 76 instFluxKeyName =
"SomeFlux" 80 inputDir = os.path.join(dataDir,
'tests/data/cfht_minimal')
81 butler = lsst.daf.persistence.Butler(inputDir)
84 camera = butler.get(
'camera', visit=visit1)
87 photoCalibMean=100.0, photoCalibErr=1.0, fakeCcdId=fakeCcdId)
89 photoCalibMean=120.0, photoCalibErr=5.0, fakeCcdId=fakeCcdId)
91 return lsst.pipe.base.Struct(camera=camera,
92 catalogs=[struct1.catalog, struct2.catalog],
93 ccdImageList=[struct1.ccdImage, struct2.ccdImage],
95 instFluxKeyName=instFluxKeyName)
99 photoCalibMean=100.0, photoCalibErr=1.0, fakeCcdId=12):
100 """Create a fake CcdImage by making a fake catalog. 104 butler : `lsst.daf.persistence.Butler` 105 Butler to load metadata from. 107 Visit identifier to build a butler dataId. 109 Number of sources to put in the catalogs. Should be 110 a square, to have sqrt(num) centroids on a grid. 111 instFluxKeyName : `str` 112 Name of the instFluxKey to populate in the catalog. 113 photoCalibMean : `float`, optional 114 Value to set for calibrationMean in the created PhotoCalib. 115 photoCalibErr : `float`, optional 116 Value to set for calibrationErr in the created PhotoCalib. 117 fakeCcdId : `int`, optional 118 Use this as the ccdId in the returned CcdImage. 122 struct : `lsst.pipe.base.Struct` 123 Result struct with components: 125 - `catalog` : Catalogs containing fake sources 126 (`lsst.afw.table.SourceCatalog`). 127 - `ccdImage` : CcdImage containing the metadata and fake sources 128 (`lsst.jointcal.CcdImage`). 129 - `bbox` : Bounding Box of the image (`lsst.afw.geom.Box2I`). 133 dataId = dict(visit=visit, ccd=ccdId)
134 skyWcs = butler.get(
'calexp_wcs', dataId=dataId)
135 visitInfo = butler.get(
'calexp_visitInfo', dataId=dataId)
136 bbox = butler.get(
'calexp_bbox', dataId=dataId)
137 detector = butler.get(
'calexp_detector', dataId=dataId)
138 filt = butler.get(
"calexp_filter", dataId=dataId).getName()
142 ccdImage = lsst.jointcal.ccdImage.CcdImage(catalog, skyWcs, visitInfo, bbox, filt, photoCalib,
143 detector, visit, fakeCcdId, instFluxKeyName)
145 return lsst.pipe.base.Struct(catalog=catalog, ccdImage=ccdImage, bbox=bbox)
149 """Return a fake minimally-useful catalog for jointcal. 154 Number of sources to put in the catalogs. Should be 155 a square, to have sqrt(num) centroids on a grid. 156 bbox : `lsst.afw.geom.Box2I` 157 Bounding Box of the detector to populate. 158 instFluxKeyName : `str` 159 Name of the instFluxKey to populate in the catalog. 160 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 161 If supplied, use this to fill in coordinates from centroids. 162 refCat : `bool`, optional 163 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 167 catalog : `lsst.afw.table.SourceCatalog` 168 A populated source catalog. 172 centroidKey = lsst.afw.table.Point2DKey.addFields(schema,
"centroid",
"centroid",
"pixels")
173 xErrKey = schema.addField(
"centroid_xSigma", type=
"F")
174 yErrKey = schema.addField(
"centroid_ySigma", type=
"F")
177 lsst.afw.table.CoordinateType.PIXEL)
179 schema.addField(instFluxKeyName+
"_flux", type=
"D", doc=
"post-ISR instFlux")
180 schema.addField(instFluxKeyName+
"_fluxSigma", type=
"D", doc=
"post-ISR instFlux stddev")
181 schema.addField(instFluxKeyName+
"_calFlux", type=
"D", doc=
"maggies")
182 schema.addField(instFluxKeyName+
"_calFluxErr", type=
"D", doc=
"maggies stddev")
183 schema.addField(instFluxKeyName+
"_mag", type=
"D", doc=
"magnitude")
184 schema.addField(instFluxKeyName+
"_magErr", type=
"D", doc=
"magnitude stddev")
186 centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
187 skyWcs=skyWcs, refCat=refCat)
191 centroidKey, xErrKey, yErrKey, shapeKey, instFluxKeyName,
192 skyWcs=None, fluxErrFraction=0.05, refCat=False):
193 """Return a catalog populated with fake, but reasonable, sources. 195 Centroids are placed on a uniform grid, errors are normally distributed. 199 schema : `lsst.afw.table.Schema` 200 Pre-built schema to make the catalog from. 202 Number of sources to put in the catalog. 203 bbox : `lsst.afw.geom.Box2I` 204 Bounding box of the ccd to put sources in. 205 centroidKey : `lsst.afw.table.Key` 206 Key for the centroid field to populate. 207 xErrKey : `lsst.afw.table.Key` 208 Key for the xErr field to populate. 209 yErrKey : `lsst.afw.table.Key` 210 Key for the yErr field to populate. 211 shapeKey : `lsst.afw.table.Key` 212 Key for the shape field to populate. 213 instFluxKeyName : `str` 214 Name of instFlux field to populate (i.e. instFluxKeyName+'_flux') 215 skyWcs : `lsst.afw.geom.SkyWcs` or None, optional 216 If supplied, use this to fill in coordinates from centroids. 217 fluxErrFraction : `float`, optional 218 Fraction of instFlux to use for the instFluxErr. 219 refCat : `bool`, optional 220 Return a ``SimpleCatalog`` so that it behaves like a reference catalog? 224 catalog : `lsst.afw.table.SourceCatalog` 228 table.defineCentroid(
'centroid')
229 table.defineShape(
'shape')
230 table.defineInstFlux(instFluxKeyName)
236 instFlux = np.random.random(num)*10000
237 instFluxErr = np.abs(instFlux * np.random.normal(fluxErrFraction, scale=0.1, size=num))
238 xx = np.linspace(bbox.getMinX(), bbox.getMaxX(), int(np.sqrt(num)))
239 yy = np.linspace(bbox.getMinY(), bbox.getMaxY(), int(np.sqrt(num)))
240 xv, yv = np.meshgrid(xx, yy)
241 vx = np.random.normal(scale=0.1, size=num)
242 vy = np.random.normal(scale=0.1, size=num)
249 for i, (x, y)
in enumerate(zip(xv.ravel(), yv.ravel())):
250 record = catalog.addNew()
252 record.set(centroidKey, lsst.afw.geom.Point2D(x, y))
255 if skyWcs
is not None:
258 catalog[xErrKey] = vx
259 catalog[yErrKey] = vy
260 catalog[instFluxKeyName +
'_flux'] = instFlux
261 catalog[instFluxKeyName +
'_fluxSigma'] = instFluxErr
267 """Return a list of measuredStars built from a catalog. 271 catalog : `lsst.afw.table.SourceCatalog` 272 The table to get sources from. 273 pixToFocal : `lsst.afw.geom.TransformPoint2ToPoint2` 274 Transform that goes from pixel to focal plane coordinates, to set the 275 MeasuredStar x/y focal points. 279 stars : `list` of `lsst.jointcal.MeasuredStar` 280 MeasuredStars built from the catalog sources. 283 for record
in catalog:
284 star = lsst.jointcal.star.MeasuredStar()
285 star.x = record.getX()
286 star.y = record.getY()
287 star.setInstFluxAndErr(record.getInstFlux(), record.getInstFluxErr())
289 point = lsst.afw.geom.Point2D(star.x, star.y)
290 pointFocal = pixToFocal.applyForward(point)
291 star.setXFocal(pointFocal.getX())
292 star.setYFocal(pointFocal.getY())
def createFakeCatalog(num, bbox, instFluxKeyName, skyWcs=None, refCat=False)
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)
def createTwoFakeCcdImages(num1=4, num2=4, seed=100, fakeCcdId=12)
static Schema makeMinimalSchema()
static std::shared_ptr< SourceTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
def getMeasuredStarsFromCatalog(catalog, pixToFocal)
def createFakeCcdImage(butler, visit, num, instFluxKeyName, photoCalibMean=100.0, photoCalibErr=1.0, fakeCcdId=12)