31 """Convert an `lsst.images` object to its afw equivalent for display.
36 Data to display. If this is an `lsst.images.MaskedImage` (including
37 subclasses such as `~lsst.images.VisitImage` and
38 `~lsst.images.cells.CellCoadd`), `lsst.images.Image`, or
39 `lsst.images.Mask`, it is converted to the corresponding
40 `lsst.afw.image` type; anything else is returned unchanged.
41 wcs : `lsst.afw.geom.SkyWcs` or `None`, optional
42 WCS supplied by the caller.
47 The converted afw object, or the input unchanged.
48 wcs : `lsst.afw.geom.SkyWcs` or `None`
49 The WCS converted from ``data.sky_projection`` if present, else the
50 caller-supplied ``wcs``.
55 Raised if ``wcs`` is not `None` and ``data`` has its own
60 ``lsst.images`` is deliberately never imported here: it optionally
61 depends on afw, so the dependency cannot go the other way. If the
62 module has never been imported, the caller cannot be holding one of
63 its objects, so looking it up in `sys.modules` is sufficient.
65 Only the image and mask planes are ever forwarded to display backends,
66 so PSFs, variance, and other components are never serialized for
67 display. Mask schemas with more than 31 named planes cannot be
68 represented as an `lsst.afw.image.Mask` and fail conversion.
70 images = sys.modules.get(
"lsst.images")
71 if images
is None or not isinstance(data, (images.MaskedImage, images.Image, images.Mask)):
74 if data.sky_projection
is not None:
77 "You may not specify a wcs with an lsst.images object that has its own sky_projection"
79 wcs = data.sky_projection.to_legacy()
81 if isinstance(data, images.MaskedImage):
83 data.image.to_legacy(),
84 mask=data.mask.to_legacy(),
85 variance=data.variance.to_legacy(),
86 dtype=data.image.array.dtype,
90 data = data.to_legacy()