Ejemplo n.º 1
0
def plot_patch_zpoffset(patchdat, maglim=None, etitle="", newfig=True, z_method=n.mean):
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad,
                                                               patchdat['dec']*deg2rad)
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['dmag'], z_method=z_method,
                     zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mag')
    figtitle = "Zeropoint Offsets " + etitle
    pyl.title(figtitle, fontsize='medium')
    return 
Ejemplo n.º 2
0
def plot_nstars_patch(patchdat, z_method=n.mean, zlimits=None, newfig=True):
    """Plot the n.min/mean/std number of stars ever seen in a particular patch."""
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad,
                                                            patchdat['dec']*deg2rad)
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'], patchdat['y'], z=patchdat['nstars'], z_method=z_method,
                    zlimits=zlimits, gridsize=gridsize, radecgrid=True, newfig=newfig)
    pyl.title("Patch Minimum Nstars")
    return
Ejemplo n.º 3
0
def plot_visits(visits, visitlim=None, etitle="", newfig=True):
    """Plot the location of the visits across the sky. Color code by number of visits."""
    if 'x' not in list(visits.keys()):
        visits['x'], visits['y'] = cpu.hammer_project_toxy(visits['ra']*deg2rad,
                                                          visits['dec']*deg2rad)
    gridsize = cpu.calc_gridsize(visits,binsize='fov', rad_fov=1.8)
    cpu.plot_density(visits['x'], visits['y'], gridsize=gridsize, zlimits=visitlim,
                    radecgrid=True, newfig=newfig)#, zscale='log')
    pyl.title("Visit density " + etitle, fontsize='medium')
    return
Ejemplo n.º 4
0
def plot_visits(visits, visitlim=None, etitle="", newfig=True):
    """Plot the location of the visits across the sky. Color code by number of visits."""
    if 'x' not in list(visits.keys()):
        visits['x'], visits['y'] = cpu.hammer_project_toxy(
            visits['ra'] * deg2rad, visits['dec'] * deg2rad)
    gridsize = cpu.calc_gridsize(visits, binsize='fov', rad_fov=1.8)
    cpu.plot_density(visits['x'],
                     visits['y'],
                     gridsize=gridsize,
                     zlimits=visitlim,
                     radecgrid=True,
                     newfig=newfig)  #, zscale='log')
    pyl.title("Visit density " + etitle, fontsize='medium')
    return
Ejemplo n.º 5
0
def plot_nstars_patch(patchdat, z_method=n.mean, zlimits=None, newfig=True):
    """Plot the n.min/mean/std number of stars ever seen in a particular patch."""
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(
            patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad)
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'],
                     patchdat['y'],
                     z=patchdat['nstars'],
                     z_method=z_method,
                     zlimits=zlimits,
                     gridsize=gridsize,
                     radecgrid=True,
                     newfig=newfig)
    pyl.title("Patch Minimum Nstars")
    return
Ejemplo n.º 6
0
def plot_nvisits_patch(patchdat, subpatch=None, patchlim=None, newfig=True):
    """Plot the location of the (sub)patches across the sky. Color code by number of visits.
    Also plot the number of stars observed in each patch. """
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad,
                                                            patchdat['dec']*deg2rad)
    if subpatch != None:
        condition = (patchdat['subpatch'] == subpatch)
        x = patchdat['x'][condition]
        y = patchdat['y'][condition]
    else:
        x = patchdat['x']
        y = patchdat['y']
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(x, y, gridsize=gridsize, zlimits=patchlim, radecgrid=True, newfig=newfig)
    pyl.title("Patch Density", fontsize='medium')
    return
Ejemplo n.º 7
0
def plot_patch_zpoffset(patchdat,
                        maglim=None,
                        etitle="",
                        newfig=True,
                        z_method=n.mean):
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(
            patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad)
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'],
                     patchdat['y'],
                     patchdat['dmag'],
                     z_method=z_method,
                     zlimits=maglim,
                     gridsize=gridsize,
                     radecgrid=True,
                     newfig=newfig,
                     cb_label='mag')
    figtitle = "Zeropoint Offsets " + etitle
    pyl.title(figtitle, fontsize='medium')
    return
Ejemplo n.º 8
0
def plot_nvisits_patch(patchdat, subpatch=None, patchlim=None, newfig=True):
    """Plot the location of the (sub)patches across the sky. Color code by number of visits.
    Also plot the number of stars observed in each patch. """
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(
            patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad)
    if subpatch != None:
        condition = (patchdat['subpatch'] == subpatch)
        x = patchdat['x'][condition]
        y = patchdat['y'][condition]
    else:
        x = patchdat['x']
        y = patchdat['y']
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(x,
                     y,
                     gridsize=gridsize,
                     zlimits=patchlim,
                     radecgrid=True,
                     newfig=newfig)
    pyl.title("Patch Density", fontsize='medium')
    return
Ejemplo n.º 9
0
def plot_stars_dmagcaltrue(stardat, maglim=None, etitle="", newfig=True,
                           starcal=None, z_method=n.mean):
    adjust_stardat = False
    if maglim !=0:
        maglim=n.round(n.array(maglim)*1000, decimals=1)
    if 'magcal' not in list(stardat.keys()):
        if starcal == None:
            raise Exception("Must either pass in starcal as well, or match_calvstrue previously")
        stardat = match_calvstrue(stardat, starcal)
        adjust_stardat = True
    if 'magdiff' not in list(stardat.keys()):
        stardat = adjust_calvstrue(stardat)
        adjust_stardat = True
    if 'x' not in list(stardat.keys()):
        stardat['x'], stardat['y'] = cpu.hammer_project_toxy(stardat['ra']*deg2rad,
                                                            stardat['dec']*deg2rad)
        adjust_stardat = True
    gridsize = cpu.calc_gridsize(stardat, binsize='patch')
    cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff']*1000, z_method=z_method,
                     zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='mmag')
    figtitle = "Stars dMag(true-bestfit) " + etitle
    pyl.title(figtitle, fontsize='medium')
    return stardat
Ejemplo n.º 10
0
def plot_patch_nstars(patchdat, maglim=None, etitle="", newfig=True,
                           patchcal=None, z_method=n.mean):
    adjust_patchdat = False
    if maglim != None:
        maglim=n.array(maglim)
    if 'dmagcal' not in list(patchdat.keys()):
        if patchcal == None:
            raise Exception("Must either pass in patchcal as well, or match_patch_calvstrue previously")
        patchdat = match_calvstrue(patchdat, starcal)
        adjust_patchdat = True
    if 'magdiff' not in list(patchdat.keys()):
        patchdat = adjust_calvstrue(patchdat)
        adjust_patchdat = True
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(patchdat['ra']*deg2rad,
                                                            patchdat['dec']*deg2rad)
        adjust_patchdat = True
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'], patchdat['y'], patchdat['nstars'], z_method=z_method,
                     zlimits=maglim, gridsize=gridsize, radecgrid=True, newfig=newfig, cb_label='')
    figtitle = "N stars per patch" + etitle
    pyl.title(figtitle, fontsize='medium')
    return patchdat
Ejemplo n.º 11
0
def plot_stars_dmagcaltrue(stardat,
                           maglim=None,
                           etitle="",
                           newfig=True,
                           starcal=None,
                           z_method=n.mean):
    adjust_stardat = False
    if maglim != 0:
        maglim = n.round(n.array(maglim) * 1000, decimals=1)
    if 'magcal' not in list(stardat.keys()):
        if starcal == None:
            raise Exception(
                "Must either pass in starcal as well, or match_calvstrue previously"
            )
        stardat = match_calvstrue(stardat, starcal)
        adjust_stardat = True
    if 'magdiff' not in list(stardat.keys()):
        stardat = adjust_calvstrue(stardat)
        adjust_stardat = True
    if 'x' not in list(stardat.keys()):
        stardat['x'], stardat['y'] = cpu.hammer_project_toxy(
            stardat['ra'] * deg2rad, stardat['dec'] * deg2rad)
        adjust_stardat = True
    gridsize = cpu.calc_gridsize(stardat, binsize='patch')
    cpu.plot_density(stardat['x'],
                     stardat['y'],
                     stardat['magdiff'] * 1000,
                     z_method=z_method,
                     zlimits=maglim,
                     gridsize=gridsize,
                     radecgrid=True,
                     newfig=newfig,
                     cb_label='mmag')
    figtitle = "Stars dMag(true-bestfit) " + etitle
    pyl.title(figtitle, fontsize='medium')
    return stardat
Ejemplo n.º 12
0
def plot_patch_nstars(patchdat,
                      maglim=None,
                      etitle="",
                      newfig=True,
                      patchcal=None,
                      z_method=n.mean):
    adjust_patchdat = False
    if maglim != None:
        maglim = n.array(maglim)
    if 'dmagcal' not in list(patchdat.keys()):
        if patchcal == None:
            raise Exception(
                "Must either pass in patchcal as well, or match_patch_calvstrue previously"
            )
        patchdat = match_calvstrue(patchdat, starcal)
        adjust_patchdat = True
    if 'magdiff' not in list(patchdat.keys()):
        patchdat = adjust_calvstrue(patchdat)
        adjust_patchdat = True
    if 'x' not in list(patchdat.keys()):
        patchdat['x'], patchdat['y'] = cpu.hammer_project_toxy(
            patchdat['ra'] * deg2rad, patchdat['dec'] * deg2rad)
        adjust_patchdat = True
    gridsize = cpu.calc_gridsize(patchdat, binsize='patch')
    cpu.plot_density(patchdat['x'],
                     patchdat['y'],
                     patchdat['nstars'],
                     z_method=z_method,
                     zlimits=maglim,
                     gridsize=gridsize,
                     radecgrid=True,
                     newfig=newfig,
                     cb_label='')
    figtitle = "N stars per patch" + etitle
    pyl.title(figtitle, fontsize='medium')
    return patchdat
cpu.plot_density(stardat['x'],stardat['y'],z=stardat['color'],z_method=n.std,radecgrid=True)
pyl.title('$\sigma(g-i)$')
if savefig:
    pyl.savefig('Starcolorstd.png', format='png')
pyl.figure()
ack1,ack2,ack3 = pyl.hist(stardat['color'], bins=100)
pyl.xlabel('$(g-i)$')
pyl.ylabel('Number of stars')
pyl.title('Color Distribution of Calibration Stars')
pyl.savefig('Starcolorhist.png', format='png')

visits=cp.read_visitfile()
#histogram up the visits, set visitlim to [0,90th%ile]
#do a pre-bin to crop range and 90th %tile
x, y = cpu.hammer_project_toxy(visits['ra']*deg2rad,\
                           visits['dec']*deg2rad)
gridsize = cpu.calc_gridsize(visits,binsize='fov', rad_fov=1.8)
ack=pyl.hexbin(x,y,gridsize=gridsize, mincnt=0.5)
counts=ack.get_array()
hist, bins=n.histogram(counts, n.arange(max(counts)+1))
nc=n.cumsum(hist, dtype=float)/n.sum(hist)
visit_max=bins[n.max(n.where(nc < 0.99))]

pyl.figure()
cp.plot_visits(visits, visitlim=[1,visit_max])
if savefig:
    pyl.savefig('Visitdensity.png',format='png')


Ejemplo n.º 14
0
def starPlots(truestarfile = "stardata.dat", bestfitstarfile = "test_bestfit_Star.dat"):

    #assume both the files are sorted by star id.
    stardat = cp.read_true_stars(truestarfile) #keys are ('id', 'dbid', 'ra', 'dec', 'magtrue', 'color')
    starcal = ui.readDatafile(bestfitstarfile, keys=('id','magcal','rms','iqr_sigma','nobs'))
    HP = True
    if np.size(starcal['id']) == 0:
        starcal = ui.readDatafile(bestfitstarfile, keys=('id','magcal'))
        HP = False                     
    fitted_stars = np.in1d(stardat['id'], starcal['id'])
    for key in stardat.keys():
        stardat[key] = stardat[key][fitted_stars]
    for key in starcal.keys():
        stardat[key] = starcal[key]
    stardat['magdiff'] = stardat['magcal'] - stardat['magtrue']
    stardat = cp.adjust_stars_calvstrue(stardat)

    starResults = {}
    HPResults = {}
    starResults['N stars Fit'] = np.size(stardat['magdiff'])

    outlier_clip=np.where(np.abs(stardat['magdiff']) < .05)
    rms = stardat['magdiff'][outlier_clip].std()
    print 'true-bestfit RMS = %f, true-bestfit (clipped) = %f'%(stardat['magdiff'].std(), rms)
    lim = rms*2.5
    if lim < 0.001:
        lim = round(lim * 10000) / 10000.0
    elif lim < 0.01:
        lim = round(lim * 1000) / 1000.0
    print "Using magnitude limits for plots of %f, %f" %(-lim, lim)
    maglim= [-lim, lim]
    
    starResults['Residuals RMS (mmag)'] = stardat['magdiff'].std()*1e3
    starResults['IQR_sigma (mmag)'] = so.robustSigma(stardat['magdiff'])*1e3
    
    #star residual map
    stardat['x'], stardat['y'] = cpu.hammer_project_toxy(stardat['ra']*deg2rad,
                                                         stardat['dec']*deg2rad)
    gridsize = cpu.calc_gridsize(stardat, binsize='patch')
    etitle = " RMS = %4.1f mmag"%(rms*1000)
    cpu.plot_density(stardat['x'], stardat['y'], stardat['magdiff']*1000, z_method=np.mean,
                     zlimits=np.array(maglim)*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag')
    figtitle = "Stars dMag(true-bestfit)"
    pyl.title(figtitle, fontsize='medium')
    pyl.savefig('Sdmag.png',type='png')

    
    maglim2 = [0, maglim[1]/2.]
    cp.plot_stars_dmagcaltrue(stardat, maglim=maglim2, etitle=" RMS "+etitle, z_method=np.std)
    pyl.savefig('Sdmag_rms.png', format='png')

    histrange = [maglim[0]*2.5, maglim[1]*2.5]
    nbins = 100
    cp.histogram_stars_dmagcaltrue(stardat, nbins=nbins, range=histrange, etitle=etitle)
    pyl.savefig('Sdamg_hist.png', format='png')


   
  
    #color distribution of stars
    pyl.figure()
    pyl.hist(stardat['color'], bins=100)
    pyl.xlabel(r'$g-i$')
    pyl.ylabel('# of stars')
    pyl.title('Color Distribution')
    pyl.savefig('Scolordist.png',type='png')


    #accuracy v color
    pyl.figure()
    #pyl.scatter(stardat['color'], stardat['magdiff']*1000., c=stardat['magtrue'], alpha=0.1,edgecolors=None)
    pyl.hexbin(stardat['color'], stardat['magdiff']*1000., bins='log')
    cb=pyl.colorbar()
    cb.ax.set_ylabel(r'$\log{\rm{N}}$')
    pyl.xlabel(r'$g-i$')
    pyl.ylabel('Bestfit-True (mmag)')
    pyl.savefig('Saccuracyvcolor.png',type='png')

    
    #accuracy v mag
    pyl.figure()
    #pyl.scatter(stardat['magtrue'], stardat['magdiff']*1000., c=stardat['color'], alpha=0.1,edgecolors=None)
    pyl.hexbin(stardat['magtrue'], stardat['magdiff']*1000., bins='log')
    cb=pyl.colorbar()
    cb.ax.set_ylabel(r'$\log{\rm{N}}$')
    pyl.xlabel('True Mag')
    pyl.ylabel('Bestfit-True (mmag)')
    pyl.savefig('Saccuracyvmag.png',type='png')

    if HP:

        zlim = [np.min(stardat['nobs']), (np.median(stardat['nobs'])-np.min(stardat['nobs']))+np.median(stardat['nobs'])]
        cpu.plot_density(stardat['x'], stardat['y'],stardat['nobs'], z_method=np.mean,
                         zlimits=zlim, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='N observations')
        pyl.title('Visit Density')
        pyl.savefig('Snobs.png', format='png')

        pyl.figure()
        #I should just figure out from the data what nsides is!
        hpid = hp.ang2pix(16, (stardat['dec']+90.)*deg2rad, stardat['ra']*deg2rad)
        cpu.plot_density(stardat['x'], stardat['y'],np.mod(hpid,250), z_method=np.median,
                          gridsize=gridsize, radecgrid=True, newfig=True, cb_label='HEALpix ID mod 250')
        pyl.title("HEALpix Map")
        pyl.savefig('HPid.png')
        HPResults['number of HEALpix'] = np.size(np.unique(hpid))
        
        pyl.figure()
        num, b, p = pyl.hist(stardat['nobs'], bins=100, range=zlim, histtype='bar')
        pyl.xlabel("Number of Observations per Star")
        pyl.title('Median = %d'%np.median(stardat['nobs']))
        pyl.savefig('Snobs_hist.png',type='png')
        starResults['median repeat obs'] = np.median(stardat['nobs'])

        pyl.figure()
        x = np.sort(stardat['iqr_sigma'])*1e3
        y = np.arange(np.size(x), dtype='float')
        y = y/np.max(y)
        per50 = np.max(np.where(y <= .5))
        per90 = np.max(np.where(y <= .9))
        pyl.plot(x,y, 'k--', label='IQR, 50th,90th %2.1f, %2.1f'%(x[per50],x[per90]))
        pyl.plot([0,x[per50]],[y[per50],y[per50]],'b--')
        pyl.plot([x[per50],x[per50]],[0,y[per50]],'b--')
        pyl.plot([0,x[per90]],[y[per90],y[per90]],'b--')
        pyl.plot([x[per90],x[per90]],[0,y[per90]],'b--')
        #pyl.title('Cumulative Distribution of Stellar Repeatability')
        #pyl.xlabel('Repeatability IQR RMS (mmag)')
        #pyl.ylabel('Cumulative Fraction')
        #pyl.savefig('Srepeat_IQR_cumulative.png',type='png')
        pyl.legend()
        pyl.savefig('Srepeat_cumulative.png',type='png')

       #repeatability from IQR
        rs = so.robustSigma(stardat['iqr_sigma'])
        med = np.median(stardat['iqr_sigma'])
        maglim = np.around(np.array([med-3*rs, med+3.*rs])*1000, decimals=2)/1000
        cpu.plot_density(stardat['x'], stardat['y'], stardat['iqr_sigma']*1000, z_method=np.mean,
                         zlimits=maglim*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag')
        pyl.title('Repeatability (IQR)')
        pyl.savefig('Srepeat_IQR.png',type='png')


        pyl.figure()
        num, b, p = pyl.hist(stardat['iqr_sigma']*1000, bins=100, range=maglim*1000, histtype='bar')
        pyl.xlabel('RMS per star (mmag)')
        pyl.title('Repeatability IQR, Median = %4.2f mmag'%np.median(stardat['iqr_sigma']*1000))
        pyl.savefig('Srepeat_IQR_hist.png',type='png')
        starResults['Median Repeatability (IQR) (mmag)'] = np.median(med)*1e3


        pyl.figure()
        good = np.where(stardat['magtrue'] < 18)
        num, b, p = pyl.hist(stardat['iqr_sigma'][good]*1000, bins=100, range=maglim*1000, histtype='bar')
        pyl.xlabel('RMS per star, m < 18 (mmag)')
        pyl.title('Repeatability IQR, Median = %4.2f mmag'%np.median(stardat['iqr_sigma'][good]*1000))
        pyl.savefig('Srepeat_IQR_bright_hist.png',type='png')
        starResults['Median Repeatability Bright (IQR) (mmag)'] = np.median(stardat['iqr_sigma'][good])*1e3
     

        #repeatability v color
        pyl.figure()
        #pyl.plot(stardat['color'], stardat['rms']*1000., 'ko', alpha=.1)
        pyl.hexbin(stardat['color'], stardat['iqr_sigma']*1000., bins='log')
        cb = pyl.colorbar()
        cb.set_label(r'$\log{\rm{N}}$')
        pyl.ylim([0,40])
        pyl.xlabel(r'$g-i$')
        pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)')
        pyl.savefig('Srepeatvcolor.png',type='png')

        #repeatability v mag
        pyl.figure()
        #pyl.plot(stardat['magtrue'], stardat['rms']*1000., 'ko', alpha=.1)
        pyl.hexbin(stardat['magtrue'], stardat['iqr_sigma']*1000.,bins='log')
        cb = pyl.colorbar()
        cb.set_label(r'$\log{\rm{N}}$')
        pyl.ylim([0,40])
        pyl.xlabel('True Mag')
        pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)')
        pyl.savefig('Srepeatvmag.png',type='png')


        #repeatability
        rs = so.robustSigma(stardat['rms'])
        med = np.median(stardat['rms'])
        maglim = np.around(np.array([med-3*rs, med+3.*rs])*1000, decimals=2)/1000
        cpu.plot_density(stardat['x'], stardat['y'], stardat['rms']*1000, z_method=np.mean,
                         zlimits=maglim*1000, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag')
        pyl.title('Repeatability')
        pyl.savefig('Srepeat.png',type='png')

        pyl.figure()
        num, b, p = pyl.hist(stardat['rms']*1000, bins=100, range=maglim*1000, histtype='bar')
        pyl.xlabel('RMS per star (mmag)')
        pyl.title('Repeatability, Median = %4.2f mmag'%np.median(stardat['rms']*1000))
        pyl.savefig('Srepeat_hist.png',type='png')
        starResults['Median Repeatability (mmag)'] = np.median(med)*1e3

        pyl.figure()
        x = np.sort(stardat['rms'])*1e3
        y = np.arange(np.size(x), dtype='float')
        y = y/np.max(y)
        per50 = np.max(np.where(y <= .5))
        per90 = np.max(np.where(y <= .9))
        pyl.plot(x,y, 'k', label='RMS, %2.1f, %2.1f'%(x[per50],x[per90]))
        pyl.plot([0,x[per50]],[y[per50],y[per50]],'k')
        pyl.plot([x[per50],x[per50]],[0,y[per50]],'k')
        pyl.plot([0,x[per90]],[y[per90],y[per90]],'k')
        pyl.plot([x[per90],x[per90]],[0,y[per90]],'k')
        pyl.title('Cumulative Distribution of Stellar Repeatability')
        pyl.xlabel('Repeatability RMS (mmag)')
        pyl.ylabel('Cumulative Fraction')
        pyl.savefig('Srepeat_cumulative.png',type='png')


        #need to make a spatial uniformity plot since we can now have varying densities of stars.  
        nside = 64
        stardat['hpid'] = hp.ang2pix(nside, (stardat['dec']+90.)*deg2rad, stardat['ra']*deg2rad)
        uhpid = np.unique(stardat['hpid'])
        hp_mean = uhpid*0.
        hp_std = uhpid*0.
        hp_dec, hp_ra = hp.pix2ang(nside,uhpid)
        #hp_ra = hp_ra
        hp_dec = hp_dec-90.*deg2rad
        hp_x, hp_y = cpu.hammer_project_toxy(hp_ra, hp_dec)
        stardat = dictsort(stardat,'hpid')

        left = np.searchsorted(stardat['hpid'], uhpid)
        right = np.searchsorted(stardat['hpid'], uhpid,side='right')

        for i in np.arange(left.size):
            hp_mean[i] = np.mean(stardat['magdiff'][left[i]:right[i]])
            hp_std[i] = np.std(stardat['magdiff'][left[i]:right[i]])

        cpu.plot_density(hp_x, hp_y, hp_mean*1000, z_method=np.mean,
                         zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag')
        HPResults['Spatial Uniformity RMS (mmag)'] = np.std(hp_mean)*1e3
        HPResults['Spatial Uniformity IQR RMS (mmag)'] = so.robustSigma(hp_mean)*1e3

        pyl.title('mean(True-Bestfit), binned by HEALpix')
        pyl.savefig('HPresid.png',type='png')

        cpu.plot_density(hp_x, hp_y, hp_std*1000, z_method=np.mean,
                         zlimits=None, gridsize=gridsize, radecgrid=True, newfig=True, cb_label='mmag')

        pyl.title('std(True-Bestfit), binned by HEALpix')
        pyl.savefig('HPstd.png',type='png')

        pyl.figure()
        num, b, p = pyl.hist( hp_mean*1000, bins=100, range=None, histtype='bar')
        pyl.xlabel("HEALpix(True-Bestfit) (mmag)")
        pyl.title('Spatial Uniformity, RMS=%4.2f'%HPResults['Spatial Uniformity RMS (mmag)'])
        pyl.savefig('HPmean_hist.png',type='png')

        pyl.figure()
        num, b, p = pyl.hist( hp_std*1000, bins=100, range=None, histtype='bar')
        pyl.xlabel("std(True-Bestfit) per HEALpix (mmag)")
        pyl.title('Variation within HEALpix, median=%4.2f mmag'%np.median(hp_std*1000))
        pyl.savefig('HPstd_hist.png',type='png')

    

    return starResults,HPResults
Ejemplo n.º 15
0
def starPlots(truestarfile="stardata.dat",
              bestfitstarfile="test_bestfit_Star.dat"):

    #assume both the files are sorted by star id.
    stardat = cp.read_true_stars(
        truestarfile
    )  #keys are ('id', 'dbid', 'ra', 'dec', 'magtrue', 'color')
    starcal = ui.readDatafile(bestfitstarfile,
                              keys=('id', 'magcal', 'rms', 'iqr_sigma',
                                    'nobs'))
    HP = True
    if np.size(starcal['id']) == 0:
        starcal = ui.readDatafile(bestfitstarfile, keys=('id', 'magcal'))
        HP = False
    fitted_stars = np.in1d(stardat['id'], starcal['id'])
    for key in list(stardat.keys()):
        stardat[key] = stardat[key][fitted_stars]
    for key in list(starcal.keys()):
        stardat[key] = starcal[key]
    stardat['magdiff'] = stardat['magcal'] - stardat['magtrue']
    stardat = cp.adjust_stars_calvstrue(stardat)

    starResults = {}
    HPResults = {}
    starResults['N stars Fit'] = np.size(stardat['magdiff'])

    outlier_clip = np.where(np.abs(stardat['magdiff']) < .05)
    rms = stardat['magdiff'][outlier_clip].std()
    print('true-bestfit RMS = %f, true-bestfit (clipped) = %f' %
          (stardat['magdiff'].std(), rms))
    lim = rms * 2.5
    if lim < 0.001:
        lim = round(lim * 10000) / 10000.0
    elif lim < 0.01:
        lim = round(lim * 1000) / 1000.0
    print("Using magnitude limits for plots of %f, %f" % (-lim, lim))
    maglim = [-lim, lim]

    starResults['Residuals RMS (mmag)'] = stardat['magdiff'].std() * 1e3
    starResults['IQR_sigma (mmag)'] = so.robustSigma(stardat['magdiff']) * 1e3

    #star residual map
    stardat['x'], stardat['y'] = cpu.hammer_project_toxy(
        stardat['ra'] * deg2rad, stardat['dec'] * deg2rad)
    gridsize = cpu.calc_gridsize(stardat, binsize='patch')
    etitle = " RMS = %4.1f mmag" % (rms * 1000)
    cpu.plot_density(stardat['x'],
                     stardat['y'],
                     stardat['magdiff'] * 1000,
                     z_method=np.mean,
                     zlimits=np.array(maglim) * 1000,
                     gridsize=gridsize,
                     radecgrid=True,
                     newfig=True,
                     cb_label='mmag')
    figtitle = "Stars dMag(true-bestfit)"
    pyl.title(figtitle, fontsize='medium')
    pyl.savefig('Sdmag.png', type='png')

    maglim2 = [0, maglim[1] / 2.]
    cp.plot_stars_dmagcaltrue(stardat,
                              maglim=maglim2,
                              etitle=" RMS " + etitle,
                              z_method=np.std)
    pyl.savefig('Sdmag_rms.png', format='png')

    histrange = [maglim[0] * 2.5, maglim[1] * 2.5]
    nbins = 100
    cp.histogram_stars_dmagcaltrue(stardat,
                                   nbins=nbins,
                                   range=histrange,
                                   etitle=etitle)
    pyl.savefig('Sdamg_hist.png', format='png')

    #color distribution of stars
    pyl.figure()
    pyl.hist(stardat['color'], bins=100)
    pyl.xlabel(r'$g-i$')
    pyl.ylabel('# of stars')
    pyl.title('Color Distribution')
    pyl.savefig('Scolordist.png', type='png')

    #accuracy v color
    pyl.figure()
    #pyl.scatter(stardat['color'], stardat['magdiff']*1000., c=stardat['magtrue'], alpha=0.1,edgecolors=None)
    pyl.hexbin(stardat['color'], stardat['magdiff'] * 1000., bins='log')
    cb = pyl.colorbar()
    cb.ax.set_ylabel(r'$\log{\rm{N}}$')
    pyl.xlabel(r'$g-i$')
    pyl.ylabel('Bestfit-True (mmag)')
    pyl.savefig('Saccuracyvcolor.png', type='png')

    #accuracy v mag
    pyl.figure()
    #pyl.scatter(stardat['magtrue'], stardat['magdiff']*1000., c=stardat['color'], alpha=0.1,edgecolors=None)
    pyl.hexbin(stardat['magtrue'], stardat['magdiff'] * 1000., bins='log')
    cb = pyl.colorbar()
    cb.ax.set_ylabel(r'$\log{\rm{N}}$')
    pyl.xlabel('True Mag')
    pyl.ylabel('Bestfit-True (mmag)')
    pyl.savefig('Saccuracyvmag.png', type='png')

    if HP:

        zlim = [
            np.min(stardat['nobs']),
            (np.median(stardat['nobs']) - np.min(stardat['nobs'])) +
            np.median(stardat['nobs'])
        ]
        cpu.plot_density(stardat['x'],
                         stardat['y'],
                         stardat['nobs'],
                         z_method=np.mean,
                         zlimits=zlim,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='N observations')
        pyl.title('Visit Density')
        pyl.savefig('Snobs.png', format='png')

        pyl.figure()
        #I should just figure out from the data what nsides is!
        hpid = hp.ang2pix(16, (stardat['dec'] + 90.) * deg2rad,
                          stardat['ra'] * deg2rad)
        cpu.plot_density(stardat['x'],
                         stardat['y'],
                         np.mod(hpid, 250),
                         z_method=np.median,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='HEALpix ID mod 250')
        pyl.title("HEALpix Map")
        pyl.savefig('HPid.png')
        HPResults['number of HEALpix'] = np.size(np.unique(hpid))

        pyl.figure()
        num, b, p = pyl.hist(stardat['nobs'],
                             bins=100,
                             range=zlim,
                             histtype='bar')
        pyl.xlabel("Number of Observations per Star")
        pyl.title('Median = %d' % np.median(stardat['nobs']))
        pyl.savefig('Snobs_hist.png', type='png')
        starResults['median repeat obs'] = np.median(stardat['nobs'])

        pyl.figure()
        x = np.sort(stardat['iqr_sigma']) * 1e3
        y = np.arange(np.size(x), dtype='float')
        y = y / np.max(y)
        per50 = np.max(np.where(y <= .5))
        per90 = np.max(np.where(y <= .9))
        pyl.plot(x,
                 y,
                 'k--',
                 label='IQR, 50th,90th %2.1f, %2.1f' % (x[per50], x[per90]))
        pyl.plot([0, x[per50]], [y[per50], y[per50]], 'b--')
        pyl.plot([x[per50], x[per50]], [0, y[per50]], 'b--')
        pyl.plot([0, x[per90]], [y[per90], y[per90]], 'b--')
        pyl.plot([x[per90], x[per90]], [0, y[per90]], 'b--')
        #pyl.title('Cumulative Distribution of Stellar Repeatability')
        #pyl.xlabel('Repeatability IQR RMS (mmag)')
        #pyl.ylabel('Cumulative Fraction')
        #pyl.savefig('Srepeat_IQR_cumulative.png',type='png')
        pyl.legend()
        pyl.savefig('Srepeat_cumulative.png', type='png')

        #repeatability from IQR
        rs = so.robustSigma(stardat['iqr_sigma'])
        med = np.median(stardat['iqr_sigma'])
        maglim = np.around(np.array([med - 3 * rs, med + 3. * rs]) * 1000,
                           decimals=2) / 1000
        cpu.plot_density(stardat['x'],
                         stardat['y'],
                         stardat['iqr_sigma'] * 1000,
                         z_method=np.mean,
                         zlimits=maglim * 1000,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='mmag')
        pyl.title('Repeatability (IQR)')
        pyl.savefig('Srepeat_IQR.png', type='png')

        pyl.figure()
        num, b, p = pyl.hist(stardat['iqr_sigma'] * 1000,
                             bins=100,
                             range=maglim * 1000,
                             histtype='bar')
        pyl.xlabel('RMS per star (mmag)')
        pyl.title('Repeatability IQR, Median = %4.2f mmag' %
                  np.median(stardat['iqr_sigma'] * 1000))
        pyl.savefig('Srepeat_IQR_hist.png', type='png')
        starResults['Median Repeatability (IQR) (mmag)'] = np.median(med) * 1e3

        pyl.figure()
        good = np.where(stardat['magtrue'] < 18)
        num, b, p = pyl.hist(stardat['iqr_sigma'][good] * 1000,
                             bins=100,
                             range=maglim * 1000,
                             histtype='bar')
        pyl.xlabel('RMS per star, m < 18 (mmag)')
        pyl.title('Repeatability IQR, Median = %4.2f mmag' %
                  np.median(stardat['iqr_sigma'][good] * 1000))
        pyl.savefig('Srepeat_IQR_bright_hist.png', type='png')
        starResults['Median Repeatability Bright (IQR) (mmag)'] = np.median(
            stardat['iqr_sigma'][good]) * 1e3

        #repeatability v color
        pyl.figure()
        #pyl.plot(stardat['color'], stardat['rms']*1000., 'ko', alpha=.1)
        pyl.hexbin(stardat['color'], stardat['iqr_sigma'] * 1000., bins='log')
        cb = pyl.colorbar()
        cb.set_label(r'$\log{\rm{N}}$')
        pyl.ylim([0, 40])
        pyl.xlabel(r'$g-i$')
        pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)')
        pyl.savefig('Srepeatvcolor.png', type='png')

        #repeatability v mag
        pyl.figure()
        #pyl.plot(stardat['magtrue'], stardat['rms']*1000., 'ko', alpha=.1)
        pyl.hexbin(stardat['magtrue'],
                   stardat['iqr_sigma'] * 1000.,
                   bins='log')
        cb = pyl.colorbar()
        cb.set_label(r'$\log{\rm{N}}$')
        pyl.ylim([0, 40])
        pyl.xlabel('True Mag')
        pyl.ylabel(r'Repeatability $\sigma_{\rm{IQR}}$ (mmag)')
        pyl.savefig('Srepeatvmag.png', type='png')

        #repeatability
        rs = so.robustSigma(stardat['rms'])
        med = np.median(stardat['rms'])
        maglim = np.around(np.array([med - 3 * rs, med + 3. * rs]) * 1000,
                           decimals=2) / 1000
        cpu.plot_density(stardat['x'],
                         stardat['y'],
                         stardat['rms'] * 1000,
                         z_method=np.mean,
                         zlimits=maglim * 1000,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='mmag')
        pyl.title('Repeatability')
        pyl.savefig('Srepeat.png', type='png')

        pyl.figure()
        num, b, p = pyl.hist(stardat['rms'] * 1000,
                             bins=100,
                             range=maglim * 1000,
                             histtype='bar')
        pyl.xlabel('RMS per star (mmag)')
        pyl.title('Repeatability, Median = %4.2f mmag' %
                  np.median(stardat['rms'] * 1000))
        pyl.savefig('Srepeat_hist.png', type='png')
        starResults['Median Repeatability (mmag)'] = np.median(med) * 1e3

        pyl.figure()
        x = np.sort(stardat['rms']) * 1e3
        y = np.arange(np.size(x), dtype='float')
        y = y / np.max(y)
        per50 = np.max(np.where(y <= .5))
        per90 = np.max(np.where(y <= .9))
        pyl.plot(x, y, 'k', label='RMS, %2.1f, %2.1f' % (x[per50], x[per90]))
        pyl.plot([0, x[per50]], [y[per50], y[per50]], 'k')
        pyl.plot([x[per50], x[per50]], [0, y[per50]], 'k')
        pyl.plot([0, x[per90]], [y[per90], y[per90]], 'k')
        pyl.plot([x[per90], x[per90]], [0, y[per90]], 'k')
        pyl.title('Cumulative Distribution of Stellar Repeatability')
        pyl.xlabel('Repeatability RMS (mmag)')
        pyl.ylabel('Cumulative Fraction')
        pyl.savefig('Srepeat_cumulative.png', type='png')

        #need to make a spatial uniformity plot since we can now have varying densities of stars.
        nside = 64
        stardat['hpid'] = hp.ang2pix(nside, (stardat['dec'] + 90.) * deg2rad,
                                     stardat['ra'] * deg2rad)
        uhpid = np.unique(stardat['hpid'])
        hp_mean = uhpid * 0.
        hp_std = uhpid * 0.
        hp_dec, hp_ra = hp.pix2ang(nside, uhpid)
        #hp_ra = hp_ra
        hp_dec = hp_dec - 90. * deg2rad
        hp_x, hp_y = cpu.hammer_project_toxy(hp_ra, hp_dec)
        stardat = dictsort(stardat, 'hpid')

        left = np.searchsorted(stardat['hpid'], uhpid)
        right = np.searchsorted(stardat['hpid'], uhpid, side='right')

        for i in np.arange(left.size):
            hp_mean[i] = np.mean(stardat['magdiff'][left[i]:right[i]])
            hp_std[i] = np.std(stardat['magdiff'][left[i]:right[i]])

        cpu.plot_density(hp_x,
                         hp_y,
                         hp_mean * 1000,
                         z_method=np.mean,
                         zlimits=None,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='mmag')
        HPResults['Spatial Uniformity RMS (mmag)'] = np.std(hp_mean) * 1e3
        HPResults['Spatial Uniformity IQR RMS (mmag)'] = so.robustSigma(
            hp_mean) * 1e3

        pyl.title('mean(True-Bestfit), binned by HEALpix')
        pyl.savefig('HPresid.png', type='png')

        cpu.plot_density(hp_x,
                         hp_y,
                         hp_std * 1000,
                         z_method=np.mean,
                         zlimits=None,
                         gridsize=gridsize,
                         radecgrid=True,
                         newfig=True,
                         cb_label='mmag')

        pyl.title('std(True-Bestfit), binned by HEALpix')
        pyl.savefig('HPstd.png', type='png')

        pyl.figure()
        num, b, p = pyl.hist(hp_mean * 1000,
                             bins=100,
                             range=None,
                             histtype='bar')
        pyl.xlabel("HEALpix(True-Bestfit) (mmag)")
        pyl.title('Spatial Uniformity, RMS=%4.2f' %
                  HPResults['Spatial Uniformity RMS (mmag)'])
        pyl.savefig('HPmean_hist.png', type='png')

        pyl.figure()
        num, b, p = pyl.hist(hp_std * 1000,
                             bins=100,
                             range=None,
                             histtype='bar')
        pyl.xlabel("std(True-Bestfit) per HEALpix (mmag)")
        pyl.title('Variation within HEALpix, median=%4.2f mmag' %
                  np.median(hp_std * 1000))
        pyl.savefig('HPstd_hist.png', type='png')

    return starResults, HPResults
Ejemplo n.º 16
0
                 stardat['y'],
                 z=stardat['color'],
                 z_method=n.std,
                 radecgrid=True)
pyl.title('$\sigma(g-i)$')
if savefig:
    pyl.savefig('Starcolorstd.png', format='png')
pyl.figure()
ack1, ack2, ack3 = pyl.hist(stardat['color'], bins=100)
pyl.xlabel('$(g-i)$')
pyl.ylabel('Number of stars')
pyl.title('Color Distribution of Calibration Stars')
pyl.savefig('Starcolorhist.png', format='png')

visits = cp.read_visitfile()
#histogram up the visits, set visitlim to [0,90th%ile]
#do a pre-bin to crop range and 90th %tile
x, y = cpu.hammer_project_toxy(visits['ra']*deg2rad,\
                           visits['dec']*deg2rad)
gridsize = cpu.calc_gridsize(visits, binsize='fov', rad_fov=1.8)
ack = pyl.hexbin(x, y, gridsize=gridsize, mincnt=0.5)
counts = ack.get_array()
hist, bins = n.histogram(counts, n.arange(max(counts) + 1))
nc = n.cumsum(hist, dtype=float) / n.sum(hist)
visit_max = bins[n.max(n.where(nc < 0.99))]

pyl.figure()
cp.plot_visits(visits, visitlim=[1, visit_max])
if savefig:
    pyl.savefig('Visitdensity.png', format='png')