예제 #1
0
파일: bok_file.py 프로젝트: RapidLzj/201603
def insbok (mjd, objtype, fits, cur) :
    print fits
    hdulist = pyfits.open(fits)
    hdr = hdulist[0].header
    #date = hdr['date']
    loct = lzju.hdr(hdr,'loctime', '00:00:00')
    #yr = int(date[0:4]); mn = int(date[5:7]); dy = int(date[8:10])
    hr = int(loct[0:2]); mi = int(loct[3:5]); se = int(loct[6:8])
    #ss = time.mktime((yr, mn, dy, hr, mi, se, 0, 0, 0)) - time0
    #mjd = int(ss / 60 / 60 / 24)
    hr24 = hr
    if hr < 12 : hr24 = hr + 24 
    tim = (hr24 - 12) * 3600 + mi * 60 + se
    sn = int(fits[-9:-5])
    obj = lzju.hdr(hdr, 'object').strip()
    if obj == '' : obj = 'NONE'
    obj = obj.replace("'", '')
    fil = lzju.hdr(hdr, 'filter', 'NONE').strip()
    ext = lzju.tryfloat(lzju.hdr(hdr, 'exptime', '0.0'))
    ra  = lzju.sex2dec(lzju.hdr(hdr, 'ra', '00:00:00')) * 15.0
    dec = lzju.sex2dec(lzju.hdr(hdr, 'dec', '00:00:00'))
    fid = '%4.4dB%4.4d'%(mjd, sn)
    sql = "INSERT INTO ObsFileBasic (FileID, Telescope, MJD, ObsTime, SN, ObjType, Object, Filter, ExpTime, RADeg, DecDeg, Tag, FileName, Note) " + \
          "VALUES ('%s', 'B', %d, %d, %d, '%s', '%s', '%s', %f, %f, %f, 0, '%s', '')" % \
          (fid, mjd, tim, sn, objtype, obj, fil, ext, ra, dec, fits)
    #print sql
    try :
        cur.execute(sql)
    except:
        print sql
        exit()
예제 #2
0
def insnowtred (cur, fileid, mjd, fil, filename) :

    baselist = {'u':'/data/red/XAO/u/pass1/',
        'v':'/data/red/XAO/v/pass1/',
        'b':'/data/red/XAO/b/pass1/',
        'y':'/data/red/XAO/y/pass1/',
        'w':'/data/red/XAO/Hw/pass1/',
        'n':'/data/red/XAO/Hn/pass1/',
        }
    if not baselist.has_key(fil) : return (0)
    basepath = baselist[fil]

    filepart = filename.split('/')
    basename = filepart[8][0:-5]
    caldate = '%4.4d%2.2d%2.2d' % lzju.cal(mjd)[0:3]

    redpath = basepath+filepart[4]+'/'+filepart[5]+'/good/'+basename+'/'
    dbfile = redpath+basename+'.db.txt'
    if not os.path.exists(dbfile) :
        redpath = basepath+filepart[4]+'/'+filepart[5]+'/other/'+basename+'/'
        dbfile = redpath+basename+'.db.txt'
        if not os.path.exists(dbfile) :
            return (0)
    #print filename, dbfile

    # reduce time (file create time)
    rtimef = os.path.getctime(dbfile)
    rtimes = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(rtimef))

    # reduce result
    f = open(dbfile, 'r')
    line = f.readline()
    line = f.readline()
    f.close()
    part = (': '+line).split()  # add a leading part, make index from 1

    if int(part[33]) > 0 :
        laststep = 4
    elif int(part[8]) > 0 :
        laststep = 3
    elif int(part[28]) > 0 :
        laststep = 2
    else :
        laststep = 1

    fld = [lzju.tryfloat(v, allownan=False) for v in part]

    sql = "INSERT INTO FileReduceResult (FileID, Version, ReduceTime, LastStep, " + \
          "NStar, FwhmMed, FwhmSig, ElongMed, ElongSig, " + \
          "Azi , Alt , AirMass, MoonPhase, MoonAngle, MoonAlt, " + \
          "NWcs, MagWcs, NewRA, NewDec, CorRA, CorDec, " + \
          "NMag, MagConst, MagErr, " + \
          "Mag5, Mag10, Mag33, Mag50, Mag100, Mag333, " + \
          "SkyMag, SkyErr, " +\
          "FilePath) " + \
          "VALUES ('%s', 1, '%s', %d, " + \
          "%i, %f, %f, %f, %f, " + \
          "%f, %f, %f, %f, %f, %f, " + \
          "%i, %f, %f, %f, %f, %f, " + \
          "%i, %s, %s, " + \
          "%f, %f, %f, %f, %f, %f, " + \
          "%f, %f, " + \
          "'%s')"
    sql = sql % (fileid, rtimes, laststep, \
        fld[28], fld[29], fld[30], fld[31], fld[32], \
        fld[22], fld[23], fld[24], fld[25], fld[27], fld[26], \
        fld[ 8], fld[ 9], fld[18], fld[19], fld[20], fld[21], \
        fld[33], fld[34], fld[35], \
        fld[36], fld[37], fld[38], fld[39], fld[40], fld[41], \
        fld[44], fld[45], \
        redpath)
    #print sql
    try :
        cur.execute(sql)
    except:
        print sql
        exit()
    return (laststep)