IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23263


Ignore:
Timestamp:
Mar 11, 2009, 7:08:37 AM (17 years ago)
Author:
Sebastian Jester
Message:

Deal with possibility of encountering IQ_FW1,2 instead of FWHM_X,Y in headers

File:
1 edited

Legend:

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

    r20560 r23263  
    6868
    6969# Look at extended flag in PS1 vs. SDSS!!!
     70
     71# os.chdir('/disk1/jester/IPP/data/SDSS/stripe82/coadd/compare')
     72# execfile('/disk1/jester/usrdevel/ipp_sj/ippTests/compIPPphoto.py')
     73# h1,h2=compIPPphoto('test.fits','new',workdir='/IPP/data/SDSS/stripe82/coadd/compare',runlist=[1056,1755])
    7074
    7175plotcol_1frame_tlist = [
     
    167171        plotStatsOnefile(column_hash,goodrow_hash,matchtable,plotcol_1frame_tlist,bandindex,bandid=filter_name)
    168172        # return column_hash,goodrow_hash
     173    # Herre, need to check that keylist is filled i.e. files were found
    169174    newrows = numpy.rec.array(rowtuple_list,names=keylist)
    170175    tabhdu = tabHDUfromRecArray(newrows)
     
    269274                    if not re.search('objc',col2name):
    270275                        try:
    271                             [xmin,xmax] = stats_med(values1[goodrows],[histo_min_ntile,histo_max_ntile])
     276                            r = stats_med(values1[goodrows],[histo_min_ntile,histo_max_ntile])
     277                            [xmin,xmax] = r
    272278                            [ymin,ymax] = stats_med(values2[goodrows],[histo_min_ntile,histo_max_ntile])
    273                         except IndexError:
     279                        except ValueError:
     280                            print "Pffrz! ",r
    274281                            print col1name, goodrows, type(goodrows), len(goodrows), len(values1)
    275282                        # print "Huhu", outname, min(values1),max(values2),xmin,xmax
     
    448455    # "reference columns"
    449456    outhash = {}
    450     #print "Looking for FWHM_MAJ in table %s" %(tablename)
    451     if 'FWHM_MAJ' in copyfields_list and 'FWHM_MAJ' not in h.ascardlist().keys():
    452         copyfields_list.remove('FWHM_MAJ')
    453         copyfields_list.remove('FWHM_MIN')
    454         copyfields_list.append('FWHM_X')
    455         copyfields_list.append('FWHM_Y')
    456457    for f in copyfields_list:
    457458        outhash[f] = h[f]
     
    477478    # Maybe I want to keep track of these number of "good" rows?
    478479
    479     # XXX: Count number of objects in a) SDSS, b) PS1, c) both, by
     480    # Count number of objects in a) SDSS, b) PS1, c) both, by
    480481    #  counting number of a) entries > 0 in 'id', b) non-nan entries
    481482    #  in IPP_IDET, c) both (Later pass the following as parameters to
     
    617618    file."""
    618619    import pyfits
     620    from numpy import nan
    619621
    620622    def getOutname(SDSSfile,PS1file,sdssbandstr):
     
    631633   
    632634    filters = ['u','g','r','i','z']
    633     # Read primary  header of PS1 file to work out band
    634     try:
    635         ps1copyfields_hash = headerfieldHash(['FWHM_MAJ','FWHM_MIN','FILTER'],PS1cmf,HDU=0)
    636     except KeyError:
    637         ps1copyfields_hash = headerfieldHash(['FWHM_X','FWHM_Y','FILTER'],PS1cmf,HDU=0)
     635    # Read primary header of PS1 file to work out band and copy other
     636    # interesting fields. These include FHWM_MAJ,MIN which used to be
     637    # called FWHM_X,Y, but are missing in some cases if the camera
     638    # stage failed. In the latter case, we can still read IQ_FW1,2. So
     639    # we first update the .cmf file to be sure that FWHM_MAJ,MIN is
     640    # present for later analysis.   
     641    ensureFHWMheaderfields(PS1cmf)
     642    ps1copyfields_hash = headerfieldHash(['FWHM_MAJ','FWHM_MIN','FILTER'],PS1cmf,HDU=0)           
     643    sdsscopyfields_hash = headerfieldHash(['RUN','RERUN','CAMCOL','FIELD'],SDSSfpObjc,0)
    638644    sdssbandstr = ps1copyfields_hash['FILTER']
    639645    bandindex = filters.index(sdssbandstr)
     
    642648        return outname,sdssbandstr,bandindex
    643649       
    644     sdsscopyfields_hash = headerfieldHash(['RUN','RERUN','CAMCOL','FIELD'],SDSSfpObjc,0)
    645650
    646651    # Note position offset - y_sdss-y_psf1 ~ 0.6, x_sdss-x_ps1 ~ 0.35 (in 1056-r1-0192)
     
    682687    return outname,sdssbandstr,bandindex
    683688
     689def ensureFHWMheaderfields(PS1cmf):
     690    import pyfits
     691    PS1handle = pyfits.open(PS1cmf,mode='update')
     692    PS1primhead = PS1handle[0].header
     693    headfields = PS1primhead.ascardlist().keys()
     694    if not ('FWHM_MAJ' in headfields and 'FWHM_MIN' in headfields):
     695        if ('FWHM_X' in headfields and 'FWHM_Y' in headfields):
     696            PS1primhead.update('FWHM_MAJ',PS1primhead['FWHM_X'])
     697            PS1primhead.update('FWHM_MIN',PS1primhead['FWHM_Y'])
     698        else:
     699            PS1primhead.update('FWHM_MAJ',PS1primhead['IQ_FW1'])
     700            PS1primhead.update('FWHM_MIN',PS1primhead['IQ_FW2'])
     701    PS1handle.close()
     702
     703   
     704
    684705def updateHeaderFromHash(header,hash):
    685706    """Add fields in hash to header"""
     
    698719    for field in fieldlist:
    699720        outhash[field] = h[field]
     721    f.close()
    700722    return outhash
    701723
     
    10181040    # For testing:
    10191041    # return ['1056-0192.421/1056-0192.421.ch.421.CHIP1.cmf'],['1056-0192.421/fpObjc-001056-1-0192.fit']
     1042    # return ['1056-0192.1/1056-0192.1.ch.1.CHIP21.cmf'],['1056-0192.1/fpObjc-001056-1-0192.fit']
    10201043
    10211044    from glob import glob
Note: See TracChangeset for help on using the changeset viewer.