def testInputInvariance(self): pl = headerToPropertyList(self.header) afwImage.makeWcs(pl) for key, value in self.header.items(): self.assertEqual( value, pl.get(key), "%s not invariant: %s vs %s" % (key, value, pl.get(key)))
def testSimpleGaussian(self): """Check that we can measure a single Gaussian's attributes""" print "SimpleGaussianTest" sigma0 = 5 # set the peak of the outer guassian to 0 so this is really a single gaussian. psf = measAlg.DoubleGaussianPsf(60, 60, 1.5*sigma0, 1, 0.0) # this is the coadd Wcs we want cd11 = 5.55555555e-05 cd12 = 0.0 cd21 = 0.0 cd22 = 5.55555555e-05 crval1 = 0.0 crval2 = 0.0 crpix = afwGeom.PointD(1000, 1000) crval = afwCoord.Coord(afwGeom.Point2D(crval1, crval2)) wcsref = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("weight", type="D", doc="Coadd weight") mycatalog = afwTable.ExposureCatalog(schema) sigma = [5,6,7,8] # 5 pixels is the same as a sigma of 1 arcsec. # lay down a simple pattern of four ccds, set in a pattern of 1000 pixels around the center offsets = [(1999,1999), (1999,0), (0, 0), (0,1999)] # Imagine a ccd in each of positions +-1000 pixels from the center for i in range(4): record = mycatalog.getTable().makeRecord() psf = measAlg.DoubleGaussianPsf(100, 100, sigma[i], 1.00, 1.0) record.setPsf(psf) crpix = afwGeom.PointD(offsets[i][0], offsets[i][1]) wcs = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) # print out the coorinates of this supposed 2000x2000 ccd in wcsref coordinates beginCoord = wcs.pixelToSky(0,0) endCoord = wcs.pixelToSky(2000, 2000) wcsref.skyToPixel(beginCoord) wcsref.skyToPixel(endCoord) record.setWcs(wcs) record['weight'] = 1.0 record['id'] = i bbox = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(2000, 2000)) record.setBBox(bbox) mycatalog.append(record) #img = psf.computeImage(afwGeom.Point2D(1000,1000), afwGeom.Extent2I(100,100), False, False) #img.writeFits("img%d.fits"%i) mypsf = measAlg.CoaddPsf(mycatalog, wcsref) #, 'weight') m1coadd,m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(1000,1000)) m1,m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(1000,1000)) self.assertAlmostEqual(m1, m1coadd, delta=.01) m1,m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(1000,1001)) m1coadd,m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(1000,1001)) self.assertAlmostEqual(m1, m1coadd, delta=0.01)
def testValidPolygonPsf(self): """Demonstrate that we can use the validPolygon on Exposures in the CoaddPsf""" cd11, cd12, cd21, cd22 = 5.55555555e-05, 0.0, 0.0, 5.55555555e-05 crval1, crval2 = 0.0, 0.0 crpix = afwGeom.PointD(1000, 1000) crval = afwCoord.Coord(afwGeom.Point2D(crval1, crval2)) wcsref = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("weight", type="D", doc="Coadd weight") mycatalog = afwTable.ExposureCatalog(schema) # Create 9 separate records, each with its own peculiar Psf, Wcs, # weight, bounding box, and valid region. for i in range(1, 10): record = mycatalog.getTable().makeRecord() record.setPsf(measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0)) crpix = afwGeom.PointD(1000-10.0*i, 1000.0-10.0*i) wcs = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) record.setWcs(wcs) record['weight'] = 1.0*(i + 1) record['id'] = i record.setBBox(afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(1000, 1000))) validPolygon = Polygon(afwGeom.Box2D(afwGeom.Point2D(0,0), afwGeom.Extent2D(i*100, i*100))) record.setValidPolygon(validPolygon) mycatalog.append(record) # Create the CoaddPsf and check at three different points to ensure that the validPolygon is working mypsf = measAlg.CoaddPsf(mycatalog, wcsref, 'weight') for position in [afwGeom.Point2D(50, 50), afwGeom.Point2D(500, 500), afwGeom.Point2D(850, 850)]: m1coadd, m2coadd = getCoaddSecondMoments(mypsf, position, True) m1, m2 = getPsfSecondMoments(mypsf, position) self.assertAlmostEqual(m1, m1coadd, delta=0.01) self.assertAlmostEqual(m2, m2coadd, delta=0.01)
def testReadDESHeader(self): """Verify that we can read a DES header""" self.metadata.set("RADESYS", "FK5 ") # note trailing white space self.metadata.set("CTYPE1", 'RA---TPV') self.metadata.set("CTYPE2", 'DEC--TPV') afwImage.makeWcs(self.metadata)
def testRepeat(self): pl = headerToPropertyList(self.header) wcs1 = afwImage.makeWcs(pl) wcs2 = afwImage.makeWcs(pl) for x, y in ((0, 0), (0, self.height), (self.width, 0), (self.width, self.height)): point = afwGeom.Point2D(x, y) self.assertEqual(wcs1.pixelToSky(point), wcs2.pixelToSky(point))
def testValidPolygonPsf(self): """Test that we can use the validPolygon on exposures in the coadd psf""" print "ValidPolygonTest" # this is the coadd Wcs we want cd11 = 5.55555555e-05 cd12 = 0.0 cd21 = 0.0 cd22 = 5.55555555e-05 crval1 = 0.0 crval2 = 0.0 crpix = afwGeom.PointD(1000, 1000) crval = afwCoord.Coord(afwGeom.Point2D(crval1, crval2)) wcsref = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("weight", type="D", doc="Coadd weight") mycatalog = afwTable.ExposureCatalog(schema) # Each of the 9 has its peculiar Psf, Wcs, weight, bounding box, and valid region. for i in range(1, 10, 1): record = mycatalog.getTable().makeRecord() psf = measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0) record.setPsf(psf) crpix = afwGeom.PointD(1000 - 10.0 * i, 1000.0 - 10.0 * i) wcs = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) record.setWcs(wcs) record['weight'] = 1.0 * (i + 1) record['id'] = i bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(1000, 1000)) record.setBBox(bbox) validPolygon_bbox = afwGeom.Box2D( afwGeom.Point2D(0, 0), afwGeom.Extent2D(i * 100, i * 100)) validPolygon = Polygon(validPolygon_bbox) record.setValidPolygon(validPolygon) mycatalog.append(record) # Create the coaddpsf and check at three different points to ensure that the validPolygon is working mypsf = measAlg.CoaddPsf(mycatalog, wcsref, 'weight') m1coadd, m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(50, 50), True) m1, m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(50, 50)) self.assertTrue(testRelDiff(m1, m1coadd, .01)) self.assertTrue(testRelDiff(m2, m2coadd, .01)) m1coadd, m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(500, 500), True) m1, m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(500, 500)) self.assertTrue(testRelDiff(m1, m1coadd, .01)) self.assertTrue(testRelDiff(m2, m2coadd, .01)) m1coadd, m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(850, 850), True) m1, m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(850, 850)) self.assertTrue(testRelDiff(m1, m1coadd, .01)) self.assertTrue(testRelDiff(m2, m2coadd, .01))
def testAssertWcssAlmostEqualOverBBox(self): """Test assertWcsAlmostEqualOverBBox and wcsAlmostEqualOverBBox""" bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(3001, 3001)) ctrPix = afwGeom.Point2I(1500, 1500) metadata = dafBase.PropertySet() metadata.set("RADECSYS", "FK5") metadata.set("EQUINOX", 2000.0) metadata.set("CTYPE1", "RA---TAN") metadata.set("CTYPE2", "DEC--TAN") metadata.set("CUNIT1", "deg") metadata.set("CUNIT2", "deg") metadata.set("CRVAL1", 215.5) metadata.set("CRVAL2", 53.0) metadata.set("CRPIX1", ctrPix[0] + 1) metadata.set("CRPIX2", ctrPix[1] + 1) metadata.set("CD1_1", 5.1e-05) metadata.set("CD1_2", 0.0) metadata.set("CD2_2", -5.1e-05) metadata.set("CD2_1", 0.0) wcs0 = afwImage.makeWcs(metadata) metadata.set("CRVAL2", 53.000001) # tweak CRVAL2 for wcs1 wcs1 = afwImage.makeWcs(metadata) self.assertWcsAlmostEqualOverBBox(wcs0, wcs0, bbox, maxDiffSky=1e-7*afwGeom.arcseconds, maxDiffPix=1e-7) # sanity-check deprecated version self.assertWcsNearlyEqualOverBBox(wcs0, wcs0, bbox, maxDiffSky=1e-7*afwGeom.arcseconds, maxDiffPix=1e-7) self.assertTrue(afwImage.wcsAlmostEqualOverBBox(wcs0, wcs0, bbox, maxDiffSky=1e-7*afwGeom.arcseconds, maxDiffPix=1e-7)) self.assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.02) self.assertTrue(afwImage.wcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.02)) with self.assertRaises(AssertionError): self.assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.02) self.assertFalse(afwImage.wcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.02)) with self.assertRaises(AssertionError): self.assertWcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.001) self.assertFalse(afwImage.wcsAlmostEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.001)) # check that doShortCircuit works in the private implementation errStr1 = _compareWcsOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.001, doShortCircuit=False) errStr2 = _compareWcsOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.001, doShortCircuit=True) self.assertNotEqual(errStr1, errStr2)
def makeAndWriteWcs(): tanWcsMetadata = getTanWcsMetata() tanWcs = makeWcs(tanWcsMetadata) tanWcs.writeFits("oldTanWcs.fits") tanSipWcsMetata = getTanSipWcsMetata() tanSipWcs = makeWcs(tanSipWcsMetata) tanSipWcs.writeFits("oldTanSipWcs.fits")
def testCreateTanWcs(self): """Check that a TAN projection in the header creates a TanWcs object""" self.metadata.set("CTYPE1", "RA---TAN") self.metadata.set("CTYPE2", "DEC--TAN") afwImage.makeWcs(self.metadata) wcs = afwImage.makeWcs(self.metadata) self.assertIsInstance(wcs, afwImage.TanWcs)
def testCreate(self): """Check that we can create a CoaddPsf with 9 elements""" print "CreatePsfTest" # this is the coadd Wcs we want cd11 = 5.55555555e-05 cd12 = 0.0 cd21 = 0.0 cd22 = 5.55555555e-05 crval1 = 0.0 crval2 = 0.0 crpix = afwGeom.PointD(1000, 1000) crval = afwCoord.Coord(afwGeom.Point2D(crval1, crval2)) wcsref = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) #also test that the weight field name is correctly observed schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("customweightname", type="D", doc="Coadd weight") mycatalog = afwTable.ExposureCatalog(schema) # Each of the 9 has its peculiar Psf, Wcs, weight, and bounding box. for i in range(1,10,1): record = mycatalog.getTable().makeRecord() psf = measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0) record.setPsf(psf) crpix = afwGeom.PointD(i*1000.0, i*1000.0) wcs = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) record.setWcs(wcs) record['customweightname'] = 1.0 * (i+1) record['id'] = i bbox = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(i*1000, i*1000)) record.setBBox(bbox) mycatalog.append(record) #create the coaddpsf mypsf = measAlg.CoaddPsf(mycatalog, wcsref, 'customweightname') # check to be sure that we got the right number of components, in the right order self.assertEqual(mypsf.getComponentCount(), 9) for i in range(1,10,1): wcs = mypsf.getWcs(i-1) psf = mypsf.getPsf(i-1) bbox = mypsf.getBBox(i-1) weight = mypsf.getWeight(i-1) id = mypsf.getId(i-1) self.assertEqual(i, id) self.assertEqual(weight, 1.0*(i+1)) self.assertEqual(bbox.getBeginX(), 0) self.assertEqual(bbox.getBeginY(), 0) self.assertEqual(bbox.getEndX(), 1000* i) self.assertEqual(bbox.getEndY(), 1000* i) self.assertEqual(wcs.getPixelOrigin().getX(), (1000.0 * i)) self.assertEqual(wcs.getPixelOrigin().getY(), (1000.0 * i)) m0,xbar,ybar,mxx,myy,x0,y0 = getPsfMoments(psf, afwGeom.Point2D(0,0)) self.assertAlmostEqual(i*i, mxx, delta=0.01) self.assertAlmostEqual(i*i, myy, delta=0.01)
def testStripKeywords(self): """Test that we can strip WCS keywords from metadata when constructing a Wcs""" metadata = self.im.getMetadata() self.wcs = afwImage.makeWcs(metadata) self.assertTrue(metadata.exists("CRPIX1")) strip = True self.wcs = afwImage.makeWcs(metadata, strip) self.assertFalse(metadata.exists("CRPIX1"))
def testCast(self): # strangely, this overload of makeWcs returns a TAN WCS that's not a TanWcs wcs = afwImage.makeWcs(afwCoord.IcrsCoord(45.0*afwGeom.degrees, 45.0*afwGeom.degrees), afwGeom.Point2D(0.0, 0.0), 1.0, 0.0, 0.0, 1.0) # ...but if you round-trip it through a PropertySet, you get a TanWcs in a Wcs ptr, # which is what we want for this test. base = afwImage.makeWcs(wcs.getFitsMetadata()) self.assertEqual(type(base), afwImage.Wcs) derived = afwImage.TanWcs.cast(base) self.assertEqual(type(derived), afwImage.TanWcs)
def testCreateTanWcs(self): """Check that a non-TAN projection in the header creates a base Wcs object""" self.metadata.set("CTYPE1", "RA---TAN") self.metadata.set("CTYPE2", "DEC--TAN") afwImage.makeWcs(self.metadata) wcs = afwImage.cast_TanWcs(afwImage.makeWcs(self.metadata)) strRepresentation = str(wcs) self.assertNotEqual( strRepresentation.find("image::TanWcs"), -1, "non TanWcs object returned")
def testCD_PC(self): """Test that we can read a FITS file with both CD and PC keys (like early Suprimecam files)""" md = dafBase.PropertyList() for k, v in ( ("EQUINOX", 2000.0), ("RADESYS", 'FK5'), ("CRPIX1" , 5353.0), ("CRPIX2" , -35.0), ("CD1_1" , 0.0), ("CD1_2" , -5.611E-05), ("CD2_1" , -5.611E-05), ("CD2_2" , -0.0), ("CRVAL1" , 4.5789875), ("CRVAL2" , 16.30004444), ("CUNIT1" , 'deg'), ("CUNIT2" , 'deg'), ("CTYPE1" , 'RA---TAN'), ("CTYPE2" , 'DEC--TAN'), ("CDELT1" , -5.611E-05), ("CDELT2" , 5.611E-05), ): md.set(k, v) wcs = afwImage.makeWcs(md) x, y = 1000, 2000 ra, dec = 4.459815023498577, 16.544199850984768 sky = wcs.pixelToSky(x, y) for i, v in enumerate([ra, dec]): self.assertEqual(sky[i].asDegrees(), v) for badPC in (False, True): if verbose: print "Checking PC coefficients: badPC =", badPC for k, v in ( ("PC001001", 0.0), ("PC001002", -1.0 if badPC else 1.0), ("PC002001", 1.0 if badPC else -1.0), ("PC002002", 0.0), ): md.set(k, v) # Check Greisen and Calabretta A&A 395 1061 (2002), Eq. 3 if not badPC: for i in (1, 2,): for j in (1, 2,): self.assertEqual(md.get("CD%d_%d" % (i, j)), md.get("CDELT%d" % i)*md.get("PC00%d00%d" % (i, j))) wcs = afwImage.makeWcs(md) sky = wcs.pixelToSky(x, y) for i, v in enumerate([ra, dec]): self.assertEqual(sky[i].asDegrees(), v)
def testTransform(self): dims = afwGeom.Extent2I(512, 512) bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), dims) radius = 5 offset = afwGeom.Extent2D(123, 456) crval = afwCoord.Coord(0 * afwGeom.degrees, 0 * afwGeom.degrees) crpix = afwGeom.Point2D(0, 0) cdMatrix = [1.0e-5, 0.0, 0.0, 1.0e-5] source = afwImage.makeWcs(crval, crpix, *cdMatrix) target = afwImage.makeWcs(crval, crpix + offset, *cdMatrix) sourceSpanSet = afwGeom.SpanSet.fromShape(radius, afwGeom.Stencil.CIRCLE) sourceSpanSet = sourceSpanSet.shiftedBy(12, 34) fpSource = afwDetect.Footprint(sourceSpanSet, bbox) fpTarget = fpSource.transform(source, target, bbox) self.assertEqual(len(fpSource.getSpans()), len(fpTarget.getSpans())) self.assertEqual(fpSource.getArea(), fpTarget.getArea()) imSource = afwImage.ImageU(dims) fpSource.spans.setImage(imSource, 1) imTarget = afwImage.ImageU(dims) fpTarget.spans.setImage(imTarget, 1) subSource = imSource.Factory(imSource, fpSource.getBBox()) subTarget = imTarget.Factory(imTarget, fpTarget.getBBox()) self.assertTrue(np.all(subSource.getArray() == subTarget.getArray())) # make a bbox smaller than the target footprint bbox2 = afwGeom.Box2I(fpTarget.getBBox()) bbox2.grow(-1) fpTarget2 = fpSource.transform(source, target, bbox2) # this one clips fpTarget3 = fpSource.transform(source, target, bbox2, False) # this one doesn't self.assertTrue(bbox2.contains(fpTarget2.getBBox())) self.assertFalse(bbox2.contains(fpTarget3.getBBox())) self.assertNotEqual(fpTarget.getArea(), fpTarget2.getArea()) self.assertEqual(fpTarget.getArea(), fpTarget3.getArea()) # Test that peakCatalogs get Transformed correctly truthList = [(x, y, 10) for x, y in zip(range(-2, 2), range(-1, 3))] for value in truthList: fpSource.addPeak(*value) scaleFactor = 2 linTrans = afwGeom.LinearTransform( np.matrix([[scaleFactor, 0], [0, scaleFactor]], dtype=float)) linTransFootprint = fpSource.transform(linTrans, fpSource.getBBox(), False) for peak, truth in zip(linTransFootprint.peaks, truthList): # Multiplied by two because that is the linear transform scaling # factor self.assertEqual(peak.getIx(), truth[0] * scaleFactor) self.assertEqual(peak.getIy(), truth[1] * scaleFactor)
def makeitLsst(prefs, context, saveWcs=False, plot=dict()): """This is the python wrapper that reads lsst tables""" # Create an array of PSFs (one PSF for each extension) if prefs.getVerboseType() != prefs.QUIET: print("----- %d input catalogues:" % prefs.getNcat()) if saveWcs: # only needed for making plots wcssList = [] fields = psfexLib.vectorField() for cat in prefs.getCatalogs(): field = psfexLib.Field(cat) wcss = [] wcssList.append(wcss) with pyfits.open(cat): # Hack: I want the WCS so I'll guess where the calexp is to be found calexpFile = guessCalexp(cat) md = afwImage.readMetadata(calexpFile) wcs = afwImage.makeWcs(md) if not wcs: crval = afwCoord.makeCoord(afwCoord.ICRS, 0.0 * afwGeom.degrees, 0.0 * afwGeom.degrees) wcs = afwImage.makeWcs(crval, afwGeom.PointD(0, 0), 1.0, 0, 0, 1.0) naxis1, naxis2 = md.get("NAXIS1"), md.get("NAXIS2") # Find how many rows there are in the catalogue md = afwImage.readMetadata(cat) field.addExt(wcs, naxis1, naxis2, md.get("NAXIS2")) if saveWcs: wcss.append((wcs, naxis1, naxis2)) field.finalize() fields.append(field) fields[0].getNext() # number of extensions prefs.getPsfStep() sets = psfexLib.vectorSet() for set in load_samplesLsst(prefs, context, plot=plot): sets.append(set) psfexLib.makeit(fields, sets) ret = [[f.getPsfs() for f in fields], sets] if saveWcs: ret.append(wcssList) return ret
def testValidPolygonPsf(self): """Test that we can use the validPolygon on exposures in the coadd psf""" print "ValidPolygonTest" # this is the coadd Wcs we want cd11 = 5.55555555e-05 cd12 = 0.0 cd21 = 0.0 cd22 = 5.55555555e-05 crval1 = 0.0 crval2 = 0.0 crpix = afwGeom.PointD(1000, 1000) crval = afwCoord.Coord(afwGeom.Point2D(crval1, crval2)) wcsref = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("weight", type="D", doc="Coadd weight") mycatalog = afwTable.ExposureCatalog(schema) # Each of the 9 has its peculiar Psf, Wcs, weight, bounding box, and valid region. for i in range(1,10,1): record = mycatalog.getTable().makeRecord() psf = measAlg.DoubleGaussianPsf(100, 100, i, 1.00, 0.0); record.setPsf(psf) crpix = afwGeom.PointD(1000-10.0*i, 1000.0-10.0*i) wcs = afwImage.makeWcs(crval,crpix,cd11,cd12,cd21,cd22) record.setWcs(wcs) record['weight'] = 1.0 * (i+1) record['id'] = i bbox = afwGeom.Box2I(afwGeom.Point2I(0,0), afwGeom.Extent2I(1000, 1000)) record.setBBox(bbox) validPolygon_bbox = afwGeom.Box2D(afwGeom.Point2D(0,0), afwGeom.Extent2D(i*100, i*100)) validPolygon = Polygon(validPolygon_bbox) record.setValidPolygon(validPolygon) mycatalog.append(record) # Create the coaddpsf and check at three different points to ensure that the validPolygon is working mypsf = measAlg.CoaddPsf(mycatalog, wcsref, 'weight') m1coadd,m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(50,50),True) m1,m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(50,50)) self.assertTrue(testRelDiff(m1,m1coadd,.01)) self.assertTrue(testRelDiff(m2,m2coadd,.01)) m1coadd,m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(500,500),True) m1,m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(500,500)) self.assertTrue(testRelDiff(m1,m1coadd,.01)) self.assertTrue(testRelDiff(m2,m2coadd,.01)) m1coadd,m2coadd = getCoaddSecondMoments(mypsf, afwGeom.Point2D(850,850),True) m1,m2 = getPsfSecondMoments(mypsf, afwGeom.Point2D(850,850)) self.assertTrue(testRelDiff(m1,m1coadd,.01)) self.assertTrue(testRelDiff(m2,m2coadd,.01))
def makeitLsst(prefs, context, saveWcs=False, plot=dict()): """This is the python wrapper that reads lsst tables""" # Create an array of PSFs (one PSF for each extension) if prefs.getVerboseType() != prefs.QUIET: print("----- %d input catalogues:" % prefs.getNcat()) if saveWcs: # only needed for making plots wcssList = [] fields = psfexLib.vectorField() for cat in prefs.getCatalogs(): field = psfexLib.Field(cat) wcss = [] wcssList.append(wcss) with pyfits.open(cat): # Hack: I want the WCS so I'll guess where the calexp is to be found calexpFile = guessCalexp(cat) md = afwImage.readMetadata(calexpFile) wcs = afwImage.makeWcs(md) if not wcs: crval = afwCoord.makeCoord(afwCoord.ICRS, 0.0*afwGeom.degrees, 0.0*afwGeom.degrees) wcs = afwImage.makeWcs(crval, afwGeom.PointD(0, 0), 1.0, 0, 0, 1.0) naxis1, naxis2 = md.get("NAXIS1"), md.get("NAXIS2") # Find how many rows there are in the catalogue md = afwImage.readMetadata(cat) field.addExt(wcs, naxis1, naxis2, md.get("NAXIS2")) if saveWcs: wcss.append((wcs, naxis1, naxis2)) field.finalize() fields.append(field) fields[0].getNext() # number of extensions prefs.getPsfStep() sets = psfexLib.vectorSet() for set in load_samplesLsst(prefs, context, plot=plot): sets.append(set) psfexLib.makeit(fields, sets) ret = [[f.getPsfs() for f in fields], sets] if saveWcs: ret.append(wcssList) return ret
def testAssertWcssNearlyEqualOverBBox(self): """Test assertWcsNearlyEqualOverBBox and wcsNearlyEqualOverBBox""" bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(3001, 3001)) ctrPix = afwGeom.Point2I(1500, 1500) metadata = dafBase.PropertySet() metadata.set("RADECSYS", "FK5") metadata.set("EQUINOX", 2000.0) metadata.set("CTYPE1", "RA---TAN") metadata.set("CTYPE2", "DEC--TAN") metadata.set("CUNIT1", "deg") metadata.set("CUNIT2", "deg") metadata.set("CRVAL1", 215.5) metadata.set("CRVAL2", 53.0) metadata.set("CRPIX1", ctrPix[0] + 1) metadata.set("CRPIX2", ctrPix[1] + 1) metadata.set("CD1_1", 5.1e-05) metadata.set("CD1_2", 0.0) metadata.set("CD2_2", -5.1e-05) metadata.set("CD2_1", 0.0) wcs0 = afwImage.cast_TanWcs(afwImage.makeWcs(metadata)) metadata.set("CRVAL2", 53.000001) # tweak CRVAL2 for wcs1 wcs1 = afwImage.cast_TanWcs(afwImage.makeWcs(metadata)) self.assertWcsNearlyEqualOverBBox(wcs0, wcs0, bbox, maxDiffSky=1e-7*afwGeom.arcseconds, maxDiffPix=1e-7) self.assertTrue(afwImage.wcsNearlyEqualOverBBox(wcs0, wcs0, bbox, maxDiffSky=1e-7*afwGeom.arcseconds, maxDiffPix=1e-7)) self.assertWcsNearlyEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.02) self.assertTrue(afwImage.wcsNearlyEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.02)) self.assertRaises(AssertionError, self.assertWcsNearlyEqualOverBBox, wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.02) self.assertFalse(afwImage.wcsNearlyEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.02)) self.assertRaises(AssertionError, self.assertWcsNearlyEqualOverBBox, wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.001) self.assertFalse(afwImage.wcsNearlyEqualOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.04*afwGeom.arcseconds, maxDiffPix=0.001)) # check that doShortCircuit works in the private implementation errStr1 = _compareWcsOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.001, doShortCircuit=False) errStr2 = _compareWcsOverBBox(wcs0, wcs1, bbox, maxDiffSky=0.001*afwGeom.arcseconds, maxDiffPix=0.001, doShortCircuit=True) self.assertNotEqual(errStr1, errStr2)
def testPythonLevelMakeWcs(self): """Verify that we can make a Wcs by providing the CD matrix elements in python.""" m = self.metadata crval = afwGeom.Point2D(m.getDouble("CRVAL1"), m.getDouble("CRVAL2")) crpix = afwGeom.Point2D(m.getDouble("CRPIX1"), m.getDouble("CRPIX2")) cd11, cd12 = m.getDouble("CD1_1"), m.getDouble("CD1_2") cd21, cd22 = m.getDouble("CD2_1"), m.getDouble("CD2_2") # this is defined at the c++ level in src/image/makeWcs.cc wcsMade = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) # this is defined at the python/swig level in python/lsst/afw/image/imageLib.i # createWcs can probably be depricated wcsCreated = afwImage.createWcs(crval, crpix, cd11, cd12, cd21, cd22) # trivial test ... verify that we get back what we put in. for wcs in [wcsMade, wcsCreated]: crvalTest = wcs.getSkyOrigin().getPosition(afwCoord.DEGREES) crpixTest = wcs.getPixelOrigin() CD = wcs.getCDMatrix() self.assertAlmostEqual(crvalTest[0], crval[0]) self.assertAlmostEqual(crvalTest[1], crval[1]) self.assertAlmostEqual(crpixTest[0], crpix[0]) self.assertAlmostEqual(crpixTest[1], crpix[1]) self.assertAlmostEqual(CD[0,0], cd11) self.assertAlmostEqual(CD[0,1], cd12) self.assertAlmostEqual(CD[1,0], cd21) self.assertAlmostEqual(CD[1,1], cd22)
def testPythonLevelMakeWcs(self): """Verify that we can make a Wcs by providing the CD matrix elements in python.""" m = self.metadata crval = afwCoord.makeCoord(afwCoord.ICRS, m.getDouble("CRVAL1") * afwGeom.degrees, m.getDouble("CRVAL2") * afwGeom.degrees) crpix = afwGeom.Point2D(m.getDouble("CRPIX1"), m.getDouble("CRPIX2")) cd11, cd12 = m.getDouble("CD1_1"), m.getDouble("CD1_2") cd21, cd22 = m.getDouble("CD2_1"), m.getDouble("CD2_2") print 'CRVAL:', crval # this is defined at the c++ level in src/image/makeWcs.cc wcsMade = afwImage.makeWcs(crval, crpix, cd11, cd12, cd21, cd22) # trivial test ... verify that we get back what we put in. for wcs in [wcsMade]: crvalTest = wcs.getSkyOrigin().getPosition(afwGeom.degrees) crpixTest = wcs.getPixelOrigin() CD = wcs.getCDMatrix() self.assertAlmostEqual(crvalTest[0], crval.getLongitude().asDegrees()) self.assertAlmostEqual(crvalTest[1], crval.getLatitude().asDegrees()) self.assertAlmostEqual(crpixTest[0], crpix[0]) self.assertAlmostEqual(crpixTest[1], crpix[1]) self.assertAlmostEqual(CD[0,0], cd11) self.assertAlmostEqual(CD[0,1], cd12) self.assertAlmostEqual(CD[1,0], cd21) self.assertAlmostEqual(CD[1,1], cd22)
def test(self): schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("ccd", int, doc="CCD number") schema.addField("visit", long, doc="Visit number") schema.addField("goodpix", int, doc="Number of good pixels") schema.addField("weight", float, doc="Weighting for this CCD") ccds = afwTable.ExposureCatalog(schema) wcs = afwImage.makeWcs(afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees), afwGeom.Point2D(0.0, 0.0), 1.0e-4, 0.0, 0.0, 1.0e-4) new = ccds.addNew() new.set("id", 0) new.set("bbox.min", afwGeom.Point2I(0,0)) new.set("bbox.max", afwGeom.Point2I(1024,1024)) # The following lines are critical for reproducing the bug, because # the code is reading a double starting at the 'ccd' (offset 24), and # it sees a zero (from the zero in 'ccd' and the leading zeros in 'visit'). new.set("ccd", 0) new.set("visit", 6789) new.set("goodpix", 987654321) new.set("weight", 1.0) new.setPsf(measAlg.SingleGaussianPsf(23, 23, 2.345)) new.setWcs(wcs) # In the presence of the bug, the following fails with: # LsstCppException: 0: lsst::pex::exceptions::RuntimeErrorException thrown at src/CoaddPsf.cc:134 in lsst::afw::geom::Point2D lsst::meas::algorithms::{anonymous}::computeAveragePosition(const ExposureCatalog&, const lsst::afw::image::Wcs&, lsst::afw::table::Key<double>) # 0: Message: Could not find a valid average position for CoaddPsf measAlg.CoaddPsf(ccds, wcs)
def mtv(self, data, title="", wcs=None): """!Display an Image or Mask on a DISPLAY display Historical note: the name "mtv" comes from Jim Gunn's forth imageprocessing system, Mirella (named after Mirella Freni); The "m" stands for Mirella. """ if hasattr(data, "getXY0"): self._xy0 = data.getXY0() else: self._xy0 = None if re.search("::Exposure<", repr(data)): # it's an Exposure; display the MaskedImage with the WCS if wcs: raise RuntimeError, "You may not specify a wcs with an Exposure" data, wcs = data.getMaskedImage(), data.getWcs() elif re.search("::DecoratedImage<", repr(data)): # it's a DecoratedImage; display it data, wcs = data.getImage(), afwImage.makeWcs(data.getMetadata()) self._xy0 = data.getXY0() # DecoratedImage doesn't have getXY0() if re.search("::Image<", repr(data)): # it's an Image; display it self._impl._mtv(data, None, wcs, title) elif re.search("::Mask<", repr(data)): # it's a Mask; display it, bitplane by bitplane # # Some displays can't display a Mask without an image; so display an Image too, # with pixel values set to the mask # self._impl._mtv(afwImage.ImageU(data.getArray()), data, wcs, title) elif re.search("::MaskedImage<", repr(data)): # it's a MaskedImage; display Image and overlay Mask self._impl._mtv(data.getImage(), data.getMask(True), wcs, title) else: raise RuntimeError, "Unsupported type %s" % repr(data)
def getSwarpedImage(self, kernelName, useSubregion=False, useDeepCopy=False): """ Inputs: - kernelName: name of kernel in the form used by afwImage.makeKernel - useSubregion: if True then the original source exposure (from which the usual test exposure was extracted) is read and the correct subregion extracted - useDeepCopy: if True then the copy of the subimage is a deep copy, else it is a shallow copy; ignored if useSubregion is False Returns: - originalExposure - swarpedImage - swarpedWcs """ if useSubregion: originalFullExposure = afwImage.ExposureF(originalExposurePath) # "medsub" is a subregion of med starting at 0-indexed pixel (40, 150) of size 145 x 200 bbox = afwGeom.Box2I(afwGeom.Point2I(40, 150), afwGeom.Extent2I(145, 200)) originalExposure = afwImage.ExposureF(originalFullExposure, bbox, useDeepCopy) swarpedImageName = "medsubswarp1%s.fits" % (kernelName,) else: originalExposure = afwImage.ExposureF(originalExposurePath) swarpedImageName = "medswarp1%s.fits" % (kernelName,) swarpedImagePath = os.path.join(dataDir, swarpedImageName) swarpedDecoratedImage = afwImage.DecoratedImageF(swarpedImagePath) swarpedImage = swarpedDecoratedImage.getImage() swarpedMetadata = swarpedDecoratedImage.getMetadata() swarpedWcs = afwImage.makeWcs(swarpedMetadata) return (originalExposure, swarpedImage, swarpedWcs)
def makeWcs(pixelScale, crPixPos, crValCoord, posAng=afwGeom.Angle(0.0), doFlipX=False, projection="TAN"): """Make a Wcs @param[in] pixelScale: desired scale, as sky/pixel, an afwGeom.Angle @param[in] crPixPos: crPix for WCS, using the LSST standard; a pair of floats @param[in] crValCoord: crVal for WCS (afwCoord.Coord) @param[in] posAng: position angle (afwGeom.Angle) @param[in] doFlipX: flip X axis? @param[in] projection: WCS projection (e.g. "TAN" or "STG") """ if len(projection) != 3: raise RuntimeError("projection=%r; must have length 3" % (projection,)) ctypeList = [("%-5s%3s" % (("RA", "DEC")[i], projection)).replace(" ", "-") for i in range(2)] ps = dafBase.PropertySet() crPixFits = [ind + 1.0 for ind in crPixPos] # convert pix position to FITS standard crValDeg = crValCoord.getPosition(afwGeom.degrees) posAngRad = posAng.asRadians() pixelScaleDeg = pixelScale.asDegrees() cdMat = numpy.array([[ math.cos(posAngRad), math.sin(posAngRad)], [-math.sin(posAngRad), math.cos(posAngRad)]], dtype=float) * pixelScaleDeg if doFlipX: cdMat[:,0] = -cdMat[:,0] for i in range(2): ip1 = i + 1 ps.add("CTYPE%1d" % (ip1,), ctypeList[i]) ps.add("CRPIX%1d" % (ip1,), crPixFits[i]) ps.add("CRVAL%1d" % (ip1,), crValDeg[i]) ps.add("RADECSYS", "ICRS") ps.add("EQUINOX", 2000) ps.add("CD1_1", cdMat[0, 0]) ps.add("CD2_1", cdMat[1, 0]) ps.add("CD1_2", cdMat[0, 1]) ps.add("CD2_2", cdMat[1, 1]) return afwImage.makeWcs(ps)
def setUp(self): # Set up local astrometry_net_data self.datapath = helper.setupAstrometryNetDataDir('photocal') self.config = measAstrom.LoadAstrometryNetObjectsTask.ConfigClass() self.bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(3001, 3001)) self.ctrPix = afwGeom.Point2I(1500, 1500) metadata = dafBase.PropertySet() metadata.set("RADECSYS", "FK5") metadata.set("EQUINOX", 2000.0) metadata.set("CTYPE1", "RA---TAN") metadata.set("CTYPE2", "DEC--TAN") metadata.set("CUNIT1", "deg") metadata.set("CUNIT2", "deg") metadata.set("CRVAL1", 215.5) metadata.set("CRVAL2", 53.0) metadata.set("CRPIX1", self.ctrPix[0] + 1) metadata.set("CRPIX2", self.ctrPix[1] + 1) metadata.set("CD1_1", 5.1e-05) metadata.set("CD1_2", 0.0) metadata.set("CD2_2", -5.1e-05) metadata.set("CD2_1", 0.0) self.wcs = afwImage.makeWcs(metadata) self.desNumStarsInPixelBox = 270 self.desNumStarsInSkyCircle = 410
def setUp(self): # Set up local astrometry_net_data self.datapath = helper.setupAstrometryNetDataDir('photocal') self.bbox = afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(3001, 3001)) self.ctrPix = afwGeom.Point2I(1500, 1500) metadata = dafBase.PropertySet() metadata.set("RADECSYS", "FK5") metadata.set("EQUINOX", 2000.0) metadata.set("CTYPE1", "RA---TAN") metadata.set("CTYPE2", "DEC--TAN") metadata.set("CUNIT1", "deg") metadata.set("CUNIT2", "deg") metadata.set("CRVAL1", 215.5) metadata.set("CRVAL2", 53.0) metadata.set("CRPIX1", self.ctrPix[0] + 1) metadata.set("CRPIX2", self.ctrPix[1] + 1) metadata.set("CD1_1", 5.1e-05) metadata.set("CD1_2", 0.0) metadata.set("CD2_2", -5.1e-05) metadata.set("CD2_1", 0.0) self.tanWcs = afwImage.cast_TanWcs(afwImage.makeWcs(metadata)) self.exposure = afwImage.ExposureF(self.bbox) self.exposure.setWcs(self.tanWcs) self.exposure.setFilter(afwImage.Filter("r", True))
def testTicket2872(self): """Test that CoaddPsf.getAveragePosition() is always a position at which we can call computeImage(). """ schema = afwTable.ExposureTable.makeMinimalSchema() weightKey = schema.addField("weight", type=float, doc="photometric weight") catalog = afwTable.ExposureCatalog(schema) cdelt = (0.2*afwGeom.arcseconds).asDegrees() wcs = afwImage.makeWcs( afwCoord.IcrsCoord(afwGeom.Point2D(45.0, 45.0), afwGeom.degrees), afwGeom.Point2D(50, 50), cdelt, 0.0, 0.0, cdelt ) kernel = measAlg.DoubleGaussianPsf(7,7,2.0).getKernel() psf1 = measAlg.KernelPsf(kernel, afwGeom.Point2D(0, 50)) psf2 = measAlg.KernelPsf(kernel, afwGeom.Point2D(100, 50)) record1 = catalog.addNew() record1.setPsf(psf1) record1.setWcs(wcs) record1.setD(weightKey, 1.0) record1.setBBox(afwGeom.Box2I(afwGeom.Point2I(-40, 0), afwGeom.Point2I(40, 100))) record2 = catalog.addNew() record2.setPsf(psf2) record2.setWcs(wcs) record2.setD(weightKey, 1.0) record2.setBBox(afwGeom.Box2I(afwGeom.Point2I(60, 0), afwGeom.Point2I(140, 100))) coaddPsf = measAlg.CoaddPsf(catalog, wcs) naiveAvgPos = afwGeom.Point2D(50, 50) self.assertRaises( pexExceptions.InvalidParameterError, coaddPsf.computeKernelImage, naiveAvgPos ) # important test is that this doesn't throw: coaddPsf.computeKernelImage()
def bypass_instcal(self, datasetType, pythonType, butlerLocation, dataId): # Workaround until I can access the butler instcalMap = self.map_instcal(dataId) dqmaskMap = self.map_dqmask(dataId) wtmapMap = self.map_wtmap(dataId) rawMap = self.map_raw(dataId) instcalType = getattr(afwImage, instcalMap.getPythonType().split(".")[-1]) rawType = getattr(afwImage, rawMap.getPythonType().split(".")[-1]) dqmaskType = getattr(afwImage, dqmaskMap.getPythonType().split(".")[-1]) wtmapType = getattr(afwImage, wtmapMap.getPythonType().split(".")[-1]) instcal = instcalType(instcalMap.getLocations()[0]) dqmask = dqmaskType(dqmaskMap.getLocations()[0]) wtmap = wtmapType(wtmapMap.getLocations()[0]) raw = rawType(rawMap.getLocations()[0]) mask = self.translate_dqmask(dqmask) variance = self.translate_wtmap(wtmap) mi = afwImage.MaskedImageF(afwImage.ImageF(instcal.getImage()), mask, variance) md = raw.getMetadata() wcs = afwImage.makeWcs(md) exp = afwImage.ExposureF(mi, wcs) # Set the calib by hand; need to grab the zeroth extension header = re.sub(r'[\[](\d+)[\]]$', "[0]", rawMap.getLocations()[0]) md0 = afwImage.readMetadata(header) calib = afwImage.Calib() calib.setExptime(md0.get("EXPTIME")) calib.setFluxMag0(10**(0.4 * md0.get("MAGZERO"))) exp.setCalib(calib) exp.setMetadata(md) # Do we need to remove WCS/calib info? return exp
def setUp(self): self.im = afwImage.DecoratedImageD(InputSmallImagePath) self.wcs = afwImage.makeWcs(self.im.getMetadata()) if False: ds9.mtv(self.im, wcs=self.wcs)
def test1(self): # This fails due to #1386 #wcsfn = os.path.join(self.datadir, 'imsim-v85518312-fu-R43-S12.wcs') wcsfn = os.path.join(self.datadir, 'imsim-v85518312-fu-R43-S12.wcs2') hdr = afwImage.readMetadata(wcsfn) wcs1 = afwImage.makeWcs(hdr) crval = wcs1.getSkyOrigin() cd = wcs1.getCDMatrix() print cd crval_p = afwGeom.Point2D(crval.getLongitude().asDegrees(), crval.getLatitude().asDegrees()) origin = wcs1.getPixelOrigin() print crval_p print origin wcs2 = afwImage.Wcs(crval_p, origin, cd) for wcs in [wcs1,wcs2]: print wcs print 'x, y, RA, Dec, pixscale("/pix), pixscale2' for x,y in [(0,0),(300,0),(350,0),(360,0),(370,0),(380,0),(400,0)]: radec = wcs.pixelToSky(x,y) ra = radec.getLongitude().asDegrees() dec = radec.getLatitude ().asDegrees() pixscale = 3600. * sqrt(wcs.pixArea(afwGeom.Point2D(x,y))) ps2 = wcs.pixelScale().asArcseconds() print x,y,ra,dec,pixscale,ps2 self.assertTrue(abs(pixscale - 0.2) < 1e-3) self.assertTrue(abs(ps2 - 0.2) < 1e-3)
def _standardizeMasterCal(self, datasetType, item, dataId, setFilter=False): """Standardize a MasterCal image obtained from NOAO archive into Exposure These MasterCal images are MEF files with one HDU for each detector. Some WCS header, eg CTYPE1, exists only in the zeroth extensionr, so info in the zeroth header need to be copied over to metadata. @param datasetType: Dataset type ("bias" or "flat") @param item: The image read by the butler @param dataId: Data identifier @param setFilter: Whether to set the filter in the Exposure @return (lsst.afw.image.Exposure) the standardized Exposure """ mi = afwImage.makeMaskedImage(item.getImage()) md = item.getMetadata() masterCalMap = getattr(self, "map_" + datasetType) masterCalPath = masterCalMap(dataId).getLocations()[0] headerPath = re.sub(r'[\[](\d+)[\]]$', "[0]", masterCalPath) md0 = afwImage.readMetadata(headerPath) for kw in ('CTYPE1', 'CTYPE2', 'CRVAL1', 'CRVAL2', 'CUNIT1', 'CUNIT2', 'CD1_1', 'CD1_2', 'CD2_1', 'CD2_2'): if kw in md0.paramNames() and kw not in md.paramNames(): md.add(kw, md0.get(kw)) wcs = afwImage.makeWcs(md, True) exp = afwImage.makeExposure(mi, wcs) exp.setMetadata(md) return self._standardizeExposure(self.calibrations[datasetType], exp, dataId, filter=setFilter)
def testImageToPixels(self): """Tests intersection of an image (WCS and dimensions) with a quad-sphere pixelization. """ #metadata taken from CFHT data v695856-e0/v695856-e0-c000-a00.sci_img.fits metadata = dafBase.PropertySet() metadata.set("SIMPLE", "T") metadata.set("BITPIX", -32) metadata.set("NAXIS", 2) metadata.set("NAXIS1", 1024) metadata.set("NAXIS2", 1153) metadata.set("RADECSYS", "FK5") metadata.set("EQUINOX", 2000.0) metadata.set("CRVAL1", 215.604025685476) metadata.set("CRVAL2", 53.1595451514076) metadata.set("CRPIX1", 1109.99981456774) metadata.set("CRPIX2", 560.018167811613) metadata.set("CTYPE1", "RA---TAN") metadata.set("CTYPE2", "DEC--TAN") metadata.set("CD1_1", 5.10808596133527E-05) metadata.set("CD1_2", 1.85579539217196E-07) metadata.set("CD2_2", -5.10281493481982E-05) metadata.set("CD2_1", -8.27440751733828E-07) wcs = afwImage.makeWcs(metadata) qs = skypix.createQuadSpherePixelization() poly = skypix.imageToPolygon(wcs, 1024, 1153) pixels = qs.intersect(poly) self.assertEqual(len(pixels), 1) self.assertEqual(pixels[0], 182720) self.assertTrue(qs.getGeometry(182720).contains(poly))
def makeTestExposure(self, xNumPix, yNumPix): """ Create and return an exposure that is completely covered by the database: test_select_lsst_images """ metadata = lsst.daf.base.PropertySet() metadata.set("NAXIS", 2) metadata.set("RADECSYS", "ICRS") metadata.set("EQUINOX", 2000.) metadata.setDouble("CRVAL1", 60.000000000000) metadata.setDouble("CRVAL2", 10.812316963572) metadata.setDouble("CRPIX1", 700000.00000000) metadata.setDouble("CRPIX2", 601345.00000000) metadata.set("CTYPE1", "RA---STG") metadata.set("CTYPE2", "DEC--STG") metadata.setDouble("CD1_1", -5.5555555555556e-05) metadata.setDouble("CD1_2", 0.0000000000000) metadata.setDouble("CD2_2", 5.5555555555556e-05) metadata.setDouble("CD2_1", 0.0000000000000) metadata.set("CUNIT1", "deg") metadata.set("CUNIT2", "deg") #exposure needs a wcs and a bbox wcs = afwImage.makeWcs(metadata) bbox = afwGeom.Box2I(afwGeom.Point2I(327750, 235750), afwGeom.Extent2I(xNumPix, yNumPix)) exposure = afwImage.ExposureF(bbox, wcs) mi = exposure.getMaskedImage() mi.set(1.0) mi.getVariance().set(1.0) return exposure
def test(self): schema = afwTable.ExposureTable.makeMinimalSchema() schema.addField("ccd", int, doc="CCD number") schema.addField("visit", long, doc="Visit number") schema.addField("goodpix", int, doc="Number of good pixels") schema.addField("weight", float, doc="Weighting for this CCD") ccds = afwTable.ExposureCatalog(schema) wcs = afwImage.makeWcs(afwCoord.Coord(0.0*afwGeom.degrees, 0.0*afwGeom.degrees), afwGeom.Point2D(0.0, 0.0), 1.0e-4, 0.0, 0.0, 1.0e-4) new = ccds.addNew() new.set("id", 0) new.set("bbox_min_x", 0) new.set("bbox_min_y", 0) new.set("bbox_max_x", 1024) new.set("bbox_max_y", 1024) # The following lines are critical for reproducing the bug, because # the code is reading a double starting at the 'ccd' (offset 24), and # it sees a zero (from the zero in 'ccd' and the leading zeros in 'visit'). new.set("ccd", 0) new.set("visit", 6789) new.set("goodpix", 987654321) new.set("weight", 1.0) new.setPsf(measAlg.SingleGaussianPsf(23, 23, 2.345)) new.setWcs(wcs) # In the presence of the bug, the following fails with # lsst::pex::exceptions::RuntimeError thrown in src/CoaddPsf.cc # with message: "Could not find a valid average position for CoaddPsf" measAlg.CoaddPsf(ccds, wcs)
def setUp(self): # Pick arbitrary numbers to create a detector object, and a synthetic # dataset. The particular numbers have no special meaning to the test # and be anything as long as they are self consistent (i.e. the # fake source is inside the bounding box) self.center = lsst.afw.geom.Point2D(50.1, 49.8) self.bbox = lsst.afw.geom.Box2I(lsst.afw.geom.Point2I(-20, -30), lsst.afw.geom.Extent2I(140,160)) self.dataset = lsst.meas.base.tests.TestDataset(self.bbox) self.dataset.addSource(100000.0, self.center) md = dafBase.PropertyList() for k, v in ( ("EQUINOX", 2000.0), ("CRPIX1" , 5353.0), ("CRPIX2" , -35.0), ("CD1_1" , 0.0), ("CD1_2" , -5.611E-05), ("CD2_1" , -5.611E-05), ("CD2_2" , -0.0), ("CRVAL1" , 4.5789875), ("CRVAL2" , 16.30004444), ("CUNIT1" , 'deg'), ("CUNIT2" , 'deg'), ("CTYPE1" , 'RA---TAN'), ("CTYPE2" , 'DEC--TAN'), ): md.set(k, v) self.wcs = afwImage.makeWcs(md)