Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-10765: Replace existing WCS classes with SkyWcs #39

Merged
merged 4 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin.src/genCoaddRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import sqlite3
import sys
from lsst.afw.fits import readMetadata
import lsst.afw.image as afwImage
from lsst.afw.geom import makeSkyWcs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no specific reason not to, I do prefer import ... as ... (as opposed to from ... import ...) so that it is more obvious where the function comes from when used far away from the import statements.

import lsst.skypix as skypix


Expand Down Expand Up @@ -107,7 +107,7 @@ def processBand(filterDir, conn, done, qsp):
id = row[0]
break

wcs = afwImage.makeWcs(md)
wcs = makeSkyWcs(md)
poly = skypix.imageToPolygon(wcs,
md.get("NAXIS1"), md.get("NAXIS2"),
padRad=0.000075) # about 15 arcsec
Expand Down
4 changes: 2 additions & 2 deletions bin.src/genInputRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import sys
import lsst.daf.base as dafBase
from lsst.afw.fits import readMetadata
import lsst.afw.image as afwImage
from lsst.afw.geom import makeSkyWcs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

import lsst.skypix as skypix


Expand Down Expand Up @@ -131,7 +131,7 @@ def processRun(runDir, conn, done, qsp):
id = row[0]
break

wcs = afwImage.makeWcs(md)
wcs = makeSkyWcs(md)
poly = skypix.imageToPolygon(wcs,
md.get("NAXIS1"), md.get("NAXIS2"),
padRad=0.000075) # about 15 arcsec
Expand Down
2 changes: 1 addition & 1 deletion policy/SdssMapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ datasets:
template: '%(run)d/%(rerun)d/objcs/%(camcol)d/psField-%(run)06d-%(camcol)d-%(field)04d.fit'
asTrans:
persistable: ignored
python: lsst.afw.image.Wcs
python: lsst.afw.geom.skyWcs.SkyWcs
storage: FitsStorage
tables: raw
template: '%(run)d/%(rerun)d/astrom/asTrans-%(run)06d.fit'
Expand Down
16 changes: 10 additions & 6 deletions python/lsst/obs/sdss/convertasTrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import lsst.afw.image as afwImage
import lsst.afw.geom as afwGeom
from lsst.afw.geom import makeSkyWcs
import lsst.afw.coord as afwCoord
import lsst.afw.table as afwTable
import lsst.meas.astrom.sip as sip
Expand Down Expand Up @@ -151,7 +152,7 @@ def createWcs(x, y, mapper, order=4, cOffset=1.0):

# CRVAL1 = RA at Reference Pixel
# CRVAL2 = DEC at Reference Pixel
crval = afwCoord.Coord(afwGeom.Point2D(ra_rad[0], dec_rad[0]), afwGeom.radians)
crval = afwCoord.IcrsCoord(afwGeom.Point2D(ra_rad[0], dec_rad[0]), afwGeom.radians)

# CD1_1 = RA degrees per column pixel
# CD1_2 = RA degrees per row pixel
Expand All @@ -161,16 +162,19 @@ def createWcs(x, y, mapper, order=4, cOffset=1.0):
ULl = mapper.xyToRaDec(0., 1.)
LRl = mapper.xyToRaDec(1., 0.)

LLc = afwCoord.Coord(afwGeom.Point2D(LLl[0], LLl[1]), afwGeom.radians)
ULc = afwCoord.Coord(afwGeom.Point2D(ULl[0], ULl[1]), afwGeom.radians)
LRc = afwCoord.Coord(afwGeom.Point2D(LRl[0], LRl[1]), afwGeom.radians)
LLc = afwCoord.IcrsCoord(afwGeom.Point2D(LLl[0], LLl[1]), afwGeom.radians)
ULc = afwCoord.IcrsCoord(afwGeom.Point2D(ULl[0], ULl[1]), afwGeom.radians)
LRc = afwCoord.IcrsCoord(afwGeom.Point2D(LRl[0], LRl[1]), afwGeom.radians)

cdN_1 = LLc.getTangentPlaneOffset(LRc)
cdN_2 = LLc.getTangentPlaneOffset(ULc)
cd1_1, cd2_1 = cdN_1[0].asDegrees(), cdN_1[1].asDegrees()
cd1_2, cd2_2 = cdN_2[0].asDegrees(), cdN_2[1].asDegrees()

linearWcs = afwImage.makeWcs(crval, crpix, cd1_1, cd2_1, cd1_2, cd2_2)
cdMatrix = np.array([cd1_1, cd2_1, cd1_2, cd2_2], dtype=float)
cdMatrix.shape = (2, 2)

linearWcs = makeSkyWcs(crpix=crpix, crval=crval, cdMatrix=cdMatrix)
wcs = sip.makeCreateWcsWithSip(matches, linearWcs, order).getNewWcs()

return wcs
Expand All @@ -180,7 +184,7 @@ def validate(xs, ys, mapper, wcs):
dists = []
for i in range(len(xs)):
tuple1 = mapper.xyToRaDec(xs[i], ys[i])
coord1 = afwCoord.Coord(afwGeom.Point2D(tuple1[0], tuple1[1]), afwGeom.radians)
coord1 = afwCoord.IcrsCoord(afwGeom.Point2D(tuple1[0], tuple1[1]), afwGeom.radians)
coord2 = wcs.pixelToSky(xs[i], ys[i])
dist = coord1.angularSeparation(coord2).asArcseconds()
dists.append(dist)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_sdss.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import lsst.daf.persistence as dafPersist
from lsst.daf.base import DateTime
import lsst.afw.image
from lsst.afw.coord import IcrsCoord
from lsst.afw.geom import SkyWcs
from lsst.afw.geom import degrees
import lsst.afw.detection


Expand Down Expand Up @@ -68,10 +71,12 @@ def testGetDR7(self):
self.assertEqual(h, 31)

wcs = ref.get("asTrans")
self.assertEqual(wcs.__class__, lsst.afw.image.TanWcs)
self.assertFalse(wcs.isFlipped())
self.assertAlmostEqual(wcs.getFitsMetadata().get("CRPIX1"), 1.0, 5)
self.assertAlmostEqual(wcs.getFitsMetadata().get("CRPIX2"), 1.0, 5)
self.assertIsInstance(wcs, SkyWcs)
self.assertFalse(wcs.isFlipped)
# comparison is to results from lsst.afw.image.TanWcs class
self.assertCoordsAlmostEqual(wcs.pixelToSky(700, 1000),
IcrsCoord(343.6507738304687 * degrees,
-0.3509870420713227 * degrees))

tsField = ref.get("tsField")
self.assertAlmostEqual(tsField.gain, 4.72, 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_selectFluxMag0.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def makeTestExposure(self, xNumPix=2060, yNumPix=1967):
metadata.set("LTV1", -341970)
metadata.set("LTV2", -11412)
# exposure needs a wcs and a bbox
wcs = afwImage.makeWcs(metadata)
wcs = afwGeom.makeSkyWcs(metadata)
bbox = afwGeom.Box2I(afwGeom.Point2I(341970, 11412), afwGeom.Extent2I(xNumPix, yNumPix))
exposure = afwImage.ExposureF(bbox, wcs)
mi = exposure.getMaskedImage()
Expand Down