IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20527


Ignore:
Timestamp:
Nov 4, 2008, 3:42:28 AM (18 years ago)
Author:
Sebastian Jester
Message:

add logic for putting plots on same page using sm windows; catch change from FWHM_X to FWHM_MAJ etc.; propagate blankrad properly in gauss-fitting

File:
1 edited

Legend:

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

    r20511 r20527  
    6262# XXX Todo: labels! group by runs? different colours for different
    6363# bands; include seeing? plot things against seeing?
     64
     65# Also: the plotcol lists need to be grouped into things that are to
     66# appear on the same page. For the beginning, that's the entire list
     67# (and that's probably quite enough anyway).
     68
    6469
    6570plotcol_1frame_tlist = [
     
    107112def compIPPphoto(summaryTable,mode,plotcol_1frame_tlist=plotcol_1frame_tlist,\
    108113                     plotcol_summary_tlist=plotcol_summary_tlist,\
    109                  cmfDir = '/IPP/data/SDSS/stripe82/coadd/prod/run_ipp_20080815/',\
    110                  skip=True):
     114                     cmfDir = '/IPP/data/SDSS/stripe82/coadd/prod/run_ipp_20080815/',\
     115                     copyfields_list = ['RUN','RERUN','CAMCOL','FIELD','FILTER','FWHM_MAJ','FWHM_MIN'],\
     116                     skip=True):
    111117    """summaryTable: .fits table for output
    112118    mode: new or append for creating summaryTable new or appending current run's output to it.
     
    144150            filters.append(filter_name)
    145151            bandindex_hash[filter_name] = bandindex
    146         stats_hash, column_hash, goodrow_hash = computeStatistics(matchtable)
     152        stats_hash, column_hash, goodrow_hash = computeStatistics(matchtable,copyfields_list = copyfields_list)
    147153        # Sort res_hash by its column names to make sure order is
    148154        # identical in all rows of the table, and output is more
     
    284290    os.remove(tmp_outname)
    285291    return all_outname
    286        
     292
     293def setWindow(i,Nplots):
     294    """Set sm window for plotting the i-th out of Nplots. The logic is
     295    that N_x * N_y >= Nplots and N_y-N_x is 0 or 1. So Ny is the sqrt
     296    of N or the next-greatest square; Nx is either the same or one
     297    fewer if that's still enough."""
     298   
     299    from scipy import sqrt
     300    if int(sqrt(Nplots))**2 == Nplots:
     301        Ny = int(sqrt(Nplots))
     302        Nx = Ny
     303    else:
     304        Ny = int(sqrt(Nplots)+1)
     305        Nx = Ny-1
     306        if Nx * Ny < Nplots:
     307            Nx+=1
     308
     309    # That's nx, ny; now count up to total Nx ny. This is like
     310    # representing i in a number system where the y-window number is
     311    # the 10s and the x-window number the 1s, but the 10s are base Ny
     312    # and the 1s are base Nx, and counting starts at 1 not 0. I.e. x =
     313    # (i % Nx) or Nx if that's 0; y = i / Nx + 1
     314    winx = i% Nx
     315    if winx == 0:
     316        winx = Nx
     317    winy = int(i/Nx)+1
     318    if int(i/Nx) == i/float(Nx):
     319        winy -= 1
     320    return Nx,Ny,winx,winy
    287321
    288322def valuesKeysSortedByKeys(hash):
     
    379413    # "reference columns"
    380414    outhash = {}
     415    if 'FWHM_MAJ' in copyfields_list and 'FWHM_MAJ' not in h.ascardlist().keys():
     416        copyfields_list.remove('FWHM_MAJ')
     417        copyfields_list.remove('FWHM_MIN')
     418        copyfields_list.append('FWHM_X')
     419        copyfields_list.append('FWHM_Y')
    381420    for f in copyfields_list:
    382421        outhash[f] = h[f]
     
    557596    filters = ['u','g','r','i','z']
    558597    # Read primary  header of PS1 file to work out band
    559     ps1copyfields_hash = headerfieldHash(['FWHM_MAJ','FWHM_MIN','FILTER'],PS1cmf,HDU=0)
     598    try:
     599        ps1copyfields_hash = headerfieldHash(['FWHM_MAJ','FWHM_MIN','FILTER'],PS1cmf,HDU=0)
     600    except KeyError:
     601        ps1copyfields_hash = headerfieldHash(['FWHM_X','FWHM_Y','FILTER'],PS1cmf,HDU=0)
    560602    sdssbandstr = ps1copyfields_hash['FILTER']
    561603    bandindex = filters.index(sdssbandstr)
     
    832874    """Fit Gaussians to image in infile's HDU near the
    833875    positions and with fluxes and sigmas given in initialGuessList"""
    834     # XXX Todo: Make frame with residuals. Make blank array, then insert residuals.   
    835876    import pyfits
    836877    from numpy import nan
     
    839880    f_handle=pyfits.open(infile)
    840881    img = f_handle[HDU].data
    841     resid_img = 1e-7*ones(img.shape,Float32)
     882    resid_img = zeros(img.shape,Float32)
    842883    fitlist = []
    843884    for initialGuessTuple in initialGuessList:
     
    860901            res = subim
    861902        (scale,x,xsig,y,ysig,theta)=par
    862         win.showArray(res)
     903        # win.showArray(res)
    863904        resid_img[int(y0)-halfwinsize:int(y0)+halfwinsize+1,int(x0)-halfwinsize:int(x0)+halfwinsize+1] = res
    864905        # print initialGuessTuple, scale,x,xsig,y,ysig,theta
    865906        fitlist.append(par)
    866907    f_handle.close()
    867     outname = 'gaussfit_resid_'+infile
     908    outname = 'gaussfit_resid_r%ipix_%s' % (blankrad,infile)
    868909    primHDU = pyfits.PrimaryHDU(resid_img)
    869910    hdulist = pyfits.HDUList([primHDU])
     
    871912    return fitlist
    872913       
    873 def doEfbComparison(simfile='simtest.1.00a.fits',efbfile='efbsim.1.00a.fits',simtab='simtest.1.00a.cmf'):
     914def doEfbComparison(simfile='simtest.1.00a.fits',efbfile='efbsim.1.00a.fits',simtab='simtest.1.00a.cmf',blankrad=9):
    874915    import pyfits
    875916    from numpy import array, rec
     
    886927        initlist.append((counts[i],x[i],2.,y[i],2.,0.))
    887928        inparlist.append((counts[i],x[i],y[i]))
    888     efbparlist = doGaussPsfPhotometry(efbfile,initlist)
    889     simparlist = doGaussPsfPhotometry(simfile,initlist)
     929    efbparlist = doGaussPsfPhotometry(efbfile,initlist,blankrad=blankrad)
     930    simparlist = doGaussPsfPhotometry(simfile,initlist,blankrad=blankrad)
    890931
    891932    savelist = [ inparlist[i] + efbparlist[i] + simparlist[i] for i in range(nrows)]
     
    900941    saveHDU = tabHDUfromRecArray(saverows)
    901942    fitsend = re.compile('(\.[sc]mf|\.fits?)$')
    902     saveHDU.writeto('gaussfit_'+fitsend.sub('',efbfile)+'___'+simfile,clobber=True)
     943    saveHDU.writeto('gaussfit_r%ipix_%s___%s' %(blankrad,fitsend.sub('',efbfile),simfile),clobber=True)
    903944   
    904945
     
    931972        fpObjcDir += '/'
    932973    # For testing:
    933     # return ['1056-0192.421/1056-0192.421.ch.421.CHIP1.cmf'],['1056-0192.421/fpObjc-001056-1-0192.fit']
     974    return ['1056-0192.421/1056-0192.421.ch.421.CHIP1.cmf'],['1056-0192.421/fpObjc-001056-1-0192.fit']
    934975
    935976    from glob import glob
Note: See TracChangeset for help on using the changeset viewer.