22 __all__ = (
'InitialSkyWcsError',
'createInitialSkyWcs',
'createInitialSkyWcsFromBoresight',
'bboxFromIraf')
25 import lsst.geom
as geom
27 from .
import Instrument
28 from lsst.afw.cameraGeom
import PIXELS, FIELD_ANGLE
29 from lsst.afw.image
import RotType
30 from lsst.afw.geom.skyWcs
import makeSkyWcs
36 """For handling failures when creating a SkyWcs from a camera geometry and
39 Typically used as a chained exception from a lower level exception.
45 """Create a SkyWcs from the visit information and detector geometry.
47 A typical usecase for this is to create the initial WCS for a newly-read
53 visitInfo : `lsst.afw.image.VisitInfo`
54 Where to get the telescope boresight and rotator angle from.
55 detector : `lsst.afw.cameraGeom.Detector`
56 Where to get the camera geomtry from.
57 flipX : `bool`, optional
58 If False, +X is along W, if True +X is along E.
62 skyWcs : `lsst.afw.geom.SkyWcs`
68 Raised if there is an error generating the SkyWcs, chained from the
69 lower-level exception if available.
71 if visitInfo.getRotType() != RotType.SKY:
72 msg = (f
"Cannot create SkyWcs from camera geometry: rotator angle defined using "
73 f
"RotType={visitInfo.getRotType()} instead of SKY.")
75 orientation = visitInfo.getBoresightRotAngle()
76 boresight = visitInfo.getBoresightRaDec()
81 """Create a SkyWcs from the telescope boresight and detector geometry.
83 A typical usecase for this is to create the initial WCS for a newly-read
88 boresight : `lsst.geom.SpherePoint`
89 The ICRS boresight RA/Dec
90 orientation : `lsst.geom.Angle`
91 The rotation angle of the focal plane on the sky.
92 detector : `lsst.afw.cameraGeom.Detector`
93 Where to get the camera geomtry from.
94 flipX : `bool`, optional
95 If False, +X is along W, if True +X is along E.
99 skyWcs : `lsst.afw.geom.SkyWcs`
100 The new composed WCS.
105 Raised if there is an error generating the SkyWcs, chained from the
106 lower-level exception if available.
109 pixelsToFieldAngle = detector.getTransform(detector.makeCameraSys(PIXELS),
110 detector.makeCameraSys(FIELD_ANGLE))
113 return makeSkyWcs(pixelsToFieldAngle, orientation, flipX, boresight)
117 """Return a Box2I corresponding to an IRAF-style BBOX
119 [x0:x1,y0:y1] where x0 and x1 are the one-indexed start and end columns,
120 and correspondingly y0 and y1 are the start and end rows.
123 mat = re.search(
r"^\[([-\d]+):([-\d]+),([-\d]+):([-\d]+)\]$", irafBBoxStr)
125 raise RuntimeError(
"Unable to parse IRAF-style bbox \"%s\"" % irafBBoxStr)
126 x0, x1, y0, y1 = [int(_)
for _
in mat.groups()]
128 return geom.BoxI(geom.PointI(x0 - 1, y0 - 1), geom.PointI(x1 - 1, y1 - 1))
132 """Return an instance of a named instrument.
134 If the instrument name not is qualified (does not contain a '.') and a
135 butler registry is provided, this will attempt to load the instrument using
136 Instrument.fromName. Otherwise the instrument will be imported and
141 instrumentName : string
142 The name or fully-qualified class name of an instrument.
143 registry : `lsst.daf.butler.Registry`, optional
144 Butler registry to query to find information about the instrument, by
149 Instrument subclass instance
150 The instantiated instrument.
155 If the instrument can not be imported, instantiated, or obtained from
158 If the instrument is not a subclass of lsst.obs.base.Instrument.
160 if "." not in instrumentName
and registry
is not None:
162 instr = Instrument.fromName(instrumentName, registry)
163 except Exception
as err:
165 f
"Could not get instrument from name: {instrumentName}. Failed with exception: {err}")
168 instr = doImport(instrumentName)
169 except Exception
as err:
170 raise RuntimeError(f
"Could not import instrument: {instrumentName}. Failed with exception: {err}")
172 if not isinstance(instr, Instrument):
173 raise TypeError(f
"{instrumentName} is not an Instrument subclass.")
180 """Set an instance attribute (like `setattr` but accepting hierarchical
181 names such as ``foo.bar.baz``) If the attribute can not be set as a string,
182 will attempt to set the attribute with the result of eval'ing the value.
187 Object whose attribute is to be set.
189 Name of attribute to set.
191 New value for the attribute.
195 For example if name is ``foo.bar.baz`` then ``item.foo.bar.baz``
196 is set to the specified value.
201 If the item does not have a field specified by name that can be set.
203 If the value can not be set as a string or rendered by eval, or if
204 there is an error setting the attribute with the rendered value.
207 subnameList = name.split(
".")
208 for subname
in subnameList[:-1]:
209 subitem = getattr(subitem, subname)
211 setattr(subitem, subnameList[-1], value)
212 except AttributeError:
213 raise AttributeError(f
"No field: {name!r}")
218 raise RuntimeError(f
"Cannot render {value!r} as a value for {name!r}")
220 setattr(subitem, subnameList[-1], v)
221 except Exception
as e:
222 raise RuntimeError(f
"Cannot set config. {name}={value!r}: {e}")
226 for name, value
in attrs: