Coverage for tests/test_fitTanSipWcsTask.py : 72%

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
# LSST Data Management System # Copyright 2008, 2009, 2010 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. # # The classes in this test are a little non-standard to reduce code # duplication and support automated unittest discovery. # A base class includes all the code that implements the testing and # itself inherits from unittest.TestCase. unittest automated discovery # will scan all classes that inherit from unittest.TestCase and invoke # any test methods found. To prevent this base class from being executed # the test methods are placed in a different class that does not inherit # from unittest.TestCase. The actual test classes then inherit from # both the testing class and the implementation class allowing test # discovery to only run tests found in the subclasses.
"""A test case for CreateWcsWithSip
Use involves setting one class attribute: * MatchClass: match class, e.g. ReferenceMatch or SourceMatch
This test is a bit messy because it exercises two templatings of makeCreateWcsWithSip, the underlying TAN-SIP WCS fitter, but only one of those is supported by FitTanSipWcsTask """
"""Load catalogs and make the match list
This is a separate function so data can be reloaded if fitting more than once (each time a WCS is fit it may update the source catalog, reference catalog and match list) """ filterNameList=["r"], addFluxSigma=True, addIsPhotometric=True) else: raise RuntimeError("Unsupported MatchClass=%r" % (self.MatchClass,))
if False: print("x,y = (%.1f, %.1f) pixels -- RA,Dec = (%.3f, %.3f) deg" % (i, j, c.toFk5().getRa().asDegrees(), c.toFk5().getDec().asDegrees()))
"""Check results
@param[in] fitRes a object with two fields: - wcs fit TAN-SIP WCS, an lsst.afw.geom.SkyWcs - scatterOnSky median on-sky scatter, an lsst.afw.geom.Angle @param[in] catsUpdated if True then coord field of self.sourceCat and centroid fields of self.refCat have been updated """ else:
else: "Computed distance in match list is off by %s arcsec" % (maxDistErr.asArcseconds(),))
"""Apply func(x, y) to each source in self.sourceCat, then fit and check the resulting WCS """
sipObject = makeCreateWcsWithSip(self.matches, tanSipWcs, order, bbox) else: wcs=tanSipWcs, scatterOnSky=sipObject.getScatterOnSky(), )
crpix=tanSipWcs.getPixelOrigin(), crval=tanSipWcs.getSkyOrigin(), cdMatrix=tanSipWcs.getCdMatrix(), sipA=sipObject.getSipA(), sipB=sipObject.getSipB(), sipAp=sipObject.getSipAp(), sipBp=sipObject.getSipBp(), )
self.plotWcs(tanSipWcs, name=name)
# reset source coord and reference centroid based on initial WCS
fitRes = fitter.fitWcs( matches=self.matches, initWcs=self.tanWcs, bbox=bbox, refCat=self.refCat, sourceCat=self.sourceCat, ) else: matches=self.matches, initWcs=self.tanWcs, bbox=bbox, refCat=self.refCat, sourceCat=self.sourceCat, )
import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt fileNamePrefix = "testCreateWcsWithSip_%s_%s" % (self.MatchClass.__name__, name) pnum = 1
xs, ys, xc, yc = [], [], [], [] rs, ds, rc, dc = [], [], [], [] for ref, src, d in self.matches: xs.append(src.getX()) ys.append(src.getY()) refPixPos = tanSipWcs.skyToPixel(ref.getCoord()) xc.append(refPixPos[0]) yc.append(refPixPos[1]) rc.append(ref.getRa()) dc.append(ref.getDec()) srd = tanSipWcs.pixelToSky(src.get(self.srcCentroidKey)) rs.append(srd.getRa()) ds.append(srd.getDec()) xs = np.array(xs) ys = np.array(ys) xc = np.array(xc) yc = np.array(yc)
plt.clf() plt.plot(xs, ys, "r.") plt.plot(xc, yc, "bx") fileName = "%s_%i.png" % (fileNamePrefix, pnum) plt.savefig(fileName) print("Wrote", fileName) pnum += 1
plt.clf() plt.plot(xs, xc-xs, "b.") fileName = "%s_%i.png" % (fileNamePrefix, pnum) plt.xlabel("x(source)") plt.ylabel("x(ref - src)") plt.savefig(fileName) print("Wrote", fileName) pnum += 1
plt.clf() plt.plot(rs, ds, "r.") plt.plot(rc, dc, "bx") fileName = "%s_%i.png" % (fileNamePrefix, pnum) plt.savefig(fileName) print("Wrote", fileName) pnum += 1
plt.clf() for y in np.linspace(0, 4000, 5): x0, y0 = [], [] x1, y1 = [], [] for x in np.linspace(0., 4000., 401): x0.append(x) y0.append(y) rd = tanSipWcs.pixelToSky(x, y) xy = tanSipWcs.skyToPixel(rd) x1.append(xy[0]) y1.append(xy[1]) x0 = np.array(x0) x1 = np.array(x1) plt.plot(x0, x1-x0, "b-") fileName = "%s_%i.png" % (fileNamePrefix, pnum) plt.savefig(fileName) print("Wrote", fileName) pnum += 1
"""Base class implementations of testing methods.
Explicitly does not inherit from unittest.TestCase"""
"""Add no distortion"""
"""Add an offset"""
"""Scale x, offset y"""
"""Scale x and y"""
"""Add an offset to each point; scale in y and x"""
"""Add quadratic distortion in x"""
"""Add radial distortion"""
# The test classes inherit from two base classes and differ in the match # class being used.
lsst.utils.tests.init() unittest.main() |