Bug in snmin02

From: Don Groom (deg@lbl.gov)
Date: Tue Aug 17 2004 - 13:35:35 PDT

  • Next message: Don Groom: "Re: Bug in snmin02"

    Some time ago, Gerson told me about an snmin02 problem: If the number of
    counts in the first line of a Hamuy-style data file were negative, the
    line would be dropped.

    The incorrect lines in read_hamuy.pro are:

    regnamez= '^[[:space:]]*([a-z0-9\.]+)[[:space:]]+z=[[:space:]]*([0-9\.]+)'
     
    regjcdcmdm='^[[:space:]]*([0-9\.]+)[[:space:]]+([0-9\.]+)[[:space:]]+' + $
      '([0-9\.]+)[[:space:]]+([0-9\.]+)[[:space:]]+([0-9\.]+)'

    So please repair these lines to accept negative counts in your version of
    the code. Ha ha.

    Alternatives are to replace your version of read_hamuy.pro with the
    version attached to this email, or to copy the corrected version from the
    master version at /home/sierra1/deg/idl/SCPfits02 . Sorry that these
    files haven't yet been nationalized into SCP space.

    The error affects ONLY NOCOV=YES files with negative early points or
    negative data points in reference images. The latter must occur 50% of the
    time.

    If "foreign" data arrives as magnitudes rather than counts, the negative
    points have already been discarded, in which case the fits are biased
    anyway.

    Thanks to Alex Conley for finding/repairing the regular expressions.

    Don

    |-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|-+|
    Don Groom (Particle Data Group, Supernova Cosmology Project)
    DEGroom(at)lbl(dot)gov www-ccd.lbl.gov 510/486-6788 FAX: 510/486-4799
    Analog: 50R6008//1 Cyclotron Road//Berkeley Lab//Berkeley, CA 94720-8166

    ---------- Forwarded message ----------
    Date: Tue, 17 Aug 2004 10:32:35 -0700
    From: Alex Conley <AJConley@lbl.gov>
    To: DEGroom@lbl.gov, Gerson Goldhaber <G_Goldhaber@lbl.gov>
    Subject: Re: read_hamuy

    Yup, my fault. The regular expression doesn't know about
    negative numbers. Attached is a version of read_hamuy
    which shouldn't have this problem.


    ;+
    ;NAME
    ; read_hamuy
    ;PURPOSE
    ; Generates roblight style lightcurves from input files
    ;CALLING SEQUENCE
    ; st = read_hamuy(filename,filter)
    ;INPUTS
    ; filename -- the name of the file to be read in (full path)
    ;RETURN VALUE
    ; The name of the new lightcurve file, or '' if something went wrong
    ;SIDE EFFECTS
    ; A file is written in SN_hamuy/
    ;MODIFICATION HISTORY
    ; deg -- written
    ; 2002/07/30 aconley -- Default behaviour changed. It is no longer
    ; quite so gerson specific, and relys on the
    ; calling program to figure out the input
    ; filename.
    ;-

    function read_hamuy,filename

    outdir = 'SN_hamuy/'

    filter = 'B' ;;;Default, possibly changed later

    if keyword_set(directory) then begin
        if strmid(directory,strlen(directory)-1) ne '/' then $
          directory = directory + '/'
        filein = directory + filename
    endif else filein = filename

    ;;Use the input filename to figure out the output one
    ;; This will be the input filename with .dat on the end and the path
    ;; of outdir
    slashpos = rstrpos(filename,'/')
    if slashpos ne -1 then begin
        fileout = strmid(filename,slashpos+1)
    endif else fileout = filename
    fileout = outdir + fileout + '.dat'

    find = findfile(filein,c=nf)
    if nf ne 1 then begin
       print,' read_hamuy: ',filein,' not found, Stopping'
       return,''
    endif

    openr,unit,filein,/GET_LUN
    line = ' '
    sn_file = ' '

    ;;Now read in the input file using regular expressions
    ;; First define the possibilities:

    ;;Name z= redshift
    regnamez = '^[[:space:]]*([a-z0-9\.]+)[[:space:]]+z=[[:space:]]*([0-9\.\-]+)'
    ;;deltam 15= error= stretch=
    regdm15ddm15s = '^[[:space:]]*deltam[[:space:]]{0,1}15=[[:space:]]*' + $
      '([0-9\.]+)[[:space:]]+error=[[:space:]]*([0-9\.]+)[[:space:]]*' + $
      'stretch=[[:space:]]*([0-9\.]+)'
    ;; jday filt_counts dfilt_counts filt dfilt (strings)
    regstrng = '^[[:space:]]*jday[[:space:]]+([a-z])[[:space:]]cts[[:space:]]+' + $
      'd([a-z])[[:space:]]cts'
    ;; jday cnts dcnts mag dmag (numbers all)
    regjcdcmdm = '^[[:space:]]*([0-9\.]+)[[:space:]]+([0-9\.\-]+)[[:space:]]+' + $
     '([0-9\.\-]+)[[:space:]]+([0-9\.\-]+)[[:space:]]+([0-9\.\-]+)'

    jday = [0.0d]
    counts = [0.0d]
    dcounts = [0.0d]
    mags = [0.0d]
    dmags = [0.0d]

    while not eof(unit) do begin
        readf,unit,line,f='(a)'
        
        ;;Test the possiblilties
        res1 = stregex(line,regnamez,/EXTRACT,/FOLD_CASE,/SUBEXP)
        res2 = stregex(line,regdm15ddm15s,/EXTRACT,/FOLD_CASE,/SUBEXP)
        res3 = stregex(line,regstrng,/EXTRACT,/FOLD_CASE,/SUBEXP)
        res4 = stregex(line,regjcdcmdm,/EXTRACT,/FOLD_CASE,/SUBEXP)
        if res1[0] ne '' then begin
            ;;Line is name z=
            sn_file = res1[1]
            z = float(res1[2])
        endif else if res2[0] ne '' then begin
            ;;Line is dm15 ddm15 stretch
            dm15 = float(res2[1])
            ddm15 = float(res2[2])
            stretch = float(res2[3])
        endif else if res3[0] ne '' then begin
            ;;Line is jday counts dcounts mag dmag (as string)
            ;; Use this to figure out filter type
            filter = res3[1]
        endif else if res4[0] ne '' then begin
            ;;Line is actual lightcurve numbers
            jday = [jday,double(res4[1])]
            counts = [counts,double(res4[2])]
            dcounts = [dcounts,double(res4[3])]
            mags = [mags,double(res4[4])]
            dmags = [dmags,double(res4[5])]
        endif

    endwhile

    FREE_LUN,unit

    if n_elements(jday) eq 1 then begin
        print,"Error -- no lightcurve data points found in file ",filein
        return,''
    endif

    ;;Strip off of the spurious first entries from jday, counts, etc.
    jday = jday[1:*]
    counts = counts[1:*]
    dcounts = dcounts[1:*]
    mags = mags[1:*]
    dmags= dmags[1:*]

    npts = n_elements(jday)

    countmax = max(counts,wcountmax)
    zeropoint = mags[wcountmax] + 2.5*alog10(countmax) ;;At maximum

    dmag = 0.05 ;;Assumed error in zeropoint

    ;;Actually write the output file
    openw,unit,fileout,/GET_LUN
    printf,unit,'date of write: ',systime()
    printf,unit,'date source: ',filein
    printf,unit,'no reference galaxy counts, this is a hamuy file'
    printf,unit,'zeropoint: ',zeropoint,dmag,f='(a11,2f13.3)'
    printf,unit,'datapoints: ',npts,f='(a14,i10)'
    printf,unit,' jd counts dcounts nr filename'
    printf,unit,'------------------------------------------------------'

    ;;Print data points
    for j = 0,npts-1 do begin
        printf,unit,jday[j],counts[j],dcounts[j],' n ',filein, $
            format='(f10.2,f15.2,f16.2,a,a)'
    endfor

    ;;Print fake correlation matrix
    InvCorrMat = dblarr(npts,npts)
    ;;Set diagonal to 1/dcounts^2
    InvCorrMat[indgen(npts),indgen(npts)] = 1.0 / dcounts^2
    printf,unit,InvCorrMat,format='(e25.14)'

    FREE_LUN,unit

    return,fileout

    end



    This archive was generated by hypermail 2.1.4 : Tue Aug 17 2004 - 13:37:09 PDT