22 __all__ = (
'InitialSkyWcsError',
'createInitialSkyWcs',
'bboxFromIraf')
25 import lsst.geom
as geom
27 from lsst.afw.cameraGeom
import PIXELS, FIELD_ANGLE
28 from lsst.afw.image
import RotType
29 from lsst.afw.geom.skyWcs
import makeSkyWcs
34 """For handling failures when creating a SkyWcs from a camera geometry and
37 Typically used as a chained exception from a lower level exception.
43 """Create a SkyWcs from the telescope boresight and detector geometry.
45 A typical usecase for this is to create the initial WCS for a newly-read
51 visitInfo : `lsst.afw.image.VisitInfo`
52 Where to get the telescope boresight and rotator angle from.
53 detector : `lsst.afw.cameraGeom.Detector`
54 Where to get the camera geomtry from.
55 flipX : `bool`, optional
56 If False, +X is along W, if True +X is along E.
60 skyWcs : `lsst.afw.geom.SkyWcs`
66 Raised if there is an error generating the SkyWcs, chained from the
67 lower-level exception if available.
69 if visitInfo.getRotType() != RotType.SKY:
70 msg = (f
"Cannot create SkyWcs from camera geometry: rotator angle defined using "
71 f
"RotType={visitInfo.getRotType()} instead of SKY.")
73 orientation = visitInfo.getBoresightRotAngle()
74 boresight = visitInfo.getBoresightRaDec()
76 pixelsToFieldAngle = detector.getTransform(detector.makeCameraSys(PIXELS),
77 detector.makeCameraSys(FIELD_ANGLE))
80 return makeSkyWcs(pixelsToFieldAngle, orientation, flipX, boresight)
84 """Return a Box2I corresponding to an IRAF-style BBOX
86 [x0:x1,y0:y1] where x0 and x1 are the one-indexed start and end columns, and correspondingly
87 y0 and y1 are the start and end rows.
90 mat = re.search(
r"^\[([-\d]+):([-\d]+),([-\d]+):([-\d]+)\]$", irafBBoxStr)
92 raise RuntimeError(
"Unable to parse IRAF-style bbox \"%s\"" % irafBBoxStr)
93 x0, x1, y0, y1 = [int(_)
for _
in mat.groups()]
95 return geom.BoxI(geom.PointI(x0 - 1, y0 - 1), geom.PointI(x1 - 1, y1 - 1))