Ejemplo n.º 1
0
def showAmp(amp,
            imageSource=FakeImageDataSource(isTrimmed=False),
            display=None,
            overlay=True,
            imageFactory=afwImage.ImageU):
    """Show an amp in an image display.

    Parameters
    ----------
    amp : `lsst.afw.tables.AmpInfoRecord`
        Amp record to use in display.
    imageSource : `FakeImageDataSource` or None
        Source for getting the amp image.  Must have a ``getAmpImage()`` method.
    display : `lsst.afw.display.Display`
        Image display to use.
    overlay : `bool`
        Overlay bounding boxes?
    imageFactory : callable like `lsst.afw.image.Image`
        Type of image to display (only used if ampImage is None).
    """

    if not display:
        display = _getDisplayFromDisplayOrFrame()

    ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
    ampImSize = ampImage.getDimensions()
    title = amp.getName()
    display.mtv(ampImage, title=title)
    if overlay:
        with display.Buffering():
            if amp.getHasRawInfo() and ampImSize == amp.getRawBBox(
            ).getDimensions():
                bboxes = [
                    (amp.getRawBBox(), 0.49, afwDisplay.GREEN),
                ]
                xy0 = bboxes[0][0].getMin()
                bboxes.append(
                    (amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
                bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
                bboxes.append(
                    (amp.getRawPrescanBBox(), 0.49, afwDisplay.YELLOW))
                bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49,
                               afwDisplay.MAGENTA))
            else:
                bboxes = [
                    (amp.getBBox(), 0.49, None),
                ]
                xy0 = bboxes[0][0].getMin()

            for bbox, borderWidth, ctype in bboxes:
                if bbox.isEmpty():
                    continue
                bbox = lsst.geom.Box2I(bbox)
                bbox.shift(-lsst.geom.ExtentI(xy0))
                displayUtils.drawBBox(bbox,
                                      borderWidth=borderWidth,
                                      ctype=ctype,
                                      display=display)
Ejemplo n.º 2
0
def showCcd(ccd, imageSource=FakeImageDataSource(), display=None, frame=None, overlay=True,
            imageFactory=afwImage.ImageF, binSize=1, inCameraCoords=False):
    """Show a CCD on display.

    Parameters
    ----------
    ccd : `lsst.afw.cameraGeom.Detector`
        Detector to use in display.
    imageSource : `FakeImageDataSource` or `None`
        Source to get ccd images.  Must have a ``getCcdImage()`` method.
    display : `lsst.afw.display.Display`
        image display to use.
    frame : `None`
        frame ID on which to display. **Deprecated** in v12.
    overlay : `bool`
        Show amp bounding boxes on the displayed image?
    imageFactory : callable like `lsst.afw.image.Image`
        The image factory to use in generating the images.
    binSize : `int`
        Bin the image by this factor in both dimensions.
    inCameraCoords : `bool`
        Show the Detector in camera coordinates?
    """
    if frame is not None:
        warnings.warn("The frame kwarg is deprecated; use the `lsst.afw.display` system instead.",
                      DeprecationWarning)

    display = _getDisplayFromDisplayOrFrame(display, frame)

    ccdOrigin = lsst.geom.Point2I(0, 0)
    nQuarter = 0
    ccdImage, ccd = imageSource.getCcdImage(
        ccd, imageFactory=imageFactory, binSize=binSize)

    ccdBbox = ccdImage.getBBox()
    if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
        isTrimmed = True
    else:
        isTrimmed = False

    if inCameraCoords:
        nQuarter = ccd.getOrientation().getNQuarter()
        ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
    title = ccd.getName()
    if isTrimmed:
        title += "(trimmed)"

    if display:
        display.mtv(ccdImage, title=title)

        if overlay:
            overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed,
                            ccdOrigin, display, binSize)

    return ccdImage
Ejemplo n.º 3
0
def showCcd(ccd,
            imageSource=FakeImageDataSource(),
            display=None,
            overlay=True,
            imageFactory=afwImage.ImageF,
            binSize=1,
            inCameraCoords=False):
    """Show a CCD on display.

    Parameters
    ----------
    ccd : `lsst.afw.cameraGeom.Detector`
        Detector to use in display.
    imageSource : `FakeImageDataSource` or `None`
        Source to get ccd images.  Must have a ``getCcdImage()`` method.
    display : `lsst.afw.display.Display`
        image display to use.
    overlay : `bool`
        Show amp bounding boxes on the displayed image?
    imageFactory : callable like `lsst.afw.image.Image`
        The image factory to use in generating the images.
    binSize : `int`
        Bin the image by this factor in both dimensions.
    inCameraCoords : `bool`
        Show the Detector in camera coordinates?
    """
    display = _getDisplayFromDisplayOrFrame(display)

    ccdOrigin = lsst.geom.Point2I(0, 0)
    nQuarter = 0
    ccdImage, ccd = imageSource.getCcdImage(ccd,
                                            imageFactory=imageFactory,
                                            binSize=binSize)

    ccdBbox = ccdImage.getBBox()
    if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
        isTrimmed = True
    else:
        isTrimmed = False

    if inCameraCoords:
        nQuarter = ccd.getOrientation().getNQuarter()
        ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
    title = ccd.getName()
    if isTrimmed:
        title += "(trimmed)"

    if display:
        display.mtv(ccdImage, title=title)

        if overlay:
            overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin,
                            display, binSize)

    return ccdImage
Ejemplo n.º 4
0
Archivo: utils.py Proyecto: brianv0/afw
def showAmp(amp,
            imageSource=FakeImageDataSource(isTrimmed=False),
            display=None,
            overlay=True,
            imageFactory=afwImage.ImageU):
    """!Show an amp in an image display

    @param[in] amp  amp record to use in display
    @param[in] imageSource  Source for getting the amp image.  Must have a getAmpImage method.
    @param[in] display image display to use
    @param[in] overlay  Overlay bounding boxes?
    @param[in] imageFactory  Type of image to display (only used if ampImage is None)
    """

    if not display:
        display = _getDisplayFromDisplayOrFrame()

    ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
    ampImSize = ampImage.getDimensions()
    title = amp.getName()
    display.mtv(ampImage, title=title)
    if overlay:
        with display.Buffering():
            if amp.getHasRawInfo() and ampImSize == amp.getRawBBox(
            ).getDimensions():
                bboxes = [
                    (amp.getRawBBox(), 0.49, afwDisplay.GREEN),
                ]
                xy0 = bboxes[0][0].getMin()
                bboxes.append(
                    (amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
                bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
                bboxes.append(
                    (amp.getRawPrescanBBox(), 0.49, afwDisplay.YELLOW))
                bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49,
                               afwDisplay.MAGENTA))
            else:
                bboxes = [
                    (amp.getBBox(), 0.49, None),
                ]
                xy0 = bboxes[0][0].getMin()

            for bbox, borderWidth, ctype in bboxes:
                if bbox.isEmpty():
                    continue
                bbox = afwGeom.Box2I(bbox)
                bbox.shift(-afwGeom.ExtentI(xy0))
                displayUtils.drawBBox(bbox,
                                      borderWidth=borderWidth,
                                      ctype=ctype,
                                      display=display)
Ejemplo n.º 5
0
Archivo: utils.py Proyecto: brianv0/afw
def showCcd(ccd,
            imageSource=FakeImageDataSource(),
            display=None,
            frame=None,
            overlay=True,
            imageFactory=afwImage.ImageF,
            binSize=1,
            inCameraCoords=False):
    """!Show a CCD on display

    @param[in] ccd  Detector to use in display
    @param[in] imageSource  Source for producing images to display.  Must have a getCcdImage method.
    @param[in] display image display to use
    @param[in] frame  frame ID on which to display
    @param[in] overlay  Show amp bounding boxes on the displayed image?
    @param[in] imageFactory  The image factory to use in generating the images.
    @param[in] binSize  Binning factor
    @param[in] inCameraCoords  Show the Detector in camera coordinates?
    """
    display = _getDisplayFromDisplayOrFrame(display, frame)

    ccdOrigin = afwGeom.Point2I(0, 0)
    nQuarter = 0
    ccdImage = imageSource.getCcdImage(ccd,
                                       imageFactory=imageFactory,
                                       binSize=binSize)

    ccdBbox = ccdImage.getBBox()
    if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
        isTrimmed = True
    else:
        isTrimmed = False

    if inCameraCoords:
        nQuarter = ccd.getOrientation().getNQuarter()
        ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
    title = ccd.getName()
    if isTrimmed:
        title += "(trimmed)"

    if display:
        display.mtv(ccdImage, title=title)

        if overlay:
            overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin,
                            display, binSize)

    return ccdImage
Ejemplo n.º 6
0
def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=False), display=None, overlay=True,
            imageFactory=afwImage.ImageU):
    """Show an amp in an image display.

    Parameters
    ----------
    amp : `lsst.afw.tables.AmpInfoRecord`
        Amp record to use in display.
    imageSource : `FakeImageDataSource` or `None`
        Source for getting the amp image.  Must have a ``getAmpImage()`` method.
    display : `lsst.afw.display.Display`
        Image display to use.
    overlay : `bool`
        Overlay bounding boxes?
    imageFactory : callable like `lsst.afw.image.Image`
        Type of image to display (only used if ampImage is `None`).
    """
    if not display:
        display = _getDisplayFromDisplayOrFrame(display)

    ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
    ampImSize = ampImage.getDimensions()
    title = amp.getName()
    display.mtv(ampImage, title=title)
    if overlay:
        with display.Buffering():
            if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
                bboxes = [(amp.getRawBBox(), 0.49, afwDisplay.GREEN), ]
                xy0 = bboxes[0][0].getMin()
                bboxes.append(
                    (amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED))
                bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
                bboxes.append((amp.getRawPrescanBBox(),
                               0.49, afwDisplay.YELLOW))
                bboxes.append((amp.getRawVerticalOverscanBBox(),
                               0.49, afwDisplay.MAGENTA))
            else:
                bboxes = [(amp.getBBox(), 0.49, None), ]
                xy0 = bboxes[0][0].getMin()

            for bbox, borderWidth, ctype in bboxes:
                if bbox.isEmpty():
                    continue
                bbox = lsst.geom.Box2I(bbox)
                bbox.shift(-lsst.geom.ExtentI(xy0))
                displayUtils.drawBBox(
                    bbox, borderWidth=borderWidth, ctype=ctype, display=display)
Ejemplo n.º 7
0
def showCcd(ccd, imageSource=FakeImageDataSource(), display=None, frame=None, overlay=True,
            imageFactory=afwImage.ImageF, binSize=1, inCameraCoords=False):
    """!Show a CCD on display

    @param[in] ccd  Detector to use in display
    @param[in] imageSource  Source for producing images to display.  Must have a getCcdImage method.
    @param[in] display image display to use
    @param[in] frame  frame ID on which to display
    @param[in] overlay  Show amp bounding boxes on the displayed image?
    @param[in] imageFactory  The image factory to use in generating the images.
    @param[in] binSize  Binning factor
    @param[in] inCameraCoords  Show the Detector in camera coordinates?
    """
    display = _getDisplayFromDisplayOrFrame(display, frame)

    ccdOrigin = afwGeom.Point2I(0,0)
    nQuarter = 0
    ccdImage = imageSource.getCcdImage(ccd, imageFactory=imageFactory, binSize=binSize)

    ccdBbox = ccdImage.getBBox()
    if ccdBbox.getDimensions() == ccd.getBBox().getDimensions():
        isTrimmed = True
    else:
        isTrimmed = False

    if inCameraCoords:
        nQuarter = ccd.getOrientation().getNQuarter()
        ccdImage = afwMath.rotateImageBy90(ccdImage, nQuarter)
    title = ccd.getName()
    if isTrimmed:
        title += "(trimmed)"

    if display:
        display.mtv(ccdImage, title=title)

        if overlay:
            overlayCcdBoxes(ccd, ccdBbox, nQuarter, isTrimmed, ccdOrigin, display, binSize)

    return ccdImage
Ejemplo n.º 8
0
def showAmp(amp, imageSource=FakeImageDataSource(isTrimmed=False), display=None, overlay=True,
            imageFactory=afwImage.ImageU):
    """!Show an amp in an image display

    @param[in] amp  amp record to use in display
    @param[in] imageSource  Source for getting the amp image.  Must have a getAmpImage method.
    @param[in] display image display to use
    @param[in] overlay  Overlay bounding boxes?
    @param[in] imageFactory  Type of image to display (only used if ampImage is None)
    """

    if not display:
        display = _getDisplayFromDisplayOrFrame()

    ampImage = imageSource.getAmpImage(amp, imageFactory=imageFactory)
    ampImSize = ampImage.getDimensions()
    title = amp.getName()
    display.mtv(ampImage, title=title)
    if overlay:
        with display.Buffering():
            if amp.getHasRawInfo() and ampImSize == amp.getRawBBox().getDimensions():
                bboxes = [(amp.getRawBBox(), 0.49, afwDisplay.GREEN),]
                xy0 = bboxes[0][0].getMin()
                bboxes.append((amp.getRawHorizontalOverscanBBox(), 0.49, afwDisplay.RED)) 
                bboxes.append((amp.getRawDataBBox(), 0.49, afwDisplay.BLUE))
                bboxes.append((amp.getRawPrescanBBox(), 0.49, afwDisplay.YELLOW))
                bboxes.append((amp.getRawVerticalOverscanBBox(), 0.49, afwDisplay.MAGENTA))
            else:
                bboxes = [(amp.getBBox(), 0.49, None),]
                xy0 = bboxes[0][0].getMin()

            for bbox, borderWidth, ctype in bboxes:
                if bbox.isEmpty():
                    continue
                bbox = afwGeom.Box2I(bbox)
                bbox.shift(-afwGeom.ExtentI(xy0))
                displayUtils.drawBBox(bbox, borderWidth=borderWidth, ctype=ctype, display=display)
Ejemplo n.º 9
0
def showCamera(camera, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageF,
               detectorNameList=None, binSize=10, bufferSize=10, frame=None, overlay=True, title="",
               ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=True, display=None, **kwargs):
    """!Show a Camera on display, with the specified display

    The rotation of the sensors is snapped to the nearest multiple of 90 deg. 
    Also note that the pixel size is constant over the image array. The lower left corner (LLC) of each
    sensor amp is snapped to the LLC of the pixel containing the LLC of the image. 
    if overlay show the IDs and detector boundaries

    @param[in] camera  Camera to show
    @param[in] imageSource  Source to get Ccd images from.  Must have a getCcdImage method.
    @param[in] imageFactory  Type of image to make
    @param[in] detectorNameList  List of names of Detectors to use. If None use all
    @param[in] binSize  bin factor
    @param[in] bufferSize  size of border in binned pixels to make around camera image.
    @param[in] frame  specify image display (@deprecated; new code should use display)
    @param[in] overlay  Overlay Detector IDs and boundaries?
    @param[in] title  Title in display
    @param[in] ctype  Color to use when drawing Detector boundaries
    @param[in] textSize  Size of detector labels
    @param[in] originAtCenter Put origin of the camera WCS at the center of the image? Else it will be LL
    @param[in] display  image display on which to display
    @param[in] **kwargs all remaining keyword arguments are passed to makeImageFromCamera
    @return the mosaic image
    """
    display = _getDisplayFromDisplayOrFrame(display, frame)

    if binSize < 1:
        binSize = 1
    cameraImage = makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
                                      imageSource=imageSource, imageFactory=imageFactory, binSize=binSize,
                                      **kwargs)

    if detectorNameList is None:
        ccdList = [camera[name] for name in camera.getNameIter()]
    else:
        ccdList = [camera[name] for name in detectorNameList]

    if detectorNameList is None:
        camBbox = camera.getFpBBox()
    else:
        camBbox = afwGeom.Box2D()
        for detName in detectorNameList:
            for corner in camera[detName].getCorners(FOCAL_PLANE):
                camBbox.include(corner)
    pixelSize = ccdList[0].getPixelSize()
    if originAtCenter:
        #Can't divide SWIGGED extent type things when division is imported
        #from future.  This is DM-83
        ext = cameraImage.getBBox().getDimensions()

        wcsReferencePixel = afwGeom.PointI(ext.getX()//2, ext.getY()//2)
    else:
        wcsReferencePixel = afwGeom.Point2I(0,0)
    wcs = makeFocalPlaneWcs(pixelSize*binSize, wcsReferencePixel)

    if display:
        if title == "":
            title = camera.getName()
        display.mtv(cameraImage, title=title, wcs=wcs)

        if overlay:
            with display.Buffering():
                camBbox = getCameraImageBBox(camBbox, pixelSize, bufferSize*binSize)
                bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize, camBbox.getMin())
                for bbox, ccd in itertools.izip(bboxList, ccdList):
                    nQuarter = ccd.getOrientation().getNQuarter()
                    # borderWidth to 0.5 to align with the outside edge of the pixel
                    displayUtils.drawBBox(bbox, borderWidth=0.5, ctype=ctype, display=display)
                    dims = bbox.getDimensions()
                    display.dot(ccd.getName(), bbox.getMinX()+dims.getX()/2, bbox.getMinY()+dims.getY()/2,
                                ctype=ctype, size=textSize, textAngle=nQuarter*90)

    return cameraImage
Ejemplo n.º 10
0
def showCamera(camera,
               imageSource=FakeImageDataSource(),
               imageFactory=afwImage.ImageF,
               detectorNameList=None,
               binSize=10,
               bufferSize=10,
               frame=None,
               overlay=True,
               title="",
               showWcs=None,
               ctype=afwDisplay.GREEN,
               textSize=1.25,
               originAtCenter=True,
               display=None,
               **kwargs):
    """Show a Camera on display, with the specified display.

    The rotation of the sensors is snapped to the nearest multiple of 90 deg.
    Also note that the pixel size is constant over the image array. The lower
    left corner (LLC) of each sensor amp is snapped to the LLC of the pixel
    containing the LLC of the image.

    Parameters
    ----------
    camera : `lsst.afw.cameraGeom.Camera`
        Camera object to use to make the image.
    imageSource : `FakeImageDataSource` or None
        Source to get ccd images.  Must have a ``getCcdImage()`` method.
    imageFactory : `lsst.afw.image.Image`
        Type of image to make
    detectorNameList : `list` of `str`
        List of detector names from `camera` to use in building the image.
        Use all Detectors if None.
    binSize : `int`
        Bin the image by this factor in both dimensions.
    bufferSize : `int`
        Size of border in binned pixels to make around the camera image.
    frame : None
        specify image display. **Deprecated** in v12.
    overlay : `bool`
        Overlay Detector IDs and boundaries?
    title : `str`
        Title to use in display.
    showWcs : `bool`
        Include a WCS in the display?
    ctype : `lsst.afw.display.COLOR` or `str`
        Color to use when drawing Detector boundaries.
    textSize : `float`
        Size of detector labels
    originAtCenter : `bool`
        Put origin of the camera WCS at the center of the image?
        If False, the origin will be at the lower left.
    display : `lsst.afw.display`
        Image display on which to display.
    **kwargs :
        All remaining keyword arguments are passed to makeImageFromCamera

    Returns
    -------
    image : `lsst.afw.image.Image`
        The mosaic image.
    """
    if frame is not None:
        warnings.warn(
            "The frame kwarg is deprecated; use the `lsst.afw.display` system instead.",
            DeprecationWarning)

    display = _getDisplayFromDisplayOrFrame(display, frame)

    if binSize < 1:
        binSize = 1
    cameraImage = makeImageFromCamera(camera,
                                      detectorNameList=detectorNameList,
                                      bufferSize=bufferSize,
                                      imageSource=imageSource,
                                      imageFactory=imageFactory,
                                      binSize=binSize,
                                      **kwargs)

    if detectorNameList is None:
        ccdList = [camera[name] for name in camera.getNameIter()]
    else:
        ccdList = [camera[name] for name in detectorNameList]

    if detectorNameList is None:
        camBbox = camera.getFpBBox()
    else:
        camBbox = lsst.geom.Box2D()
        for detName in detectorNameList:
            for corner in camera[detName].getCorners(FOCAL_PLANE):
                camBbox.include(corner)
    pixelSize = ccdList[0].getPixelSize()

    if showWcs:
        if originAtCenter:
            wcsReferencePixel = lsst.geom.Box2D(
                cameraImage.getBBox()).getCenter()
        else:
            wcsReferencePixel = lsst.geom.Point2I(0, 0)
        wcs = makeFocalPlaneWcs(pixelSize * binSize, wcsReferencePixel)
    else:
        wcs = None

    if display:
        if title == "":
            title = camera.getName()
        display.mtv(cameraImage, title=title, wcs=wcs)

        if overlay:
            with display.Buffering():
                camBbox = getCameraImageBBox(camBbox, pixelSize,
                                             bufferSize * binSize)
                bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize,
                                               camBbox.getMin())
                for bbox, ccd in zip(bboxList, ccdList):
                    nQuarter = ccd.getOrientation().getNQuarter()
                    # borderWidth to 0.5 to align with the outside edge of the
                    # pixel
                    displayUtils.drawBBox(bbox,
                                          borderWidth=0.5,
                                          ctype=ctype,
                                          display=display)
                    dims = bbox.getDimensions()
                    display.dot(ccd.getName(),
                                bbox.getMinX() + dims.getX() / 2,
                                bbox.getMinY() + dims.getY() / 2,
                                ctype=ctype,
                                size=textSize,
                                textAngle=nQuarter * 90)

    return cameraImage
Ejemplo n.º 11
0
Archivo: utils.py Proyecto: brianv0/afw
def showCamera(camera,
               imageSource=FakeImageDataSource(),
               imageFactory=afwImage.ImageF,
               detectorNameList=None,
               binSize=10,
               bufferSize=10,
               frame=None,
               overlay=True,
               title="",
               ctype=afwDisplay.GREEN,
               textSize=1.25,
               originAtCenter=True,
               display=None,
               **kwargs):
    """!Show a Camera on display, with the specified display

    The rotation of the sensors is snapped to the nearest multiple of 90 deg.
    Also note that the pixel size is constant over the image array. The lower left corner (LLC) of each
    sensor amp is snapped to the LLC of the pixel containing the LLC of the image.
    if overlay show the IDs and detector boundaries

    @param[in] camera  Camera to show
    @param[in] imageSource  Source to get Ccd images from.  Must have a getCcdImage method.
    @param[in] imageFactory  Type of image to make
    @param[in] detectorNameList  List of names of Detectors to use. If None use all
    @param[in] binSize  bin factor
    @param[in] bufferSize  size of border in binned pixels to make around camera image.
    @param[in] frame  specify image display (@deprecated; new code should use display)
    @param[in] overlay  Overlay Detector IDs and boundaries?
    @param[in] title  Title in display
    @param[in] ctype  Color to use when drawing Detector boundaries
    @param[in] textSize  Size of detector labels
    @param[in] originAtCenter Put origin of the camera WCS at the center of the image? Else it will be LL
    @param[in] display  image display on which to display
    @param[in] **kwargs all remaining keyword arguments are passed to makeImageFromCamera
    @return the mosaic image
    """
    display = _getDisplayFromDisplayOrFrame(display, frame)

    if binSize < 1:
        binSize = 1
    cameraImage = makeImageFromCamera(camera,
                                      detectorNameList=detectorNameList,
                                      bufferSize=bufferSize,
                                      imageSource=imageSource,
                                      imageFactory=imageFactory,
                                      binSize=binSize,
                                      **kwargs)

    if detectorNameList is None:
        ccdList = [camera[name] for name in camera.getNameIter()]
    else:
        ccdList = [camera[name] for name in detectorNameList]

    if detectorNameList is None:
        camBbox = camera.getFpBBox()
    else:
        camBbox = afwGeom.Box2D()
        for detName in detectorNameList:
            for corner in camera[detName].getCorners(FOCAL_PLANE):
                camBbox.include(corner)
    pixelSize = ccdList[0].getPixelSize()
    if originAtCenter:
        #Can't divide SWIGGED extent type things when division is imported
        #from future.  This is DM-83
        ext = cameraImage.getBBox().getDimensions()

        wcsReferencePixel = afwGeom.PointI(ext.getX() // 2, ext.getY() // 2)
    else:
        wcsReferencePixel = afwGeom.Point2I(0, 0)
    wcs = makeFocalPlaneWcs(pixelSize * binSize, wcsReferencePixel)

    if display:
        if title == "":
            title = camera.getName()
        display.mtv(cameraImage, title=title, wcs=wcs)

        if overlay:
            with display.Buffering():
                camBbox = getCameraImageBBox(camBbox, pixelSize,
                                             bufferSize * binSize)
                bboxList = getCcdInCamBBoxList(ccdList, binSize, pixelSize,
                                               camBbox.getMin())
                for bbox, ccd in zip(bboxList, ccdList):
                    nQuarter = ccd.getOrientation().getNQuarter()
                    # borderWidth to 0.5 to align with the outside edge of the pixel
                    displayUtils.drawBBox(bbox,
                                          borderWidth=0.5,
                                          ctype=ctype,
                                          display=display)
                    dims = bbox.getDimensions()
                    display.dot(ccd.getName(),
                                bbox.getMinX() + dims.getX() / 2,
                                bbox.getMinY() + dims.getY() / 2,
                                ctype=ctype,
                                size=textSize,
                                textAngle=nQuarter * 90)

    return cameraImage
Ejemplo n.º 12
0
def showCamera(camera, imageSource=FakeImageDataSource(), imageFactory=afwImage.ImageF,
               detectorNameList=None, binSize=10, bufferSize=10, frame=None, overlay=True, title="",
               showWcs=None, ctype=afwDisplay.GREEN, textSize=1.25, originAtCenter=True, display=None,
               **kwargs):
    """Show a Camera on display, with the specified display.

    The rotation of the sensors is snapped to the nearest multiple of 90 deg.
    Also note that the pixel size is constant over the image array. The lower
    left corner (LLC) of each sensor amp is snapped to the LLC of the pixel
    containing the LLC of the image.

    Parameters
    ----------
    camera : `lsst.afw.cameraGeom.Camera`
        Camera object to use to make the image.
    imageSource : `FakeImageDataSource` or `None`
        Source to get ccd images.  Must have a ``getCcdImage()`` method.
    imageFactory : `lsst.afw.image.Image`
        Type of image to make
    detectorNameList : `list` of `str` or `None`
        List of detector names from `camera` to use in building the image.
        Use all Detectors if `None`.
    binSize : `int`
        Bin the image by this factor in both dimensions.
    bufferSize : `int`
        Size of border in binned pixels to make around the camera image.
    frame : `None`
        specify image display. **Deprecated** in v12.
    overlay : `bool`
        Overlay Detector IDs and boundaries?
    title : `str`
        Title to use in display.
    showWcs : `bool`
        Include a WCS in the display?
    ctype : `lsst.afw.display.COLOR` or `str`
        Color to use when drawing Detector boundaries.
    textSize : `float`
        Size of detector labels
    originAtCenter : `bool`
        Put origin of the camera WCS at the center of the image?
        If `False`, the origin will be at the lower left.
    display : `lsst.afw.display`
        Image display on which to display.
    **kwargs :
        All remaining keyword arguments are passed to makeImageFromCamera

    Returns
    -------
    image : `lsst.afw.image.Image`
        The mosaic image.
    """
    if frame is not None:
        warnings.warn("The frame kwarg is deprecated; use the `lsst.afw.display` system instead.",
                      DeprecationWarning)

    display = _getDisplayFromDisplayOrFrame(display, frame)

    if binSize < 1:
        binSize = 1
    cameraImage = makeImageFromCamera(camera, detectorNameList=detectorNameList, bufferSize=bufferSize,
                                      imageSource=imageSource, imageFactory=imageFactory, binSize=binSize,
                                      **kwargs)

    if detectorNameList is None:
        ccdList = [camera[name] for name in camera.getNameIter()]
    else:
        ccdList = [camera[name] for name in detectorNameList]

    if detectorNameList is None:
        camBbox = camera.getFpBBox()
    else:
        camBbox = lsst.geom.Box2D()
        for detName in detectorNameList:
            for corner in camera[detName].getCorners(FOCAL_PLANE):
                camBbox.include(corner)
    pixelSize = ccdList[0].getPixelSize()

    if showWcs:
        if originAtCenter:
            wcsReferencePixel = lsst.geom.Box2D(
                cameraImage.getBBox()).getCenter()
        else:
            wcsReferencePixel = lsst.geom.Point2I(0, 0)
        wcs = makeFocalPlaneWcs(pixelSize*binSize, wcsReferencePixel)
    else:
        wcs = None

    if display:
        if title == "":
            title = camera.getName()
        display.mtv(cameraImage, title=title, wcs=wcs)

        if overlay:
            with display.Buffering():
                camBbox = getCameraImageBBox(
                    camBbox, pixelSize, bufferSize*binSize)
                bboxList = getCcdInCamBBoxList(
                    ccdList, binSize, pixelSize, camBbox.getMin())
                for bbox, ccd in zip(bboxList, ccdList):
                    nQuarter = ccd.getOrientation().getNQuarter()
                    # borderWidth to 0.5 to align with the outside edge of the
                    # pixel
                    displayUtils.drawBBox(
                        bbox, borderWidth=0.5, ctype=ctype, display=display)
                    dims = bbox.getDimensions()
                    display.dot(ccd.getName(), bbox.getMinX() + dims.getX()/2, bbox.getMinY() + dims.getY()/2,
                                ctype=ctype, size=textSize, textAngle=nQuarter*90)

    return cameraImage