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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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