LSSTApplications  17.0+103,17.0+11,17.0+61,18.0.0+13,18.0.0+25,18.0.0+5,18.0.0+52,18.0.0-4-g68ffd23,18.1.0-1-g0001055+8,18.1.0-1-g03d53ef+1,18.1.0-1-g1349e88+28,18.1.0-1-g2505f39+22,18.1.0-1-g380d4d4+27,18.1.0-1-g5315e5e+1,18.1.0-1-g5e4b7ea+10,18.1.0-1-g7e8fceb+1,18.1.0-1-g85f8cd4+23,18.1.0-1-g9a6769a+13,18.1.0-1-ga1a4c1a+22,18.1.0-1-gd55f500+17,18.1.0-12-g42eabe8e+10,18.1.0-14-gd04256d+15,18.1.0-16-g430f6a53+1,18.1.0-17-gd2166b6e4,18.1.0-18-gb5d19ff+1,18.1.0-2-gfbf3545+7,18.1.0-2-gfefb8b5+16,18.1.0-3-g52aa583+13,18.1.0-3-g62b5e86+14,18.1.0-3-g8f4a2b1+17,18.1.0-3-g9bc06b8+7,18.1.0-3-gb69f684+9,18.1.0-4-g1ee41a7+1,18.1.0-5-g6dbcb01+13,18.1.0-5-gc286bb7+3,18.1.0-6-g48bdcd3+2,18.1.0-6-gd05e160+9,18.1.0-7-gc4d902b+2,18.1.0-7-gebc0338+8,18.1.0-9-gae7190a+10,w.2019.38
LSSTDataManagementBasePackage
utils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2017 AURA/LSST
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 __all__ = ('InitialSkyWcsError', 'createInitialSkyWcs', 'bboxFromIraf')
24 
25 import re
26 import lsst.geom as geom
27 
28 from lsst.afw.cameraGeom import PIXELS, FIELD_ANGLE
29 from lsst.afw.image import RotType
30 from lsst.afw.geom.skyWcs import makeSkyWcs
32 
33 
34 class InitialSkyWcsError(Exception):
35  """For handling failures when creating a SkyWcs from a camera geometry and
36  boresight.
37 
38  Typically used as a chained exception from a lower level exception.
39  """
40  pass
41 
42 
43 def createInitialSkyWcs(visitInfo, detector, flipX=False):
44  """Create a SkyWcs from the telescope boresight and detector geometry.
45 
46  A typical usecase for this is to create the initial WCS for a newly-read
47  raw exposure.
48 
49 
50  Parameters
51  ----------
52  visitInfo : `lsst.afw.image.VisitInfo`
53  Where to get the telescope boresight and rotator angle from.
54  detector : `lsst.afw.cameraGeom.Detector`
55  Where to get the camera geomtry from.
56  flipX : `bool`, optional
57  If False, +X is along W, if True +X is along E.
58 
59  Returns
60  -------
61  skyWcs : `lsst.afw.geom.SkyWcs`
62  The new composed WCS.
63 
64  Raises
65  ------
66  InitialSkyWcsError
67  Raised if there is an error generating the SkyWcs, chained from the
68  lower-level exception if available.
69  """
70  if visitInfo.getRotType() != RotType.SKY:
71  msg = (f"Cannot create SkyWcs from camera geometry: rotator angle defined using "
72  f"RotType={visitInfo.getRotType()} instead of SKY.")
73  raise InitialSkyWcsError(msg)
74  orientation = visitInfo.getBoresightRotAngle()
75  boresight = visitInfo.getBoresightRaDec()
76  try:
77  pixelsToFieldAngle = detector.getTransform(detector.makeCameraSys(PIXELS),
78  detector.makeCameraSys(FIELD_ANGLE))
80  raise InitialSkyWcsError("Cannot compute PIXELS to FIELD_ANGLE Transform.") from e
81  return makeSkyWcs(pixelsToFieldAngle, orientation, flipX, boresight)
82 
83 
84 def bboxFromIraf(irafBBoxStr):
85  """Return a Box2I corresponding to an IRAF-style BBOX
86 
87  [x0:x1,y0:y1] where x0 and x1 are the one-indexed start and end columns, and correspondingly
88  y0 and y1 are the start and end rows.
89  """
90 
91  mat = re.search(r"^\[([-\d]+):([-\d]+),([-\d]+):([-\d]+)\]$", irafBBoxStr)
92  if not mat:
93  raise RuntimeError("Unable to parse IRAF-style bbox \"%s\"" % irafBBoxStr)
94  x0, x1, y0, y1 = [int(_) for _ in mat.groups()]
95 
96  return geom.BoxI(geom.PointI(x0 - 1, y0 - 1), geom.PointI(x1 - 1, y1 - 1))
def createInitialSkyWcs(visitInfo, detector, flipX=False)
Definition: utils.py:43
def bboxFromIraf(irafBBoxStr)
Definition: utils.py:84
std::shared_ptr< SkyWcs > makeSkyWcs(daf::base::PropertySet &metadata, bool strip=false)
Construct a SkyWcs from FITS keywords.
Definition: SkyWcs.cc:506
Reports invalid arguments.
Definition: Runtime.h:66
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
An integer coordinate rectangle.
Definition: Box.h:54