IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20142


Ignore:
Timestamp:
Oct 14, 2008, 2:51:21 AM (18 years ago)
Author:
Sebastian Jester
Message:

Add creation of summary plots

File:
1 edited

Legend:

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

    r20086 r20142  
    2727#     + magdiff vs. sky
    2828#     + magdiff vs. skydiff
    29 #     + magdiff vs. stellar density
    30 #     + magdiff vs. presence of bright stars
    3129#     + something about PSF sizes; use Michigan moments for photo -
    3230#       M_rr_cc_psf is the size of the reconstructed PSF, and m_rr_cc is the size of the object
     
    3836#     + histograms of everything - recovery fractions, means, medians, quartiles
    3937#     + Trends with field number, seeing etc.
    40 
     38#     + magdiff vs. stellar density
     39#     + magdiff vs. presence of bright stars (e.g. number of bright
     40#       stars above some typical S/N or counts threshold - 50%
     41#       saturation?)
     42#
     43# XXX Todo:
     44#
     45# - Merge identical plots into single .eps file
     46#
     47# - Make html page with jpeg/gif versions of plots
     48#
     49# - Need mechanism to specify default plotting ranges, since outliers
     50#   mess up axis ranges. Different quantities need different
     51#   ranges. Comparing different plots is also easier if the plot
     52#   ranges are the same.
     53#
     54# - second tlist for summary plots (same or different plot routine?)
     55#
     56# - towards generality, want to read these things and colname_hash and
     57#   label_l from config files
     58#
    4159# Convention: for scatter, plot second against first; for histogram, plot both histograms
    42 #
    43 # XXX: Need mechanism to specify default plotting ranges, since
    44 # outliers mess up axis ranges. E.g. 0.1 and 0.9 percentiles?
    45 plotcol_tlist = [
     60plotcol_1frame_tlist = [
    4661    (['d_sky'],['d_mag'],'scatter')
    4762    ,(['d_x'],['d_y'],'scatter')
     
    5671    ]
    5772
    58 def compIPPphoto(summaryTable,mode,plotcol_tlist=plotcol_tlist,skip=False):
     73plotcol_summary_tlist = [
     74    (['d_mag_median'],['d_sky_median'],'scatter')
     75    ,(['d_x_median'],['d_y_median'],'scatter')
     76    ,(['d_mag_median'],['N_SDSS'],'scatter')
     77    ,(['d_mag_median','d_mag_mean'],['field','field'],'scatter')
     78    ]
     79
     80
     81def compIPPphoto(summaryTable,mode,plotcol_1frame_tlist=plotcol_1frame_tlist,\
     82                     plotcol_summary_tlist=plotcol_summary_tlist,skip=True):
    5983    """summaryTable: .fits table for output
    6084    mode: new or append for creating summaryTable new or appending current run's output to it.
     
    93117        vallist,keylist = valuesKeysSortedByKeys(stats_hash)
    94118        rowtuple_list.append(vallist)
    95         plotStatsOnefile(column_hash,goodrow_hash,matchtable,plotcol_tlist,bandindex)
     119        plotStatsOnefile(column_hash,goodrow_hash,matchtable,plotcol_1frame_tlist,bandindex)
    96120        # return column_hash,goodrow_hash
    97121    newrows = numpy.rec.array(rowtuple_list,names=keylist)
     
    99123    if mode == 'new':
    100124        tabhdu.writeto(summaryTable,clobber=True)
     125        nrows = tabhdu.header['NAXIS2']
     126        summaryhash = hashFromPyfitsTable(tabhdu)
    101127    else:
    102         appendFitsTable(summaryTable,tabhdu)
     128        newtabhdu = appendFitsTable(summaryTable,tabhdu)
     129        nrows = newtabhdu.header['NAXIS2']
     130        summaryhash = hashFromPyfitsTable(newtabhdu)
     131    # Fake a goodrows hash
     132    sumgoodrows_hash = summaryhash.fromkeys(summaryhash.keys(),numpy.ones((nrows,),bool))
     133    plotStatsOnefile(summaryhash,sumgoodrows_hash,summaryTable,plotcol_summary_tlist,bandindex)
    103134    return column_hash,goodrow_hash
     135
     136def hashFromPyfitsTable(pyfitsTableHDU):
     137    """Return a hash wrapping the table data so a column can be
     138    addressed as hash[colname] instead of tabledata.field(colname)"""
     139    from numpy import array
     140    outhash = {}
     141    for col in pyfitsTableHDU.columns.names:
     142        # Column names are uppercase, we want lowercase hash keys
     143        outhash[col.lower()] = array(pyfitsTableHDU.data.field(col))
     144    return outhash
    104145
    105146def getOutnameStatsOnefile(matchtable,kind,col1_l,col2_l=None,format='eps'):
     
    124165    histo_min_ntile = 0.03
    125166    histo_max_ntile = 1-histo_min_ntile
     167    angle_l = [0,45,0,45,0,90]
     168    ptype_l = [ 41, 41, 40, 40, 30,30]
    126169    for troika in plotcol_tlist:
    127170        col1name_l = troika[0]
     
    131174        smOpenPlot(outname,format=format)
    132175        firstplot = True
     176        i = 0
    133177        for col1name,col2name in zip(col1name_l,col2name_l):
    134             values1 = values_hash[col1name]
    135             goodrows1 = goodrow_hash[col1name]
    136             values2 = values_hash[col2name]
    137             goodrows2 = goodrow_hash[col2name]
     178            values1 = values_hash[col1name.lower()]
     179            goodrows1 = goodrow_hash[col1name.lower()]
     180            values2 = values_hash[col2name.lower()]
     181            goodrows2 = goodrow_hash[col2name.lower()]
    138182            # Slice out depth for current filter if necessary
    139183            if len(values1.shape) > 1:
     
    150194                    # Avoid plotting outliers
    151195                    if not re.search('objc',col2name):
    152                         [xmin,xmax] = stats_med(values1[goodrows],[histo_min_ntile,histo_max_ntile])
    153                         [ymin,ymax] = stats_med(values2[goodrows],[histo_min_ntile,histo_max_ntile])
     196                        try:
     197                            [xmin,xmax] = stats_med(values1[goodrows],[histo_min_ntile,histo_max_ntile])
     198                            [ymin,ymax] = stats_med(values2[goodrows],[histo_min_ntile,histo_max_ntile])
     199                        except IndexError:
     200                            print col1name, goodrows, type(goodrows), len(goodrows), len(values1)
    154201                        # print "Huhu", outname, min(values1),max(values2),xmin,xmax
    155202                        smScatterPlot(values1,values2,logical=goodrows,xlab=col1name,ylab=col2name,\
     
    159206                        smScatterPlot(values1,values2,logical=goodrows,xlab=col1name,ylab=col2name)
    160207                else:
    161                     angle(45)
    162                     smScatterPlot(values1,values2,logical=goodrows,append=True)
     208                    angle(angle_l[i%len(angle_l)])
     209                    smScatterPlot(values1,values2,ptype=ptype_l[i%len(ptype_l)],logical=goodrows,append=True)
    163210                    angle(0)
    164211            if plottype == 'histogram':
     
    177224                            ltype=2)
    178225            firstplot = False
     226            i+=1
    179227    smClosePlot()
    180228
     
    196244        newtabhdu.data.field(col)[nrows_old:] = tabHDU.data.field(col)
    197245    oldtabhdulist.close()
    198     return newtabhdu.writeto(fitsfile,clobber=True)
     246    newtabhdu.writeto(fitsfile,clobber=True)
     247    return newtabhdu
    199248
    200249       
     
    247296    outl = []
    248297    for ntile in ntiles:
    249         outl.append(sortarr[ntile*(l-1)])
     298        idx = max(int(ntile*(l-1)),0)
     299        outl.append(sortarr[idx])
    250300    return outl
    251301
Note: See TracChangeset for help on using the changeset viewer.