示例#1
0
def plot_bliss_nightsum(fields,nitestr):
    plot_bliss_coverage(fields)
    plt.savefig('nightsum_coverage_%s.png'%nitestr)

    new = (np.array(map(utc2nite,fields['DATE'])) == nitestr)
    new_fields = fields[new]
    old_fields = fields[~new]

    db = Database()
    db.connect()

    query = """select id, qc_fwhm as psf, qc_teff as teff from exposure
where exptime = 90 and delivered = True and propid = '%s'
and qc_teff is not NULL and qc_fwhm is not NULL
and to_timestamp(utc_beg) %s '%s'
"""

    new = db.query2recarray(query%(fields.PROPID,'>',datestr(date)))
    try:
        old = db.query2recarray(query%(fields.PROPID,'<',date))
    except ValueError as e:
        print(e)
        old = np.recarray(0,dtype=new.dtype)

    nbins = 35
    kwargs = dict(normed=True)
    step_kwargs = dict(kwargs,histtype='step',lw=3.5)
    fill_kwargs = dict(kwargs,histtype='stepfilled',lw=1.0,alpha=0.7)

    plt.figure()
    step_kwargs['bins'] = np.linspace(0.5,2.5,nbins)
    fill_kwargs['bins'] = np.linspace(0.5,2.5,nbins)
    plt.hist(new['psf'],color='green',zorder=10, label='Observed tonight', **fill_kwargs)
    plt.hist(new['psf'],color='green',zorder=10, **step_kwargs)
    plt.hist(old['psf'],color='0.5', label='Observed previously', **fill_kwargs)
    plt.hist(old['psf'],color='0.5', **step_kwargs)
    plt.axvline(1.20,ls='--',lw=2,color='gray')
    plt.legend()
    plt.title('Seeing (%s)'%nitestr)
    plt.xlabel('FWHM (arcsec)')
    plt.ylabel('Normalized Number of Exposures')
    plt.savefig('nightsum_psf_%s.png'%nitestr,bbox_inches='tight')

    plt.figure()
    step_kwargs['bins'] = np.linspace(0,1.5,nbins)
    fill_kwargs['bins'] = np.linspace(0,1.5,nbins)
    plt.hist(new['teff'],color='green',zorder=10,label='Observed tonight', **fill_kwargs)
    plt.hist(new['teff'],color='green',zorder=10, **step_kwargs)
    plt.hist(old['teff'],color='0.5',label='Observed previously', **fill_kwargs)
    plt.hist(old['teff'],color='0.5', **step_kwargs)
    plt.axvline(0.25,ls='--',lw=2,color='gray')
    plt.legend()
    plt.title('Effective Depth (%s)'%nitestr)
    plt.xlabel('Teff')
    plt.ylabel('Normalized Number of Exposures')
    plt.savefig('nightsum_teff_%s.png'%nitestr,bbox_inches='tight')
示例#2
0
from obztak.utils.database import Database
from obztak.utils.ortho import DECamBasemap, DECamMcBride

db = Database()
db.connect()

query ="""
SELECT id as expnum, telra as ra, teldec as dec, expTime, filter, 
COALESCE(qc_teff,'NaN') as teff
FROM exposure where exptime >= 30 and discard = False and delivered = True 
and flavor = 'object' and telra between 0 and 360 and teldec between -90 and 90
and filter in ('u','g','r','i','z','Y') and propid NOT LIKE '%-9999'
ORDER BY id;
"""

data = db.query2recarray(query)

exposures = odict([
        ('u',data[data['filter'] =='u']),
        ('g',data[data['filter'] =='g']),
        ('r',data[data['filter'] =='r']),
        ('i',data[data['filter'] =='i']),
        ('z',data[data['filter'] =='z']),
        ('Y',data[data['filter'] =='Y']),
        ])

for b,exp in exposures.items():
    nan = np.isnan(exp['teff'])
    median = np.median(exp[~nan]['teff'])
    print "Median teff for %s-band: %s"%(b,median)
示例#3
0
    return vec


def ang2disc(nside, lon, lat, radius, inclusive=False, fact=4, nest=False):
    """
    Wrap `query_disc` to use lon, lat, and radius in degrees.
    """
    vec = ang2vec(lon, lat)
    return hp.query_disc(nside, vec, radius, inclusive, fact, nest)


args.db = True
if args.db:
    db = Database()
    db.connect()
    data = db.query2recarray(QUERY)

    args.delve = True
    if args.delve:
        print("Reading DELVE QA values...")
        delve = pd.read_csv('data/delve-qa-20201024.csv.gz')
        df = pd.DataFrame(data)
        print("Merging %i DELVE QA values..." % (len(delve)))
        x = df.merge(delve, left_on='expnum', right_on='expnum', how='left')
        sel = np.isnan(data['teff'])
        data['teff'][sel] = x[sel]['teff_y']

    if os.path.exists(args.outfile): os.remove(args.outfile)
    print("Writing %s..." % args.outfile)
    fitsio.write(args.outfile, data)
示例#4
0
def plot_nightsum(fields,nitestr):
    """ Plot the night summary for MagLiteS.

    Parameters:
    -----------
    fields:  the fields observed tonight
    nitestr: the nite in strig format

    Returns:
    --------
    None
    """
    import pylab as plt
    from obztak.utils.database import Database
    from obztak.utils.ortho import makePlot

    #fields = FieldArray.load_database()
    #new = np.char.startswith(fields['DATE'],date)

    date = nite2utc(nitestr)
    new = (np.array(map(utc2nite,fields['DATE'])) == nitestr)
    new_fields = fields[new]
    old_fields = fields[~new]

    kwargs = dict(edgecolor='none', s=50, vmin=0, vmax=4)
    fig,basemap = makePlot(date=nitestr,name='nightsum',moon=False,airmass=False,center=(0,-90),bliss=False)
    plt.title('Coverage (%s)'%nitestr)
    kwargs['cmap'] = 'gray_r'
    proj = basemap.proj(old_fields['RA'], old_fields['DEC'])
    basemap.scatter(*proj, c=old_fields['TILING'],**kwargs)

    kwargs['cmap'] = 'summer_r'
    proj = basemap.proj(new_fields['RA'], new_fields['DEC'])
    basemap.scatter(*proj, c=new_fields['TILING'],  **kwargs)
    colorbar = plt.colorbar()
    colorbar.set_label('Tiling')

    plt.plot(np.nan, np.nan,'o',color='green',mec='green',label='Observed tonight')
    plt.plot(np.nan, np.nan,'o',color='0.7',mec='0.7',label='Observed previously')
    plt.legend(fontsize=10,loc='lower left',scatterpoints=1)
    plt.savefig('nightsum_coverage_%s.png'%nitestr,bbox_inches='tight')

    db = Database()
    db.connect()

    query = """
    select id, qc_fwhm as psf, qc_teff as teff from exposure
    where exptime = 90 and delivered = True 
    and propid = '%s'
    and qc_teff is not NULL and qc_fwhm is not NULL
    and to_timestamp(utc_beg) %s '%s'
    """

    new = db.query2recarray(query%(PROPID,'>',date))
    old = db.query2recarray(query%(PROPID,'<',date))

    nbins = 35
    kwargs = dict(normed=True)
    step_kwargs = dict(kwargs,histtype='step',lw=3.5)
    fill_kwargs = dict(kwargs,histtype='stepfilled',lw=1.0,alpha=0.7)

    plt.figure()
    step_kwargs['bins'] = np.linspace(0.5,2.5,nbins)
    fill_kwargs['bins'] = np.linspace(0.5,2.5,nbins)
    plt.hist(new['psf'],color='green',zorder=10, label='Observed tonight', **fill_kwargs)
    plt.hist(new['psf'],color='green',zorder=10, **step_kwargs)
    plt.hist(old['psf'],color='0.5', label='Observed previously', **fill_kwargs)
    plt.hist(old['psf'],color='0.5', **step_kwargs)
    plt.axvline(1.20,ls='--',lw=2,color='gray')
    plt.legend()
    plt.title('Seeing (%s)'%nitestr)
    plt.xlabel('FWHM (arcsec)')
    plt.ylabel('Normalized Number of Exposures')
    plt.savefig('nightsum_psf_%s.png'%nitestr,bbox_inches='tight')

    plt.figure()
    step_kwargs['bins'] = np.linspace(0,1.5,nbins)
    fill_kwargs['bins'] = np.linspace(0,1.5,nbins)
    plt.hist(new['teff'],color='green',zorder=10,label='Observed tonight', **fill_kwargs)
    plt.hist(new['teff'],color='green',zorder=10, **step_kwargs)
    plt.hist(old['teff'],color='0.5',label='Observed previously', **fill_kwargs)
    plt.hist(old['teff'],color='0.5', **step_kwargs)
    plt.axvline(0.25,ls='--',lw=2,color='gray')
    plt.legend()
    plt.title('Effective Depth (%s)'%nitestr)
    plt.xlabel('Teff')
    plt.ylabel('Normalized Number of Exposures')
    plt.savefig('nightsum_teff_%s.png'%nitestr,bbox_inches='tight')
示例#5
0
文件: ortho.py 项目: kadrlica/obztak
def plot_nightsum(fields,nitestr,date):
    """ Plot the bliss night summary. 

    Parameters:
    -----------
    fields:  the fields observed tonight
    nitestr: the nite in strig format

    Returns:
    --------
    None
    """
    from obztak.utils.database import Database
    plt.ioff()


    # Select the fields from the database
    db = Database()
    db.connect()
    query = """
    select id, qc_fwhm as psf, qc_teff as teff, filter from exposure
    where delivered = True and propid = '%s'
    and flavor = 'object'
    and qc_teff is not NULL
    and qc_fwhm is not NULL
    and to_timestamp(utc_beg) %s
    """
    #new = db.query2recarray(query%(fields.PROPID,'>',datestr(date)))
    d = datestr(date)
    q = query%(fields.PROPID,"between (timestamp '%s') AND (timestamp '%s' + interval '12 hours')"%(d,d))
    logging.debug(q)
    new = db.query2recarray(q)
    try:
        q = query%(fields.PROPID,"< (timestamp '%s')"%d)
        logging.debug(q)
        old = db.query2recarray(q)
    except ValueError as e:
        print(e)
        old = np.recarray(0,dtype=new.dtype)

    for b in ['u','g','r','i','z','Y']:
        f = new[new['filter'] == b]
        print ' %s-band:'%b, len(f)

    if not len(new):
        logging.warn("No new exposures...")
        return

    ##########################

    plot_coverage(fields,nitestr)

    ##########################

    fig,axes = plt.subplots(1,2,figsize=(12,5))
    for i,d in enumerate(['2017/02/08 07:00:00','2017/02/08 19:00:00']):
        plt.sca(axes[i])
        bmap = DECamOrtho(date=d)
        for b in np.unique(fields['FILTER']):
            f = fields[fields['FILTER']==b]
            bmap.draw_focal_planes(f['RA'],f['DEC'],color=COLORS[b],alpha=0.3)
        bmap.draw_bliss()
        bmap.draw_galaxy()
        bmap.draw_des()

    plt.suptitle('Coverage (%s)'%nitestr,fontsize=16)
    plt.savefig('nightsum_summary_%s.png'%nitestr)

    new_sel = (np.array(map(utc2nite,fields['DATE'])) == nitestr)
    new_fields = fields[new_sel]
    old_fields = fields[~new_sel]

    ##########################

    fig,axes = plt.subplots(1,2,figsize=(12,5))
    plt.sca(axes[0])
    plt.plot(np.nan,np.nan,'-w',label='all')
    plot_psf(new,old)
    plt.title('Seeing (%s)'%nitestr)
    plt.sca(axes[1])
    plt.plot(np.nan,np.nan,'-w',label='all')
    plot_teff(new,old)
    plt.title('Effective Depth (%s)'%nitestr)
    plt.savefig('nightsum_psf_teff_%s.png'%nitestr,bbox_inches='tight')

    fig,axes = plt.subplots(2,2,figsize=(14,10))
    axes = axes.flatten()
    for i,b in enumerate(['g','r','i','z']):
        plt.sca(axes[i])
        plt.plot(np.nan,np.nan,'-w',label='%s-band'%b)
        plot_psf(new[new['filter'] == b],old[old['filter'] == b])
    plt.savefig('nightsum_psf_%s.png'%nitestr,bbox_inches='tight')

    fig,axes = plt.subplots(2,2,figsize=(14,10))
    axes = axes.flatten()
    for i,b in enumerate(['g','r','i','z']):
        plt.sca(axes[i])
        plt.plot(np.nan,np.nan,'-w',label='%s-band'%b)
        plot_teff(new[new['filter'] == b],old[old['filter'] == b])
    plt.savefig('nightsum_teff_%s.png'%nitestr,bbox_inches='tight')