Coverage for tests/testOutputWcs.py : 34%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#from lsst.sims.coordUtils.utils import ReturnCamera
lsst.utils.tests.init()
# sedFilename
('decJ2000', 'dec*PI()/180.0', np.float)]
('properMotionRa', 0.0, np.float), ('properMotionDec', 0.0, np.float), ('radialVelocity', 0.0, np.float), ('parallax', 0.0, np.float), ('magNorm', 14.0, np.float)]
def tearDownClass(cls): sims_clean_up()
""" Test that, when GalSim generates an image, in encodes the WCS in a way afw can read. This is done by creating an image,then reading it back in, getting its WCS, and comparing the pixel-to-sky conversion both for the read WCS and the original afw.cameraGeom.detector. Raise an exception if the median difference between the two is greater than 0.01 arcseconds. """ scratchDir = tempfile.mkdtemp(dir=ROOT, prefix='testOutputWcsOfImage-') catName = os.path.join(scratchDir, 'outputWcs_test_Catalog.dat') imageRoot = os.path.join(scratchDir, 'outputWcs_test_Image') dbFileName = os.path.join(scratchDir, 'outputWcs_test_InputCatalog.dat')
baseDir = os.path.join(getPackageDir('sims_GalSimInterface'), 'tests', 'cameraData') camera = ReturnCamera(baseDir)
detector = camera[0] detName = detector.getName() imageName = '%s_%s_u.fits' % (imageRoot, detName)
nSamples = 3 rng = np.random.RandomState(42) pointingRaList = rng.random_sample(nSamples)*360.0 pointingDecList = rng.random_sample(nSamples)*180.0 - 90.0 rotSkyPosList = rng.random_sample(nSamples)*360.0
for raPointing, decPointing, rotSkyPos in \ zip(pointingRaList, pointingDecList, rotSkyPosList):
obs = ObservationMetaData(pointingRA = raPointing, pointingDec = decPointing, boundType = 'circle', boundLength = 4.0, rotSkyPos = rotSkyPos, mjd = 49250.0)
fwhm = 0.7 create_text_catalog(obs, dbFileName, np.array([3.0]), np.array([1.0]))
db = outputWcsFileDBObj(dbFileName, runtable='test')
cat = outputWcsCat(db, obs_metadata=obs) cat.camera_wrapper = GalSimCameraWrapper(camera)
psf = SNRdocumentPSF(fwhm=fwhm) cat.setPSF(psf)
cat.write_catalog(catName) cat.write_images(nameRoot=imageRoot)
# 20 March 2017 # the 'try' block is how it worked in SWIG; # the 'except' block is how it works in pybind11 try: exposure = afwImage.ExposureD_readFits(imageName) except AttributeError: exposure = afwImage.ExposureD.readFits(imageName)
wcs = exposure.getWcs()
xxTestList = [] yyTestList = []
raImage = [] decImage = []
for xx in np.arange(0.0, 4001.0, 100.0): for yy in np.arange(0.0, 4001.0, 100.0): xxTestList.append(xx) yyTestList.append(yy)
pt = LsstGeom.Point2D(xx, yy) skyPt = wcs.pixelToSky(pt).getPosition(LsstGeom.degrees) raImage.append(skyPt.getX()) decImage.append(skyPt.getY())
xxTestList = np.array(xxTestList) yyTestList = np.array(yyTestList)
raImage = np.radians(np.array(raImage)) decImage = np.radians(np.array(decImage))
raControl, \ decControl = _raDecFromPixelCoords(xxTestList, yyTestList, [detector.getName()]*len(xxTestList), camera=camera, obs_metadata=obs, epoch=2000.0)
errorList = arcsecFromRadians(haversine(raControl, decControl, raImage, decImage))
medianError = np.median(errorList) msg = 'medianError was %e' % medianError self.assertLess(medianError, 0.01, msg=msg)
if os.path.exists(catName): os.unlink(catName) if os.path.exists(dbFileName): os.unlink(dbFileName) if os.path.exists(imageName): os.unlink(imageName)
if os.path.exists(scratchDir): shutil.rmtree(scratchDir)
lsst.utils.tests.init() unittest.main() |