22 __all__ = (
'InitialSkyWcsError',
'createInitialSkyWcs',
'bboxFromIraf')
27 from .
import Instrument
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 telescope boresight 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()
78 pixelsToFieldAngle = detector.getTransform(detector.makeCameraSys(PIXELS),
79 detector.makeCameraSys(FIELD_ANGLE))
82 return makeSkyWcs(pixelsToFieldAngle, orientation, flipX, boresight)
86 """Return a Box2I corresponding to an IRAF-style BBOX
88 [x0:x1,y0:y1] where x0 and x1 are the one-indexed start and end columns, and correspondingly
89 y0 and y1 are the start and end rows.
92 mat = re.search(
r"^\[([-\d]+):([-\d]+),([-\d]+):([-\d]+)\]$", irafBBoxStr)
94 raise RuntimeError(
"Unable to parse IRAF-style bbox \"%s\"" % irafBBoxStr)
95 x0, x1, y0, y1 = [int(_)
for _
in mat.groups()]
101 """Return an instance of a named instrument.
103 If the instrument name not is qualified (does not contain a '.') and a
104 butler registry is provided, this will attempt to load the instrument using
105 Instrument.fromName. Otherwise the instrument will be imported and
110 instrumentName : string
111 The name or fully-qualified class name of an instrument.
112 registry : `lsst.daf.butler.Registry`, optional
113 Butler registry to query to find information about the instrument, by
118 Instrument subclass instance
119 The instantiated instrument.
124 If the instrument can not be imported, instantiated, or obtained from
127 If the instrument is not a subclass of lsst.obs.base.Instrument.
129 if "." not in instrumentName
and registry
is not None:
131 instr = Instrument.fromName(instrumentName, registry)
132 except Exception
as err:
134 f
"Could not get instrument from name: {instrumentName}. Failed with exception: {err}")
138 except Exception
as err:
139 raise RuntimeError(f
"Could not import instrument: {instrumentName}. Failed with exception: {err}")
141 if not isinstance(instr, Instrument):
142 raise TypeError(f
"{instrumentName} is not an Instrument subclass.")
149 """Set an instance attribute (like `setattr` but accepting hierarchical
150 names such as ``foo.bar.baz``) If the attribute can not be set as a string,
151 will attempt to set the attribute with the result of eval'ing the value.
156 Object whose attribute is to be set.
158 Name of attribute to set.
160 New value for the attribute.
164 For example if name is ``foo.bar.baz`` then ``item.foo.bar.baz``
165 is set to the specified value.
170 If the item does not have a field specified by name that can be set.
172 If the value can not be set as a string or rendered by eval, or if
173 there is an error setting the attribute with the rendered value.
176 subnameList = name.split(
".")
177 for subname
in subnameList[:-1]:
178 subitem = getattr(subitem, subname)
180 setattr(subitem, subnameList[-1], value)
181 except AttributeError:
182 raise AttributeError(f
"No field: {name!r}")
187 raise RuntimeError(f
"Cannot render {value!r} as a value for {name!r}")
189 setattr(subitem, subnameList[-1], v)
190 except Exception
as e:
191 raise RuntimeError(f
"Cannot set config. {name}={value!r}: {e}")
195 for name, value
in attrs: