コード例 #1
0
def filterNaN(instr, datacol, outfile, logfile, verbose):

    status = 0
    try:
        nanclean = instr[1].header['NANCLEAN']
    except:
        naxis2 = 0
        for i in range(len(instr[1].columns.names)):
            if 'time' in instr[1].columns.names[i].lower():
                timecol = instr[1].columns.names[i]
        try:
            instr[1].data.field(datacol)
        except:
            msg = 'ERROR -- KEPIO.FILTERNAN: cannot find column ' + datacol + ' in the infile'
            status = kepmsg.err(logfile, msg, verbose)

        if status == 0:
            try:
                for i in range(len(instr[1].data.field(0))):
                    if str(instr[1].data.field(timecol)[i]) != '-inf' and \
                            str(instr[1].data.field(datacol)[i]) != '-inf':
                        instr[1].data[naxis2] = instr[1].data[i]
                        naxis2 += 1
                instr[1].data = instr[1].data[:naxis2]
                comment = 'NaN cadences removed from data'
                status = kepkey.new('NANCLEAN', True, comment, instr[1],
                                    outfile, logfile, verbose)
            except:
                msg = 'ERROR -- KEPIO.FILTERNAN: Failed to filter NaNs from ' + outfile
                status = kepmsg.err(logfile, msg, verbose)

    return instr, status
コード例 #2
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def filterNaN(instr,datacol,outfile,logfile,verbose):

    status = 0
    try:
        nanclean = instr[1].header['NANCLEAN']
    except:
        naxis2 = 0
        for i in range(len(instr[1].columns.names)):
            if 'time' in instr[1].columns.names[i].lower():
                timecol = instr[1].columns.names[i]
        try:
            instr[1].data.field(datacol)
        except:
            msg = 'ERROR -- KEPIO.FILTERNAN: cannot find column ' + datacol + ' in the infile'
            status = kepmsg.err(logfile,msg,verbose)

        if status == 0:
            try:
                for i in range(len(instr[1].data.field(0))):
                    if str(instr[1].data.field(timecol)[i]) != '-inf' and \
                            str(instr[1].data.field(datacol)[i]) != '-inf':
                        instr[1].data[naxis2] = instr[1].data[i]
                        naxis2 += 1
                instr[1].data = instr[1].data[:naxis2]
                comment = 'NaN cadences removed from data'
                status = kepkey.new('NANCLEAN',True,comment,instr[1],outfile,logfile,verbose)
            except:
                msg = 'ERROR -- KEPIO.FILTERNAN: Failed to filter NaNs from '+ outfile
                status = kepmsg.err(logfile,msg,verbose)

    return instr, status
コード例 #3
0
def cadence(struct, file, logfile, verbose):
    # get keyword data

    status = 0
    try:
        int_time, status = get(file, struct, 'INT_TIME', logfile, verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword INT_TIME in file ' + file + '[1]'
        status = kepmsg.err(logfile, message, verbose)
    try:
        readtime, status = get(file, struct, 'READTIME', logfile, verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword READTIME in file ' + file + '[1]'
        status = kepmsg.err(logfile, message, verbose)
    try:
        num_frm, status = get(file, struct, 'NUM_FRM', logfile, verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword NUM_FRM in file ' + file + '[1]'
        status = kepmsg.err(logfile, message, verbose)

    # calculate cadence

    cadence = (float(int_time) + float(readtime)) * float(num_frm)

    return cadence, status
コード例 #4
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def cadence(struct,file,logfile,verbose):

# get keyword data

    status = 0
    try:
        int_time, status = get(file,struct,'INT_TIME',logfile,verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword INT_TIME in file ' + file + '[1]'
	status = kepmsg.err(logfile,message,verbose)
    try:
        readtime, status = get(file,struct,'READTIME',logfile,verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword READTIME in file ' + file + '[1]'
	status = kepmsg.err(logfile,message,verbose)
    try:
        num_frm, status = get(file,struct,'NUM_FRM',logfile,verbose)
    except:
        txt = 'ERROR -- KEPKEY.CADENCE: Cannot read keyword NUM_FRM in file ' + file + '[1]'
	status = kepmsg.err(logfile,message,verbose)

# calculate cadence

    cadence = (float(int_time) + float(readtime)) * float(num_frm)

    return cadence, status
コード例 #5
0
ファイル: kepmask.py プロジェクト: rodluger/PyKE
def clicker2(event):

    global mask, aid, bid, cid, did, eid, fid, done

    if event.inaxes:
        if event.button == 1:
            if (event.x > 601 and event.x < 801 and
                event.y > 422 and event.y < 482):
                disconnect(aid)
                disconnect(bid)
                disconnect(cid)
                disconnect(did)
                disconnect(eid)
                disconnect(fid)
                try:
                    lines, status = kepio.openascii(maskfile,'r',None,False)
                    for line in lines:
                        mask = []
                        work = line.strip().split('|')
                        y0 = int(work[3])
                        x0 = int(work[4])
                        work = work[5].split(';')
                        for i in range(len(work)):
                            y = int(work[i].split(',')[0]) + y0
                            x = int(work[i].split(',')[1]) + x0
                            mask.append(str(x) + ',' + str(y))
                        pylab.clf()
                        plotimage(cmdLine)
                except:
                    txt = 'ERROR -- KEPMASK: Cannot open or read mask file ' + maskfile
                    kepmsg.err(logfile,txt,True)
                     
    return
コード例 #6
0
def clicker2(event):

    global mask, aid, bid, cid, did, eid, fid, done

    if event.inaxes:
        if event.button == 1:
            if (event.x > 601 and event.x < 801 and event.y > 422
                    and event.y < 482):
                disconnect(aid)
                disconnect(bid)
                disconnect(cid)
                disconnect(did)
                disconnect(eid)
                disconnect(fid)
                try:
                    lines, status = kepio.openascii(maskfile, 'r', None, False)
                    for line in lines:
                        mask = []
                        work = line.strip().split('|')
                        y0 = int(work[3])
                        x0 = int(work[4])
                        work = work[5].split(';')
                        for i in range(len(work)):
                            y = int(work[i].split(',')[0]) + y0
                            x = int(work[i].split(',')[1]) + x0
                            mask.append(str(x) + ',' + str(y))
                        pylab.clf()
                        plotimage(cmdLine)
                except:
                    txt = 'ERROR -- KEPMASK: Cannot open or read mask file ' + maskfile
                    kepmsg.err(logfile, txt, True)

    return
コード例 #7
0
def timeranges(ranges, logfile, verbose):

    status = 0
    tstart = []
    tstop = []
    if '@' in ranges:
        try:
            lines, status = openascii(ranges[1:], 'r', logfile, verbose)
        except:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot open file ' + ranges[1:]
            status = kepmsg.err(logfile, txt, verbose)
            return tstart, tstop, status
        for line in lines:
            line = line.strip().split(',')
            if len(line) == 2:
                try:
                    float(line[0])
                    float(line[1])
                    tstart.append(float(line[0]))
                    tstop.append(float(line[1]))
                    if tstart[-1] == 0.0 and tstop[-1] == 0.0:
                        tstop[-1] = 1.0e8
                except:
                    continue
        status = closeascii(lines, logfile, verbose)
        if len(tstart) == 0 or len(
                tstop) == 0 or len(tstart) != len(tstop) or status > 0:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot understand content of ' + ranges[
                1:]
            status = kepmsg.err(logfile, txt, verbose)
            return tstart, tstop, status
    else:
        try:
            ranges = ranges.strip().split(';')
            for i in range(len(ranges)):
                tstart.append(float(ranges[i].strip().split(',')[0]))
                tstop.append(float(ranges[i].strip().split(',')[1]))
                if tstart[-1] == 0.0 and tstop[-1] == 0.0: tstop[-1] = 1.0e8
        except:
            tstart = []
            tstop = []
        if len(tstart) == 0 or len(
                tstop) == 0 or len(tstart) != len(tstop) or status > 0:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot understand time ranges provided'
            status = kepmsg.err(logfile, txt, verbose)
            return tstart, tstop, status

    return tstart, tstop, status
コード例 #8
0
def clicker2(event):

    global mask, aid, bid, cid, did, eid, fid, clobb, cmdLine

    if clobb: status = kepio.clobber(outf,logf,verb)
    if kepio.fileexists(outf): 
        message = 'ERROR -- KEPRANGE: ' + outf + ' exists. Use --clobber'
        status = kepmsg.err(logf,message,verb)
    else:
        if event.inaxes:
            if event.button == 1:
                if (event.x > 402 and event.x < 702 and
                    event.y > 12 and event.y < 68):
                    nt = 0; txt = ''
                    for i in range(int(len(mask)/2)):
                        t1 = float(mask[nt]) + barytime0
                        t2 = float(mask[nt+1]) + barytime0
                        if t1 < 2.4e6: t1 += 2.4e6
                        if t2 < 2.4e6: t2 += 2.4e6
                        txt += str(t1) + ',' + str(t2) + '\n'
                        nt += 2
                    txt = txt.strip()
                    print txt
                    kepmsg.file(outf,txt,True)
                    print '\nWrote ASCII file ' + outf
                    plotlc(cmdLine)
    return
コード例 #9
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def writeimage(struct,hdu,imagedata,logfile,verbose):

    status = 0
    try:
	struct[hdu].data = imagedata
    except:
	message = 'ERROR -- KEPIO.WRITEIMAGE: Cannot write image data to HDU ' + str(hdu)
	status = kepmsg.err(logfile,message,verbose)
    return struct, status
コード例 #10
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readimage(struct,hdu,logfile,verbose):

    status = 0
    try:
	imagedata = struct[hdu].data
    except:
	message = 'ERROR -- KEPIO.READIMAGE: cannot read image data from HDU ' + str(hdu)
	status = kepmsg.err(logfile,message,verbose)
    return imagedata, status
コード例 #11
0
def closefits(struct, logfile, verbose):

    status = 0
    try:
        struct.close()
    except:
        message = 'ERROR -- KEPIO.CLOSEFITS: cannot close HDU structure'
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #12
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def closefits(struct,logfile,verbose):

    status = 0
    try:
	struct.close()
    except:
	message = 'ERROR -- KEPIO.CLOSEFITS: cannot close HDU structure'
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #13
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def delete(file,logfile,verbose):

    status = 0
    try:
	os.remove(file)
    except:
	message = 'ERROR -- KEPIO.DELETE: could not delete ' + file
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #14
0
def delete(file, logfile, verbose):

    status = 0
    try:
        os.remove(file)
    except:
        message = 'ERROR -- KEPIO.DELETE: could not delete ' + file
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #15
0
def new(keyword, value, comment, hdu, file, logfile, verbose):
    status = 0
    try:
        hdu.header.update(keyword, value, comment)
    except:
        message = 'ERROR -- KEPKEY.NEW: Cannot create keyword ' + keyword
        message += ' in ' + file
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #16
0
def delete(keyword, hdu, file, logfile, verbose):
    status = 0
    try:
        del hdu.header[keyword]
    except:
        message = 'ERROR -- KEPKEY.DELETE: Cannot delete keyword ' + keyword
        message += ' in ' + file
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #17
0
def comment(txt, hdu, file, logfile, verbose):
    status = 0
    try:
        hdu.header.add_comment(txt)
    except:
        message = 'ERROR -- KEPKEY.COMMENT: Cannot create comment keyword'
        message += ' in ' + file
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #18
0
def history(txt, hdu, file, logfile, verbose):
    status = 0
    try:
        hdu.header.add_history(txt)
    except:
        message = 'ERROR -- KEPKEY.HISTORY: Cannot create history keyword'
        message += ' in ' + file
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #19
0
def readPRFimage(infile, hdu, logfile, verbose):

    status = 0

    # open input file

    prf, status = openfits(infile, 'readonly', logfile, verbose)

    # read bitmap image

    if status == 0:
        try:
            img = prf[hdu].data
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read PRF image in ' + infile + '[' + str(
                hdu) + ']'
            status = kepmsg.err(logfile, txt, verbose)
    if status == 0:
        try:
            naxis1 = prf[hdu].header['NAXIS1']
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read NAXIS1 keyword in ' + infile + '[' + str(
                hdu) + ']'
            status = kepmsg.err(logfile, txt, verbose)
    if status == 0:
        try:
            naxis2 = prf[hdu].header['NAXIS2']
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read NAXIS2 keyword in ' + infile + '[' + str(
                hdu) + ']'
            status = kepmsg.err(logfile, txt, verbose)

# read WCS keywords

    if status == 0:
        crpix1p, crpix2p, crval1p, crval2p, cdelt1p, cdelt2p, status = \
            kepkey.getWCSp(infile,prf[hdu],logfile,verbose)

# close input file

    if status == 0:
        status = closefits(prf, logfile, verbose)

    return img, crpix1p, crpix2p, crval1p, crval2p, cdelt1p, cdelt2p, status
コード例 #20
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readfitstab(file,hdu,logfile,verbose):

    status = 0
    try:
        table = hdu.data
    except:
	message = 'ERROR -- KEPIO.READFITSTAB: could not extract table from ' + file
	status = kepmsg.err(logfile,message,verbose)
	table = None
    return table, status
コード例 #21
0
def openfits(file, mode, logfile, verbose):

    status = 0
    try:
        struct = pyfits.open(file, mode=mode)
    except:
        message = 'ERROR -- KEPIO.OPENFITS: cannot open ' + file + ' as a FITS file'
        status = kepmsg.err(logfile, message, verbose)
        struct = None
    return struct, status
コード例 #22
0
def readimage(struct, hdu, logfile, verbose):

    status = 0
    try:
        imagedata = struct[hdu].data
    except:
        message = 'ERROR -- KEPIO.READIMAGE: cannot read image data from HDU ' + str(
            hdu)
        status = kepmsg.err(logfile, message, verbose)
    return imagedata, status
コード例 #23
0
def writeimage(struct, hdu, imagedata, logfile, verbose):

    status = 0
    try:
        struct[hdu].data = imagedata
    except:
        message = 'ERROR -- KEPIO.WRITEIMAGE: Cannot write image data to HDU ' + str(
            hdu)
        status = kepmsg.err(logfile, message, verbose)
    return struct, status
コード例 #24
0
def tmpfile(path, suffix, logfile, verbose):

    status = 0
    try:
        tempfile.tempdir = path
        file = tempfile.mktemp() + suffix
    except:
        message = 'ERROR -- KEPIO.TMPFILE: Cannot create temporary file name'
        status = kepmsg.err(logfile, message, verbose)
    return file, status
コード例 #25
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def clobber(file,logfile,verbose):

    status = 0
    if (os.path.isfile(file)):
	try:
	    status = delete(file,logfile,verbose)
	except:
	    message = 'ERROR -- KEPIO.CLOBBER: could not clobber ' + file
	    status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #26
0
def openascii(file, type, logfile, verbose):

    status = 0
    try:
        content = open(file, type)
    except:
        message = 'ERROR -- KEPIO.OPENASCII: cannot open ASCII file ' + file
        status = kepmsg.err(logfile, message, verbose)

    return content, status
コード例 #27
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def closeascii(file,logfile,verbose):

    status = 0
    try:
	file.close()
    except:
	message = 'ERROR - KEPIO.CLOSEASCII: cannot close ASCII file ' + str(file)
	status = kepmsg.err(logfile,message,verbose)
    
    return status
コード例 #28
0
def get(file, hdu, keyword, logfile, verbose):
    status = 0
    try:
        value = hdu.header[keyword]
    except:
        message = 'ERROR -- KEPKEY.GET: Cannot read keyword ' + keyword
        message += ' in file ' + file
        status = kepmsg.err(logfile, message, verbose)
        value = None
    return value, status
コード例 #29
0
def clobber(file, logfile, verbose):

    status = 0
    if (os.path.isfile(file)):
        try:
            status = delete(file, logfile, verbose)
        except:
            message = 'ERROR -- KEPIO.CLOBBER: could not clobber ' + file
            status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #30
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def delete(keyword,hdu,file,logfile,verbose):

    status = 0
    try:
	del hdu.header[keyword]
    except:
	message = 'ERROR -- KEPKEY.DELETE: Cannot delete keyword ' + keyword
	message += ' in ' + file
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #31
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def openfits(file,mode,logfile,verbose):

    status = 0
    try:
        struct = pyfits.open(file,mode=mode)
    except:
	message = 'ERROR -- KEPIO.OPENFITS: cannot open ' + file + ' as a FITS file'
	status = kepmsg.err(logfile,message,verbose)
	struct = None
    return struct, status
コード例 #32
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def history(txt,hdu,file,logfile,verbose):

    status = 0
    try:
	hdu.header.add_history(txt)
    except:
	message = 'ERROR -- KEPKEY.HISTORY: Cannot create history keyword'
	message += ' in ' + file
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #33
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def comment(txt,hdu,file,logfile,verbose):

    status = 0
    try:
	hdu.header.add_comment(txt)
    except:
	message = 'ERROR -- KEPKEY.COMMENT: Cannot create comment keyword'
	message += ' in ' + file
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #34
0
def change(keyword, value, hdu, file, logfile, verbose):
    status = 0
    try:
        hdu.header.update(keyword=value)
    except:
        message = 'ERROR -- KEPKEY.CHANGE: Cannot update keyword ' + keyword
        message += ' in ' + file
        status = kepmsg.err(logfile, message, verbose)

    return status
コード例 #35
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def tmpfile(path,suffix,logfile,verbose):

    status = 0
    try:
	tempfile.tempdir = path
        file = tempfile.mktemp() + suffix
    except:
	message = 'ERROR -- KEPIO.TMPFILE: Cannot create temporary file name'
	status = kepmsg.err(logfile,message,verbose)
    return file, status
コード例 #36
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def openascii(file,type,logfile,verbose):

    status = 0
    try:
	content = open(file,type)
    except:
	message = 'ERROR -- KEPIO.OPENASCII: cannot open ASCII file ' + file
	status = kepmsg.err(logfile,message,verbose)

    return content, status
コード例 #37
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def new(keyword,value,comment,hdu,file,logfile,verbose):

    status = 0
    try:
        hdu.header.update(keyword,value,comment)
    except:
	message = 'ERROR -- KEPKEY.NEW: Cannot create keyword ' + keyword
	message += ' in ' + file
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #38
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def parselist(inlist,logfile,verbose):

# test input name list
   
    status = 0
    inlist.strip()
    if (len(inlist) == 0 or inlist.count(' ') > 0):
	message = 'ERROR -- KEPIO.PARSELIST: list not specified'
	status = kepmsg.err(logfile,message,verbose)

# test @filelist exists

    if (inlist[0] == '@'):
	infile = inlist.lstrip('@')
	if not os.path.isfile(infile):
	    message = 'ERROR -- KEPIO.PARSELIST: input list '+infile+' does not exist'
	    status = kepmsg.err(logfile,message,verbose)

# parse wildcard and comma-separated lists

    outlist = []
    if (status == 0 and inlist[0] == '@'):
	line = ' '
        infile = open(inlist.lstrip('@'))
	while line:
	    line = infile.readline()
	    if (len(line.strip()) > 0):
		outlist.append(line.rstrip('\r\n'))
    elif (status == 0 and inlist[0] != '@' and inlist.count('*') == 0):
	if (inlist.count(',') == 0):
	    outlist.append(inlist)
        else:
	    list = inlist.split(',')
	    for listitem in list:
		outlist.append(listitem)
    elif (status == 0 and inlist[0] != '@' and inlist.count('*') > 0):
	outlist = glob.glob(inlist)
    if (status == 0 and len(outlist) == 0):
	message = 'ERROR -- KEPIO.PARSELIST: raw input image list is empty'
	status = kepmsg.err(logfile,message,verbose)

    return outlist, status
コード例 #39
0
def parselist(inlist, logfile, verbose):

    # test input name list

    status = 0
    inlist.strip()
    if (len(inlist) == 0 or inlist.count(' ') > 0):
        message = 'ERROR -- KEPIO.PARSELIST: list not specified'
        status = kepmsg.err(logfile, message, verbose)

# test @filelist exists

    if (inlist[0] == '@'):
        infile = inlist.lstrip('@')
        if not os.path.isfile(infile):
            message = 'ERROR -- KEPIO.PARSELIST: input list ' + infile + ' does not exist'
            status = kepmsg.err(logfile, message, verbose)

# parse wildcard and comma-separated lists

    outlist = []
    if (status == 0 and inlist[0] == '@'):
        line = ' '
        infile = open(inlist.lstrip('@'))
        while line:
            line = infile.readline()
            if (len(line.strip()) > 0):
                outlist.append(line.rstrip('\r\n'))
    elif (status == 0 and inlist[0] != '@' and inlist.count('*') == 0):
        if (inlist.count(',') == 0):
            outlist.append(inlist)
        else:
            list = inlist.split(',')
            for listitem in list:
                outlist.append(listitem)
    elif (status == 0 and inlist[0] != '@' and inlist.count('*') > 0):
        outlist = glob.glob(inlist)
    if (status == 0 and len(outlist) == 0):
        message = 'ERROR -- KEPIO.PARSELIST: raw input image list is empty'
        status = kepmsg.err(logfile, message, verbose)

    return outlist, status
コード例 #40
0
def closeascii(file, logfile, verbose):

    status = 0
    try:
        file.close()
    except:
        message = 'ERROR - KEPIO.CLOSEASCII: cannot close ASCII file ' + str(
            file)
        status = kepmsg.err(logfile, message, verbose)

    return status
コード例 #41
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readsapqualcol(file,table,logfile,verbose):

    status = 0
    try:
        data = table.field('SAP_QUALITY')
    except:
        message  = 'ERROR -- KEPIO.READSAPQUALCOL: could not extract SAP quality'
        message += ' time series data from ' + file
        status = kepmsg.err(logfile,message,verbose)
        data, status = None
    return data, status
コード例 #42
0
def readcbvcol(file, table, logfile, verbose):

    status = 0
    try:
        data = table.field('CBVSAP_FLUX')
    except:
        message = 'ERROR -- KEPIO.READCBVCOL: could not extract CBVSAP flux'
        message += ' time series data from ' + file
        status = kepmsg.err(logfile, message, verbose)
        data = None
    return data, status
コード例 #43
0
def writefits(hdu, filename, clobber, logfile, verbose):

    status = 0
    if (os.path.isfile(filename) and clobber):
        delete(filename, logfile, verbose)
    try:
        hdu.writeto(filename)
    except:
        message = 'ERROR -- KEPIO.WRITEFITS: Cannot create FITS file ' + filename
        status = kepmsg.err(logfile, message, verbose)
    return status
コード例 #44
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def writefits(hdu,filename,clobber,logfile,verbose):

    status = 0
    if (os.path.isfile(filename) and clobber):
	delete(filename,logfile,verbose)
    try:
	hdu.writeto(filename)
    except:
	message = 'ERROR -- KEPIO.WRITEFITS: Cannot create FITS file ' + filename
	status = kepmsg.err(logfile,message,verbose)
    return status
コード例 #45
0
def readsapqualcol(file, table, logfile, verbose):

    status = 0
    try:
        data = table.field('SAP_QUALITY')
    except:
        message = 'ERROR -- KEPIO.READSAPQUALCOL: could not extract SAP quality'
        message += ' time series data from ' + file
        status = kepmsg.err(logfile, message, verbose)
        data, status = None
    return data, status
コード例 #46
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readfitscol(file,table,column,logfile,verbose):

    status = 0
    try:
	data = table.field(column)
    except:
	message  = 'ERROR -- KEPIO.READFITSCOL: could not extract ' + column 
	message += ' data from ' + file
	status = kepmsg.err(logfile,message,verbose)
	data = None
    return data, status
コード例 #47
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readcbvcol(file,table,logfile,verbose):

    status = 0
    try:
        data = table.field('CBVSAP_FLUX')
    except:
        message  = 'ERROR -- KEPIO.READCBVCOL: could not extract CBVSAP flux'
        message += ' time series data from ' + file
        status = kepmsg.err(logfile,message,verbose)
        data = None
    return data, status
コード例 #48
0
def readfitscol(file, table, column, logfile, verbose):

    status = 0
    try:
        data = table.field(column)
    except:
        message = 'ERROR -- KEPIO.READFITSCOL: could not extract ' + column
        message += ' data from ' + file
        status = kepmsg.err(logfile, message, verbose)
        data = None
    return data, status
コード例 #49
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def change(keyword,value,hdu,file,logfile,verbose):

    status = 0
    try:
	hdu.header.update(keyword,value)
    except:
	message = 'ERROR -- KEPKEY.CHANGE: Cannot update keyword ' + keyword
	message += ' in ' + file
	status = kepmsg.err(logfile,message,verbose)

    return status
コード例 #50
0
ファイル: kepkey.py プロジェクト: KeplerGO/PyKE
def get(file,hdu,keyword,logfile,verbose):

    status = 0
    try:
	value = hdu.header[keyword]
    except:
	message = 'ERROR -- KEPKEY.GET: Cannot read keyword ' + keyword
	message += ' in file ' + file
	status = kepmsg.err(logfile,message,verbose)
	value = None
    return value, status
コード例 #51
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def timeranges(ranges,logfile,verbose):

    status = 0; tstart = []; tstop = []
    if '@' in ranges:
        try:
            lines, status = openascii(ranges[1:],'r',logfile,verbose)
        except:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot open file ' + ranges[1:]
            status = kepmsg.err(logfile,txt,verbose)
            return tstart, tstop, status
        for line in lines:
            line = line.strip().split(',')
            if len(line) == 2:
                try:
                    float(line[0])
                    float(line[1])
                    tstart.append(float(line[0]))
                    tstop.append(float(line[1]))
                    if tstart[-1] == 0.0 and tstop[-1] == 0.0: tstop[-1] = 1.0e8
                except:
                    continue
        status = closeascii(lines,logfile,verbose)
        if len(tstart) == 0 or len(tstop) == 0 or len(tstart) != len(tstop) or status > 0:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot understand content of ' + ranges[1:]
            status = kepmsg.err(logfile,txt,verbose)
            return tstart, tstop, status
    else:
        try:
            ranges = ranges.strip().split(';')
            for i in range(len(ranges)):
                tstart.append(float(ranges[i].strip().split(',')[0]))
                tstop.append(float(ranges[i].strip().split(',')[1]))
                if tstart[-1] == 0.0 and tstop[-1] == 0.0: tstop[-1] = 1.0e8
        except:
            tstart = []; tstop = []
        if len(tstart) == 0 or len(tstop) == 0 or len(tstart) != len(tstop) or status > 0:
            txt = 'ERROR -- KEPIO.TIMERANGES: cannot understand time ranges provided'
            status = kepmsg.err(logfile,txt,verbose)
            return tstart, tstop, status
        
    return tstart, tstop, status
コード例 #52
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def readPRFimage(infile,hdu,logfile,verbose):

    status = 0

# open input file

    prf, status = openfits(infile,'readonly',logfile,verbose)

# read bitmap image

    if status == 0:
        try:
            img = prf[hdu].data
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read PRF image in ' + infile + '[' + str(hdu) + ']'
            status = kepmsg.err(logfile,txt,verbose)
    if status == 0:
        try:
            naxis1 = prf[hdu].header['NAXIS1']
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read NAXIS1 keyword in ' + infile + '[' + str(hdu) + ']'
            status = kepmsg.err(logfile,txt,verbose)
    if status == 0:
        try:
            naxis2 = prf[hdu].header['NAXIS2']
        except:
            txt = 'ERROR -- KEPIO.READPRFIMAGE: Cannot read NAXIS2 keyword in ' + infile + '[' + str(hdu) + ']'
            status = kepmsg.err(logfile,txt,verbose)

# read WCS keywords

    if status == 0:
        crpix1p, crpix2p, crval1p, crval2p, cdelt1p, cdelt2p, status = \
            kepkey.getWCSp(infile,prf[hdu],logfile,verbose)     

# close input file

    if status == 0:
        status = closefits(prf,logfile,verbose)

    return img, crpix1p, crpix2p, crval1p, crval2p, cdelt1p, cdelt2p, status
コード例 #53
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def copy(file1,file2,logfile,verbose):

    status = 0
    message = 'KEPIO.COPY -- copied ' + file1 + ' to ' + file2
    try:
	shutil.copy2(file1,file2)
	kepmsg.log(logfile,message,verbose)
    except:
	message = 'ERROR -- KEPIO.COPY: could not copy ' + file1 + ' to ' + file2
	status = kepmsg.err(logfile,message,verbose)

    return status
コード例 #54
0
def readfitstab(file, hdu, logfile, verbose):

    status = 0
    try:
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            table = hdu.data
    except:
        message = 'ERROR -- KEPIO.READFITSTAB: could not extract table from ' + file
        status = kepmsg.err(logfile, message, verbose)
        table = None
    return table, status
コード例 #55
0
ファイル: kepio.py プロジェクト: KeplerGO/PyKE
def readfitstab(file,hdu,logfile,verbose):

    status = 0
    try:
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            table = hdu.data
    except:
	message = 'ERROR -- KEPIO.READFITSTAB: could not extract table from ' + file
	status = kepmsg.err(logfile,message,verbose)
	table = None
    return table, status
コード例 #56
0
ファイル: kepio.py プロジェクト: Sleekery/PyKE
def move(file1,file2,logfile,verbose):

    status = 0
    message = 'KEPIO.MOVE -- moved ' + file1 + ' to ' + file2
    try:
        shutil.move(file1,file2)
        kepmsg.log(logfile,message,verbose)
    except:
	message = 'ERROR -- KEPIO.MOVE: Could not move ' + file1 + ' to ' + file2
	status = kepmsg.err(logfile,message,verbose)

    return status
コード例 #57
0
def copy(file1, file2, logfile, verbose):

    status = 0
    message = 'KEPIO.COPY -- copied ' + file1 + ' to ' + file2
    try:
        shutil.copy2(file1, file2)
        kepmsg.log(logfile, message, verbose)
    except:
        message = 'ERROR -- KEPIO.COPY: could not copy ' + file1 + ' to ' + file2
        status = kepmsg.err(logfile, message, verbose)

    return status
コード例 #58
0
def move(file1, file2, logfile, verbose):

    status = 0
    message = 'KEPIO.MOVE -- moved ' + file1 + ' to ' + file2
    try:
        shutil.move(file1, file2)
        kepmsg.log(logfile, message, verbose)
    except:
        message = 'ERROR -- KEPIO.MOVE: Could not move ' + file1 + ' to ' + file2
        status = kepmsg.err(logfile, message, verbose)

    return status
コード例 #59
0
ファイル: kepstat.py プロジェクト: rodluger/PyKE
def median(list, logfile):

    list.sort()
    n = len(list)
    if (n == 0):
        message = 'ERROR -- KEPSTAT.MEDIAN: Supplied list is empty'
        status = kepmsg.err(logfile, message)
        median = None
    elif (n < 3):
        median = mean(list)
    else:
        median = list[n / 2]
    return median