def test_FitsChanFitsTol(self): """Test that increasing FitsTol allows writing a WCS with distortion as FITS-WCS. """ ss = ast.StringStream("".join(self.cards)) fc = ast.FitsChan(ss, "Encoding=FITS-WCS, IWC=1") frameSet = fc.read() distortion = ast.PcdMap(0.001, [0.0, 0.0]) distortedFrameSet = self.insertPixelMapping(distortion, frameSet) # Writing as FTIS-WCS should fail with the default FitsTol fc = writeFitsWcs(distortedFrameSet) self.assertEqual(fc.nCard, 0) # Writing as FITS-WCS should succeed with adequate FitsTol fc2 = writeFitsWcs(distortedFrameSet, "FitsTol=1000") self.assertGreater(fc2.nCard, 9) for i in (1, 2): fv = fc2.getFitsF("CRVAL%d" % (i,)) self.assertAlmostEqual(fv.value, 0) fv2 = fc2.getFitsS("CTYPE1") self.assertEqual(fv2.value, "RA---TAN") fv3 = fc2.getFitsS("CTYPE2") self.assertEqual(fv3.value, "DEC--TAN")
def test_PcdMap(self): coeff = 0.002 ctr = [2, 3] pcdmap = ast.PcdMap(coeff, ctr) self.assertEqual(pcdmap.className, "PcdMap") self.assertIsInstance(pcdmap, ast.PcdMap) self.assertIsInstance(pcdmap, ast.Mapping) self.assertEqual(pcdmap.nIn, 2) self.assertEqual(pcdmap.nOut, 2) self.assertEqual(pcdmap.disco, coeff) assert_allclose(pcdmap.pcdCen, ctr) self.checkBasicSimplify(pcdmap) self.checkCopy(pcdmap) # the center maps to itself assert_allclose(pcdmap.applyForward(ctr), ctr) indata = np.array([ [0.0, -1.0, 4.2], [0.0, 7.3, -5.3], ]) # inverse uses a fit so don't expect too much self.checkRoundTrip(pcdmap, indata, atol=1e-4) self.checkMappingPersistence(pcdmap, indata) outdata = pcdmap.applyForward(indata) # the mapping is: # outrad = inrad*(1 + coeff*inrad^2) # outdir = indir # where radius and direction are relative to the center of distortion inrelctr = (indata.T - ctr).T inrelctrrad = np.hypot(inrelctr[0], inrelctr[1]) inrelctrdir = np.arctan2(inrelctr[1], inrelctr[0]) pred_outrad = inrelctrrad * (1 + coeff * inrelctrrad * inrelctrrad) pred_outrelctr = np.zeros(indata.shape, dtype=float) pred_outrelctr[0, :] = pred_outrad * np.cos(inrelctrdir) pred_outrelctr[1, :] = pred_outrad * np.sin(inrelctrdir) pred_outdata = pred_outrelctr + np.expand_dims(ctr, 1) assert_allclose(outdata, pred_outdata)
def test_PcdMapBadConstruction(self): with self.assertRaises(Exception): ast.PcdMap(0.5, [1, 2, 3]) with self.assertRaises(Exception): ast.PcdMap(0.5, [1])