Example #1
0
def plot_countpix(qa_dict,outfile,plotconf=None,hardplots=False):
    
    """
    Plot pixel counts above some threshold
    
    Args:
        qa_dict: qa dictionary from countpix qa
        outfile: pdf file of the plot
    """
    from desispec.util import set_backend
    _matplotlib_backend = None
    set_backend()
    
    expid=qa_dict["EXPID"]
    camera = qa_dict["CAMERA"]
    paname=qa_dict["PANAME"]
    #npix_amp=np.array(qa_dict["METRICS"]["NPIX_AMP"])
    litfrac=np.array(qa_dict["METRICS"]["LITFRAC_AMP"])

    cutthres=qa_dict["PARAMS"]["CUTPIX"]

    fig=plt.figure()

    if plotconf:
        hardplots=ql_qaplot(fig,plotconf,qa_dict,camera,expid,outfile)

    if not hardplots:
        pass
    else:
        plt.suptitle("Fraction of pixels lit after {}, Camera: {}, ExpID: {}".format(paname,camera,expid),fontsize=10,y=0.99)
        #ax1=fig.add_subplot(211)
        #heatmap1=ax1.pcolor(npix_amp.reshape(2,2),cmap=plt.cm.OrRd)
        ##plt.title('Total Pixels > {:d} sigma = {:f}'.format(cutthres,countlo), fontsize=10)
        #ax1.set_xlabel("# pixels > {:d} sigma (per Amp)".format(cutthres),fontsize=10)
        #ax1.tick_params(axis='x',labelsize=10,labelbottom=False)
        #ax1.tick_params(axis='y',labelsize=10,labelleft=False)
        # ax1.annotate("Amp 1\n{:f}".format(npix_amp[0]),
        #             xy=(0.4,0.4),
        #             fontsize=10
        #             )
        #ax1.annotate("Amp 2\n{:f}".format(npix_amp[1]),
        #             xy=(1.4,0.4),
        #             fontsize=10
        #             )
        #ax1.annotate("Amp 3\n{:f}".format(npix_amp[2]),
        #             xy=(0.4,1.4),
        #             fontsize=10
        #             )
        #ax1.annotate("Amp 4\n{:f}".format(npix_amp[3]),
        #             xy=(1.4,1.4),
        #             fontsize=10
        #             )
        ax2=fig.add_subplot(111)
        heatmap2=ax2.pcolor(litfrac.reshape(2,2),cmap=plt.cm.OrRd)
        ax2.set_xlabel("Fraction over {:d} sigma read noise(per Amp)".format(cutthres),fontsize=10)
        ax2.tick_params(axis='x',labelsize=10,labelbottom=False)
        ax2.tick_params(axis='y',labelsize=10,labelleft=False)
        ax2.annotate("Amp 1\n{:f}".format(litfrac[0]),
                     xy=(0.4,0.4),
                     fontsize=10
                     )
        ax2.annotate("Amp 2\n{:f}".format(litfrac[1]),
                     xy=(1.4,0.4),
                     fontsize=10
                     )
        ax2.annotate("Amp 3\n{:f}".format(litfrac[2]),
                     xy=(0.4,1.4),
                     fontsize=10
                     )
        ax2.annotate("Amp 4\n{:f}".format(litfrac[3]),
                     xy=(1.4,1.4),
                     fontsize=10
                     )
        plt.tight_layout()
        fig.savefig(outfile)
Example #2
0
def ql_main(args=None):

    from desispec.util import set_backend
    _matplotlib_backend = None
    set_backend()
    from desispec.quicklook import quicklook,qllogger,qlconfig

    if args is None:
        args = parse()

    qlog=qllogger.QLLogger(name="QuickLook",loglevel=args.loglvl)
    log=qlog.getlog()

    # quiet down DESI logs. We don't want DESI_LOGGER to print messages unless they are important
    # initalize singleton with WARNING level
    quietDesiLogger(args.loglvl+10)

    if args.config is not None:
        #RS: have command line arguments for finding files via old datamodel
        psfid=None
        if args.psfid:
            psfid=args.psfid
        flatid=None
        if args.flatid:
            flatid=args.flatid
        templateid=None
        if args.templateid:
            templateid=args.templateid
        templatenight=None
        if args.templatenight:
            templatenight=args.templatenight

        if args.rawdata_dir:
            rawdata_dir = args.rawdata_dir
        else:
            if 'QL_SPEC_DATA' not in os.environ:
                sys.exit("must set ${} environment variable or provide rawdata_dir".format('QL_SPEC_DATA'))
            rawdata_dir=os.getenv('QL_SPEC_DATA')

        if args.specprod_dir:
            specprod_dir = args.specprod_dir
        else:
            if 'QL_SPEC_REDUX' not in os.environ:
                sys.exit("must set ${} environment variable or provide specprod_dir".format('QL_SPEC_REDUX'))
            specprod_dir=os.getenv('QL_SPEC_REDUX')

        log.debug("Running Quicklook using configuration file {}".format(args.config))
        if os.path.exists(args.config):
            if "yaml" in args.config:
                config=qlconfig.Config(args.config, args.night,args.camera, args.expid, args.singqa, rawdata_dir=rawdata_dir, specprod_dir=specprod_dir,psfid=psfid,flatid=flatid,templateid=templateid,templatenight=templatenight,qlplots=args.qlplots,store_res=args.resolution)
                configdict=config.expand_config()
            else:
                log.critical("Can't open config file {}".format(args.config))
                sys.exit("Can't open config file")
        else:
            sys.exit("File does not exist: {}".format(args.config))
    else:
        sys.exit("Must provide a valid config file. See desispec/data/quicklook for an example")

    pipeline, convdict = quicklook.setup_pipeline(configdict)
    res=quicklook.runpipeline(pipeline,convdict,configdict)
    log.info("QuickLook Pipeline completed")
Example #3
0
Utility functions to perform a quick calibration of DESI data

TODO:
1. Expand to r, i cameras
2. QA plots
3. Test with CR data
"""
from __future__ import print_function, absolute_import, division

import numpy as np
from desiutil.log import get_logger
from desispec import bootcalib as desiboot
from desiutil import funcfits as dufits

from desispec.util import set_backend
set_backend()

from matplotlib.backends.backend_pdf import PdfPages
import sys

import argparse

from astropy.io import fits


def parse(options=None):
    parser = argparse.ArgumentParser(description="Bootstrap DESI PSF.")

    parser.add_argument('--contfile', type = str, default = None, required=False,
                        help = 'path of DESI continuum fits file')
    parser.add_argument('--arcfile', type = str, default = None, required=False,
Example #4
0
def ql_main(args=None):

    from desispec.util import set_backend
    _matplotlib_backend = None
    set_backend()
    from desispec.quicklook import quicklook, qllogger, qlconfig

    if args is None:
        args = parse()

    qlog = qllogger.QLLogger(name="QuickLook", loglevel=args.loglvl)
    log = qlog.getlog()

    # quiet down DESI logs. We don't want DESI_LOGGER to print messages unless they are important
    # initalize singleton with WARNING level
    quietDesiLogger(args.loglvl + 10)

    if args.config is not None:
        #RS: have command line arguments for finding files via old datamodel
        psfid = None
        if args.psfid:
            psfid = args.psfid
        flatid = None
        if args.flatid:
            flatid = args.flatid
        templateid = None
        if args.templateid:
            templateid = args.templateid
        templatenight = None
        if args.templatenight:
            templatenight = args.templatenight

        if args.rawdata_dir:
            rawdata_dir = args.rawdata_dir
        else:
            if 'QL_SPEC_DATA' not in os.environ:
                sys.exit(
                    "must set ${} environment variable or provide rawdata_dir".
                    format('QL_SPEC_DATA'))
            rawdata_dir = os.getenv('QL_SPEC_DATA')

        if args.specprod_dir:
            specprod_dir = args.specprod_dir
        else:
            if 'QL_SPEC_REDUX' not in os.environ:
                sys.exit(
                    "must set ${} environment variable or provide specprod_dir"
                    .format('QL_SPEC_REDUX'))
            specprod_dir = os.getenv('QL_SPEC_REDUX')

        log.debug("Running Quicklook using configuration file {}".format(
            args.config))
        if os.path.exists(args.config):
            if "yaml" in args.config:
                config = qlconfig.Config(args.config,
                                         args.night,
                                         args.camera,
                                         args.expid,
                                         args.singqa,
                                         rawdata_dir=rawdata_dir,
                                         specprod_dir=specprod_dir,
                                         psfid=psfid,
                                         flatid=flatid,
                                         templateid=templateid,
                                         templatenight=templatenight,
                                         qlplots=args.qlplots,
                                         store_res=args.resolution)
                configdict = config.expand_config()
            else:
                log.critical("Can't open config file {}".format(args.config))
                sys.exit("Can't open config file")
        else:
            sys.exit("File does not exist: {}".format(args.config))
    else:
        sys.exit(
            "Must provide a valid config file. See desispec/data/quicklook for an example"
        )

    pipeline, convdict = quicklook.setup_pipeline(configdict)
    res = quicklook.runpipeline(pipeline, convdict, configdict)
    log.info("QuickLook Pipeline completed")