IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20459


Ignore:
Timestamp:
Oct 29, 2008, 6:35:57 AM (18 years ago)
Author:
Sebastian Jester
Message:

Add plot-merging function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sj_ippTests_branch_20080929/ippTests/compIPPphoto.py

    r20285 r20459  
    5858#
    5959# Convention: for scatter, plot second against first; for histogram, plot both histograms
     60
     61
     62# XXX Todo: labels! group by runs? different colours for different
     63# bands; include seeing? plot things against seeing?
     64
    6065plotcol_1frame_tlist = [
    6166    (['d_sky'],['d_mag'],'scatter')
     
    6368    ,(['sky_ps1'],['d_mag'],'scatter')
    6469    ,(['psfinstmag_sdss'],['d_mag'],'scatter')
     70    ,(['psfinstmag_sdss'],['d_sky'],'scatter')
    6571    ,(['m_rr_cc_psf'],['d_mag'],'scatter')
     72    ,(['sky_sdss'],['sky_ps1'],'scatter')
    6673    ,(['psfinstmag_sdss'],['psf_inst_mag'],'histogram')
    6774    ,(['sky_sdss'],['sky_ps1'],'histogram')
     
    7582    ,(['d_x_median'],['d_y_median'],'scatter')
    7683    ,(['d_mag_median'],['N_SDSS'],'scatter')
    77     ,(['d_mag_median','d_mag_mean'],['field','field'],'scatter')
     84    ,(['field','field'],['d_mag_median','d_mag_mean'],'scatter')
    7885    ]
    7986
     87def mergePlots(plotcol_1frame_tlist=plotcol_1frame_tlist,filtlist=['u','g','r','i','z'],workdir='/IPP/data/SDSS/stripe82/coadd/compare'):
     88    from subprocess import call
     89    from glob import glob
     90    import os
     91    os.chdir(workdir)
     92    for tup in plotcol_1frame_tlist:
     93        t1,t2,t3=tup
     94        for filt in filtlist:
     95            globstr = getOutnameStatsOnefile("match_%s_*"%(filt),t3,t1,t2)
     96            filelist = glob(globstr)
     97            outname = getOutnameStatsOnefile("merged_%s" %(filt),t3,t1,t2)
     98            cmdstr = "gs -dNOPAUSE -sDEVICE=pswrite -sOutputFile=%s %s -c quit" %(outname,' '.join(filelist))
     99            print "Making %s" %(outname)
     100            call(cmdstr,shell=True)
     101            call("gzip %s" %(outname),shell=True)
    80102
    81103def compIPPphoto(summaryTable,mode,plotcol_1frame_tlist=plotcol_1frame_tlist,\
     
    109131    stats_hash={}
    110132    chipfile_l,fpObjc_l = makePlan()
     133    filters = []
     134    bandindex_hash = {}
    111135    for chipfile,fpObjc in zip(chipfile_l,fpObjc_l):
    112136        matchtable,filter_name,bandindex = matchSdssPs1(fpObjc,chipfile,skip=skip)
     137        if filter_name not in filters:
     138            filters.append(filter_name)
     139            bandindex_hash[filter_name] = bandindex
    113140        stats_hash, column_hash, goodrow_hash = computeStatistics(matchtable)
    114141        # Sort res_hash by its column names to make sure order is
     
    131158    # Fake a goodrows hash
    132159    sumgoodrows_hash = summaryhash.fromkeys(summaryhash.keys(),numpy.ones((nrows,),bool))
    133     plotStatsOnefile(summaryhash,sumgoodrows_hash,summaryTable,plotcol_summary_tlist,bandindex)
     160    for filt in filters:
     161        plotStatsOnefile(summaryhash,sumgoodrows_hash,summaryTable,plotcol_summary_tlist,bandindex_hash[filt],bandid=filt)
     162    mergePlots(plotcol_1frame_tlist=plotcol_1frame_tlist,filtlist=filters)
    134163    return column_hash,goodrow_hash
     164
     165# XXX Todo: check histogram axis scaling!
    135166
    136167def hashFromPyfitsTable(pyfitsTableHDU):
     
    144175    return outhash
    145176
    146 def getOutnameStatsOnefile(matchtable,kind,col1_l,col2_l=None,format='eps'):
     177def getOutnameStatsOnefile(matchtable,kind,col1_l,col2_l=None,format='eps',bandid=''):
    147178    import re
    148179    # Construct output filename
    149180    root = re.sub('(\.[sc]mf|\.fits?)$','',matchtable)
     181    if bandid != '':
     182        root = "%s_%s" %(root,bandid)
    150183    if isNone(col2_l):
    151184        outname = '%s_%s_%s.%s' % (root,kind,col1[0],format)
     
    157190    return outname
    158191   
    159 def plotStatsOnefile(values_hash,goodrow_hash,matchtable,plotcol_tlist,bandindex,format='eps'):
     192def plotStatsOnefile(values_hash,goodrow_hash,matchtable,plotcol_tlist,bandindex,format='eps',bandid=''):
    160193    """Make diagnostic plots for a single table, based on values
    161194    in values_hash"""
    162195    from numpy import concatenate
    163196    from sm import cvar,angle
     197    import re
    164198    # In histograms, only plot core of distribution within these percentiles:
    165199    histo_min_ntile = 0.03
     
    171205        col2name_l = troika[1]
    172206        plottype = troika[2]
    173         outname = getOutnameStatsOnefile(matchtable,plottype,col1name_l,col2name_l,format=format)
     207        outname = getOutnameStatsOnefile(matchtable,plottype,col1name_l,col2name_l,format=format,bandid=bandid)
    174208        smOpenPlot(outname,format=format)
    175209        firstplot = True
     
    238272def appendFitsTable(fitsfile,tabHDU,HDU=1):
    239273    """Append rows in tabHDU to existing fits table file"""
     274    import pyfits
    240275    oldtabhdulist = pyfits.open(fitsfile)
    241276    nrows_old = len(oldtabhdulist[HDU].data)
     
    370405        ,'d_skyerr':['skyErr','SKY_SIGMA']
    371406        ,'d_pointsource':['prob_psf','pointsource_ps1']
    372         # ,'d_mag':['psfcounts','PSF_INST_MAG ']
    373         # ,'d_magerr':['psfcountserr','PSF_INST_MAG_SIG']
    374407        ,'d_mag':['psfinstmag_sdss','PSF_INST_MAG']
    375408        ,'d_magerr':['psfinstmagerr_sdss','PSF_INST_MAG_SIG']
     
    480513    return array(good1_l),array(good2_l),array(good3_l)
    481514   
    482 def makePlan():
     515def makePlan(lastcamcol=6):
    483516    """Make paired list of which fpObjc file to compare to which IPP
    484517    .cmf file. Could also think about constructing the fpObjc filename
     
    487520     
    488521    # For testing:
    489     return ['1056-0192.421/1056-0192.421.ch.421.CHIP1.cmf'],['1056-0192.421/fpObjc-001056-1-0192.fit']
     522    # return ['1056-0192.421/1056-0192.421.ch.421.CHIP1.cmf'],['1056-0192.421/fpObjc-001056-1-0192.fit']
    490523
    491524    from glob import glob
     
    507540        }
    508541    Nfields = 18
    509     camcollist = range(1,6+1)
     542    camcollist = range(1,lastcamcol+1)
    510543    sdsslist = []
    511544    ps1list = []
     
    567600    sdssfilt += ';select !((flags[%s]&1<<1)!=0)&&(!((flags[%s]&1<<3)!=0)||((flags[%s]&1<<6)!=0)||nchild==0)' % \
    568601        (bandindex,bandindex,bandindex)
     602    # add check for BINNED1 !!! bit28 in flags1
     603   
    569604    # Check flag 0x4000 (extended) to compare against prob_psf in SDSS
    570605    # - for some reason, 'flags' and the other integer columns get
     
    823858    img = f_handle[HDU].data
    824859    resid_img = 1e-7*ones(img.shape,Float32)
    825     print resid_img.shape,type(resid_img),img.shape,type(img)
    826860    fitlist = []
    827861    for initialGuessTuple in initialGuessList:
     
    846880        win.showArray(res)
    847881        resid_img[int(y0)-halfwinsize:int(y0)+halfwinsize+1,int(x0)-halfwinsize:int(x0)+halfwinsize+1] = res
    848         print initialGuessTuple, scale,x,xsig,y,ysig,theta
     882        # print initialGuessTuple, scale,x,xsig,y,ysig,theta
    849883        fitlist.append(par)
    850884    f_handle.close()
Note: See TracChangeset for help on using the changeset viewer.