Coverage for python/lsst/obs/sdss/convertpsField.py : 50%

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/>. #
# Mapping from psField coefficient locations to PolynomialFunction2 locations 0, 2, 5, 9, 14, 1, 4, 8, 13, 19, 3, 7, 12, 18, 25, 6, 11, 17, 24, 32, 10, 16, 23, 31, 40, ]
print("INVALID FILTER", filt) sys.exit(1)
# This is *not* transposed
# NOTES:
# Afw has the polynomial terms like: # # * f(x,y) = c0 (0th order) # * + c1 x + c2 y (1st order) # * + c3 x^2 + c4 x y + c5 y^2 (2nd order) # * + c6 x^3 + c7 x^2 y + c8 x y^2 + c9 y^3 (3rd order) # * + c10 x^4 + c11 x^3 y + c12 x^2 y^2 + c13 x y^3 + c14 y^4 (4th order) # # So, ordered: x^0,y^0 x^1,y^0 x^0,y^1 x^2,y^0 x^1,y^1 x^0,y^2
# SDSS has the terms ordered like, after reshape(): # # x^0,y^0 x^0,y^1 x^0,y^2 # x^1,y^0 x^1,y^1 x^1,y^2 # x^2,y^0 x^2,y^1 x^2,y^2 # # So, it technically goes up to fourth order in LSST-speak. OK, that is the trick. # # Mapping: # cmat[0][0] = c0 x^0y^0 # cmat[1][0] = c2 x^0y^1 # cmat[2][0] = c5 x^0y^2 # cmat[0][1] = c1 x^1y^0 # cmat[1][1] = c4 x^1y^1 # cmat[2][1] = c8 x^1y^2 # cmat[0][2] = c3 x^2y^0 # cmat[1][2] = c7 x^2y^1 # cmat[2][2] = c12 x^2y^2 # # This is quantified in skMatrixPos2TriSeqPosT
# Was originally written like this, but the SDSS code # takes inputs as y,x instead of x,y meaning it was # originally transposed # # idx = row * MAX_ORDER_B + col
# print "%d y=%d x=%d %10.3e %2d %2d %10.3e" % \ # (i, row, col, cmat[row,col], idx, skMatrixPos2TriSeqPosT[idx], scaledCoeff)
# print spaParamsTri
if filt not in filtToHdu.keys(): print("INVALID FILTER", filt) sys.exit(1)
# Make the kernel image from LSST psf = convertpsField(infile, filt, trim=False) kernel = psf.getKernel()
# Assumes you have built dervish and have read_PSF in your path # # read_PSF takes coordinates in the order row,col or y,x cmd = "read_PSF %s %s %f %f %s" % (infile, filtToHdu[filt], y, x, outfile) os.system(cmd) if not os.path.isfile(outfile): print("Cannot find SDSS-derived kernel", outfile) sys.exit(1)
if False: # Default version that integerizes Psf kImage1 = afwImage.ImageD(outfile) kImage1 -= soft_bias kImage1 /= (amp - soft_bias) maxVal = afwMath.makeStatistics(kImage1, afwMath.MAX).getValue(afwMath.MAX) print("TEST 1", maxVal == 1.0) kImage1.writeFits("/tmp/sdss_psf_scaled.fits") else: # Hacked version of main_PSF.c that writes floats kImage1 = afwImage.ImageD(outfile) maxVal = afwMath.makeStatistics(kImage1, afwMath.MAX).getValue(afwMath.MAX) kImage1 /= maxVal kImage1.writeFits("/tmp/sdss_psf_scaled.fits")
# kImage2 = afwImage.ImageD(kernel.getDimensions()) kernel.computeImage(kImage2, True, x, y) maxVal = afwMath.makeStatistics(kImage2, afwMath.MAX).getValue(afwMath.MAX) kImage2 /= maxVal kImage2.writeFits("/tmp/kernel.fits")
kImage3 = afwImage.ImageD(kImage2, True) kImage3 -= kImage1 kImage3.writeFits("/tmp/diff.fits") residSum = afwMath.makeStatistics(kImage3, afwMath.SUM).getValue(afwMath.SUM) print("TEST 2", residSum)
kImage4 = afwImage.ImageD(kImage2, True) kImage4 /= kImage1 kImage4.writeFits("/tmp/rat.fits")
infile = sys.argv[1] filt = sys.argv[2] x = float(sys.argv[3]) # col y = float(sys.argv[4]) # row outfile = sys.argv[5]
if not os.path.isfile(infile): sys.exit(1)
if DEBUG: directCompare(infile, filt, x, y) else: psf = convertpsField(infile, filt) kernel = psf.getKernel() kImage = afwImage.ImageD(kernel.getDimensions()) kernel.computeImage(kImage, True, x, y) kImage.writeFits(outfile)
# Persist the kernel at your own leisure |