Пример #1
0
def makeMos(butler, mos, frame0=0, bin=32, nJob=20, visits=[]):
    if not visits:
        visits = [904288, 904320, 904330, 904520, 904534, 904536, 904538, 904670, 904672,
                  904674, 904676, 904678, 904786, 904788, 904790, 904792, 904794, 905034, 905036]

    frame = frame0
    for visit in visits:
        if visit in mos:
            continue

        if visit in bad:
            print("Skipping bad visit %d: %s" % (visit, bad[visit]))
            continue

        global labels
        try:
            md = butler.get("raw_md", visit=visit, ccd=10)
            labels[visit] = afwImage.Filter(md).getName()
        except RuntimeError as e:
            print(e)

        mos[visit] = cgUtils.showCamera(butler.get("camera"),
                                        cgUtils.ButlerImage(butler, visit=visit,
                                                            callback=utils.trimRemoveCrCallback,
                                                            verbose=True),
                                        nJob=nJob, frame=frame, bin=bin,
                                        title=visit, overlay=True, names=False)
        frame += 1
def make_fp_mosaic(repo,
                   expId,
                   det_names=None,
                   outfile=None,
                   bin_size=10,
                   verbose=False):
    """
    Function to make a mosaic of raw image data in the LSST focal plane.

    Parameters
    ----------
    repo: str
        Path to the data repo containing the raw images.
    expId: int
        The expId to use.
    det_names: list-like [None]
        List of detectors to render, e.g., ['R22_S11', 'R22_S12', ...].
        If None, the all detectors in the focal plane will be plotted.
    outfile: str [None]
        Name of FITS file to write with the mosaicked data.  If None,
        then no file will be written.
    bin_size: int [10]
        Rebinning size in pixels.
    verbose: bool [False]
        Flag to print dots indicating progress of CCD processing.

    Returns
    -------
    lsst.afw.ImageF:  Image containing the mosaic.
    """
    butler = dp.Butler(repo)
    camera = butler.get('camera')
    callback = lambda *args, **kwds: raw_callback(
        *args, verbose=verbose, **kwds)
    image_source = cgu.ButlerImage(butler,
                                   'raw',
                                   expId=expId,
                                   callback=callback,
                                   verbose=verbose)
    image = cgu.showCamera(camera,
                           imageSource=image_source,
                           binSize=bin_size,
                           detectorNameList=det_names)
    if outfile is not None:
        image.writeFits(outfile)

    return image
Пример #3
0
def plot_cameraGeom(repo_dir=os.path.join(
    '/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/'),
                    detectorNameList=[
                        "R04_SW0",
                        "R04_SW1",
                        "R44_SW0",
                        "R44_SW1",
                        "R00_SW0",
                        "R00_SW1",
                        "R40_SW0",
                        "R40_SW1",
                    ],
                    instrument='LSSTCam',
                    binSize=16):
    afwDisplay.setDefaultBackend("matplotlib")

    #repo_dir = os.path.join('/project/scichris/aos/images/lsstCam/letter_lsstCam_entire_tiledF/DATA/')

    # need to specify the calib collections to be able to access the camera

    butler = dafButler.Butler(repo_dir,
                              collections=[
                                  f'{instrument}/raw/all',
                                  f'{instrument}/calib', 'run1',
                                  f'{instrument}/calib/unbounded'
                              ])

    dataId0 = dict(instrument=instrument)
    dataset = next(
        iter(
            butler.registry.queryDatasets(datasetType='postISRCCD',
                                          collections=['run1'],
                                          dataId=dataId0)))

    exposure = dataset.dataId["exposure"]

    camera = butler.get("camera", instrument=instrument, exposure=exposure)

    fig = plt.figure(figsize=(15, 15))
    fig.subplots_adjust(
        hspace=0.,
        wspace=0.0,
    )

    ax = fig.add_subplot(1, 1, 1)

    disp = afwDisplay.Display(fig)
    disp.scale('asinh', 'zscale', Q=2)
    #disp.scale('linear', 'minmax')
    #disp.scale('asinh', 5, 7000, Q=2)

    disp.setImageColormap('viridis' if True else 'gray')
    dataType = "postISRCCD"

    # use that  to limit what's shown
    #detectorNameList = ['R22_S11', 'R22_S20', 'R22_S10']# , 'R34_S20']

    # set to None to plot everything

    mos = cameraGeomUtils.showCamera(camera,
                                     cameraGeomUtils.ButlerImage(
                                         butler,
                                         dataType,
                                         instrument=instrument,
                                         exposure=exposure,
                                         verbose=True),
                                     binSize=binSize,
                                     detectorNameList=detectorNameList,
                                     display=disp,
                                     overlay=True,
                                     title=f'{instrument}')

    disp.show_colorbar(False)
    ax.axis("off")

    #plt.savefig('LsstCam_letter_entire_tiledF_wfs.png', bbox_inches='tight')
    return mos
Пример #4
0
def plotShowCamera(butler, expId, dataType, dataType2=None, butler2=None, expId2=None,
                   dataType3=None, butler3=None, expId3=None, binSize=10,
                   cmap="viridis", doVariance=False, doSignalToNoise=False, doDiffIm=False,
                   doPercentDiffIm=False, doAddIm=False, doAddThenSubtractIm=False,
                   fileUsedDir=None, fileUsedDir2=None, figureSideSize=12):
    subTypeStr = ""
    camera = butler.get("camera")
    plt.figure(figsize=(figureSideSize, figureSideSize))
    disp = afwDisplay.Display(1, "matplotlib")
    disp.scale("linear", "zscale")
    disp.setImageColormap(cmap)
    callback = None
    if doVariance:
        subTypeStr = " variance"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  varianceOrSignalToNoiseCallback(im, ccd, imageSource,
                                                                                  dataType=dataType,
                                                                                  butler=butler, expId=expId,
                                                                                  doVariance=True))
    elif doSignalToNoise:
        subTypeStr = " S/N"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  varianceOrSignalToNoiseCallback(im, ccd, imageSource,
                                                                                  dataType=dataType,
                                                                                  butler=butler, expId=expId,
                                                                                  doSignalToNoise=True))
    elif doDiffIm:
        subTypeStr = " Absolute Difference Image"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  diffImCallback(im, ccd, imageSource, dataType=dataType,
                                                                 butler=butler, expId=expId,
                                                                 butler2=butler2, expId2=expId2,
                                                  doAbsoluteDiff=doDiffIm))

    elif doPercentDiffIm:
        subTypeStr = " Percent Difference Image"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  diffImCallback(im, ccd, imageSource, dataType=dataType,
                                                                 butler=butler, expId=expId,
                                                                 butler2=butler2, expId2=expId2,
                                                                 doPercentDiff=doPercentDiffIm))
    elif doAddIm:
        subTypeStr = " Addition of two Images"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  addImCallback(im, ccd, imageSource, dataType=dataType,
                                                                butler=butler, expId=expId,
                                                                dataType2=dataType2,
                                                                butler2=butler2, expId2=expId2))
    elif doAddThenSubtractIm:
        subTypeStr = " Addition of two Images and Subtraction of a Third"
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True,
                                                  callback=lambda im, ccd, imageSource:
                                                  addThenSubtractImCallback(im, ccd, imageSource,
                                                                            dataType=dataType,
                                                                            butler=butler, expId=expId,
                                                                            dataType2=dataType2,
                                                                            butler2=butler2, expId2=expId2,
                                                                            dataType3=dataType3,
                                                                            butler3=butler3, expId3=expId3))

    else:
        imageSource = cameraGeomUtils.ButlerImage(butler, dataType, expId=expId, verbose=True)
    if "Difference" in subTypeStr:
        titleStr = ("{}{} source1: {} source2: {}  BinSize={}".
                    format(dataType, subTypeStr, fileUsedDir, fileUsedDir2, binSize))
    else:
        titleStr = ("{}{} source: {}  expId: {}  BinSize={}".
                    format(dataType, subTypeStr, fileUsedDir, expId, binSize))
    mos = cameraGeomUtils.showCamera(camera, imageSource=imageSource, detectorNameList=None,
                                     binSize=binSize, display=disp, title=titleStr, ctype=afwDisplay.GREEN,
                                     textSize=3)
Пример #5
0
    def runDataRef(self, expRefList, butler):
        """Make summary plots of full focalplane images.
        """
        if len(expRefList) == 0:
            return pipeBase.Struct(exitStatus=1)

        lsst.afw.fits.setAllowImageCompression(
            self.config.allowFitsCompression)

        dstype = expRefList[0].butlerSubset.datasetType

        if dstype == "raw":

            def callback(im, ccd, imageSource):
                return cgu.rawCallback(im,
                                       ccd,
                                       imageSource,
                                       correctGain=True,
                                       subtractBias=True)
        elif dstype == "eimage":
            callback = eimageCallback
        elif self.config.doApplySkyCorr:
            callback = skyCorrCallback
        else:
            callback = None

        for visit in set([er.dataId["visit"] for er in expRefList]):
            self.log.info("Processing visit %d", visit)
            expRefListForVisit = [
                er for er in expRefList if er.dataId["visit"] == visit
            ]

            dataId = expRefListForVisit[0].dataId
            bi = cgu.ButlerImage(butler,
                                 dstype,
                                 visit=visit,
                                 callback=callback,
                                 verbose=True)

            if self.config.doSensorImages:
                for dataId in (er.dataId for er in expRefListForVisit):
                    ccd = butler.get('calexp_detector', **dataId)
                    try:
                        md = butler.get('calexp_md', **dataId)
                    except RuntimeError:
                        md = None
                    if md:
                        afwGeom.makeSkyWcs(
                            md, strip=True
                        )  # strip WCS cards; they're invalidated by binning
                    try:
                        binned_im = bi.getCcdImage(
                            ccd,
                            binSize=self.config.sensorBinSize,
                            asMaskedImage=True)[0]
                        binned_im = rotateImageBy90(
                            binned_im,
                            ccd.getOrientation().getNQuarter())
                        if self.config.putFullSensors:
                            binned_exp = afwImage.ExposureF(binned_im)
                            binned_exp.setMetadata(md)
                            butler.put(binned_exp,
                                       'binned_sensor_fits',
                                       **dataId,
                                       dstype=dstype)
                    except (TypeError, RuntimeError) as e:
                        # butler couldn't put the image or there was no image to put
                        self.log.warn("Unable to make binned image: %s", e)
                        continue

                    (x, y) = binned_im.getDimensions()
                    boxes = {
                        'A':
                        afwGeom.Box2I(afwGeom.PointI(0, y / 2),
                                      afwGeom.ExtentI(x, y / 2)),
                        'B':
                        afwGeom.Box2I(afwGeom.PointI(0, 0),
                                      afwGeom.ExtentI(x, y / 2))
                    }
                    for half in ('A', 'B'):
                        box = boxes[half]
                        binned_exp = afwImage.ExposureF(binned_im[box])
                        binned_exp.setMetadata(md)
                        butler.put(binned_exp,
                                   'binned_sensor_fits_halves',
                                   half=half,
                                   **dataId,
                                   dstype=dstype)

            im = cgu.showCamera(butler.get('camera'),
                                imageSource=bi,
                                binSize=self.config.binSize)

            dstypeName = "%s-%s" % (
                dstype, self.config.fpId) if self.config.fpId else dstype

            butler.put(im, 'focal_plane_fits', visit=visit, dstype=dstypeName)

            # Compute the zscale stretch for just the CCDs that have data.
            detectorNameList = [
                "%s_%s" % (er.dataId["raftName"], er.dataId["detectorName"])
                for er in expRefListForVisit
            ]
            im_scaling = cgu.showCamera(butler.get('camera'),
                                        imageSource=bi,
                                        binSize=self.config.binSize,
                                        detectorNameList=detectorNameList)
            zmap = ZScaleMapping(im_scaling, contrast=self.config.contrast)

            im = flipImage(im, False, True)
            rgb = zmap.makeRgbImage(im, im, im)
            file_name = butler.get('focal_plane_png_filename',
                                   visit=visit,
                                   dstype=dstypeName)
            writeRGB(file_name[0], rgb)

        return pipeBase.Struct(exitStatus=0)