def keptrial(infile, outfile, datacol, errcol, fmin, fmax, nfreq, method, ntrials, plot, clobber, verbose, logfile, status, cmdLine=False): # startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 # log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile, hashline, verbose) call = 'KEPTRIAL -- ' call += 'infile=' + infile + ' ' call += 'outfile=' + outfile + ' ' call += 'datacol=' + datacol + ' ' call += 'errcol=' + errcol + ' ' call += 'fmin=' + str(fmin) + ' ' call += 'fmax=' + str(fmax) + ' ' call += 'nfreq=' + str(nfreq) + ' ' call += 'method=' + method + ' ' call += 'ntrials=' + str(ntrials) + ' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot=' + plotit + ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber=' + overwrite + ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose=' + chatter + ' ' call += 'logfile=' + logfile kepmsg.log(logfile, call + '\n', verbose) # start time kepmsg.clock('KEPTRIAL started at', logfile, verbose) # test log file logfile = kepmsg.test(logfile) # clobber output file if clobber: status = kepio.clobber(outfile, logfile, verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPTRIAL: ' + outfile + ' exists. Use clobber=yes' kepmsg.err(logfile, message, verbose) status = 1 # open input file if status == 0: instr, status = kepio.openfits(infile, 'readonly', logfile, verbose) # fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr, file, logfile, verbose) # input data if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile, instr[1].data, 'time', logfile, verbose) if status == 0: signal, status = kepio.readfitscol(infile, instr[1].data, datacol, logfile, verbose) if status == 0: err, status = kepio.readfitscol(infile, instr[1].data, errcol, logfile, verbose) # remove infinite data from time series if status == 0: try: nanclean = instr[1].header['NANCLEAN'] except: incols = [barytime, signal, err] [barytime, signal, err] = kepstat.removeinfinlc(signal, incols) # set up plot if status == 0: plotLatex = True try: params = { 'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight': 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize } rcParams.update(params) except: print('WARNING: install latex for scientific plotting') plotLatex = False # frequency steps and Monte Carlo iterations if status == 0: deltaf = (fmax - fmin) / nfreq freq = [] pmax = [] trial = [] for i in range(ntrials): trial.append(i + 1) # adjust data within the error bars work1 = kepstat.randarray(signal, err) # determine FT power fr, power = kepfourier.ft(barytime, work1, fmin, fmax, deltaf, False) # determine peak in FT pmax.append(-1.0e30) for j in range(len(fr)): if (power[j] > pmax[-1]): pmax[-1] = power[j] f1 = fr[j] freq.append(f1) # plot stop-motion histogram pylab.ion() pylab.figure(1, figsize=[7, 10]) clf() pylab.axes([0.08, 0.08, 0.88, 0.89]) pylab.gca().xaxis.set_major_formatter( pylab.ScalarFormatter(useOffset=False)) pylab.gca().yaxis.set_major_formatter( pylab.ScalarFormatter(useOffset=False)) n, bins, patches = pylab.hist(freq, bins=nfreq, range=[fmin, fmax], align='mid', rwidth=1, ec='#0000ff', fc='#ffff00', lw=2) # fit normal distribution to histogram x = zeros(len(bins)) for j in range(1, len(bins)): x[j] = (bins[j] + bins[j - 1]) / 2 pinit = numpy.array([float(i), freq[-1], deltaf]) if i > 3: n = array(n, dtype='float32') coeffs, errors, covar, sigma, chi2, dof, fit, plotx, ploty, status = \ kepfit.leastsquare('gauss',pinit,x[1:],n,None,logfile,verbose) fitfunc = kepfunc.gauss() f = arange(fmin, fmax, (fmax - fmin) / 100) fit = fitfunc(coeffs, f) pylab.plot(f, fit, 'r-', linewidth=2) if plotLatex: xlabel(r'Frequency (d$^{-1}$)', {'color': 'k'}) else: xlabel(r'Frequency (1/d)', {'color': 'k'}) ylabel('N', {'color': 'k'}) xlim(fmin, fmax) grid() # render plot if plot: if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() # period results if status == 0: p = 1.0 / coeffs[1] perr = p * coeffs[2] / coeffs[1] f1 = fmin f2 = fmax gotbin = False for i in range(len(n)): if n[i] > 0 and not gotbin: f1 = bins[i] gotbin = True gotbin = False for i in range(len(n) - 1, 0, -1): if n[i] > 0 and not gotbin: f2 = bins[i + 1] gotbin = True powave, powstdev = kepstat.stdev(pmax) # print result if status == 0: print(' best period: %.10f days (%.7f min)' % (p, p * 1440.0)) print(' 1-sigma period error: %.10f days (%.7f min)' % (perr, perr * 1440.0)) print(' search range: %.10f - %.10f days ' % (1.0 / fmax, 1.0 / fmin)) print(' 100%% confidence range: %.10f - %.10f days ' % (1.0 / f2, 1.0 / f1)) # print ' detection confidence: %.2f sigma' % (powave / powstdev) print(' number of trials: %d' % ntrials) print(' number of frequency bins: %d' % nfreq) # history keyword in output file if status == 0: status = kepkey.history(call, instr[0], outfile, logfile, verbose) ## write output file if status == 0: col1 = Column(name='TRIAL', format='J', array=trial) col2 = Column(name='FREQUENCY', format='E', unit='1/day', array=freq) col3 = Column(name='POWER', format='E', array=pmax) cols = ColDefs([col1, col2, col3]) instr.append(new_table(cols)) try: instr[-1].header.update('EXTNAME', 'TRIALS', 'Extension name') except: status = 1 try: instr[-1].header.update('SEARCHR1', 1.0 / fmax, 'Search range lower bound (days)') except: status = 1 try: instr[-1].header.update('SEARCHR2', 1.0 / fmin, 'Search range upper bound (days)') except: status = 1 try: instr[-1].header.update('NFREQ', nfreq, 'Number of frequency bins') except: status = 1 try: instr[-1].header.update('PERIOD', p, 'Best period (days)') except: status = 1 try: instr[-1].header.update('PERIODE', perr, '1-sigma period error (days)') except: status = 1 # instr[-1].header.update('DETNCONF',powave/powstdev,'Detection significance (sigma)') try: instr[-1].header.update('CONFIDR1', 1.0 / f2, 'Trial confidence lower bound (days)') except: status = 1 try: instr[-1].header.update('CONFIDR2', 1.0 / f1, 'Trial confidence upper bound (days)') except: status = 1 try: instr[-1].header.update('NTRIALS', ntrials, 'Number of trials') except: status = 1 instr.writeto(outfile) # close input file if status == 0: status = kepio.closefits(instr, logfile, verbose) ## end time if (status == 0): message = 'KEPTRAIL completed at' else: message = '\nKEPTRIAL aborted at' kepmsg.clock(message, logfile, verbose)
def kepft(infile, outfile, fcol, pmin, pmax, nfreq, plot, clobber, verbose, logfile, status, cmdLine=False): ## startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 ## log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile, hashline, verbose) call = 'KEPFT -- ' call += 'infile=' + infile + ' ' call += 'outfile=' + outfile + ' ' call += 'fcol=' + fcol + ' ' call += 'pmin=' + str(pmin) + ' ' call += 'pmax=' + str(pmax) + ' ' call += 'nfreq=' + str(nfreq) + ' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot=' + plotit + ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber=' + overwrite + ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose=' + chatter + ' ' call += 'logfile=' + logfile kepmsg.log(logfile, call + '\n', verbose) ## start time kepmsg.clock('Start time is', logfile, verbose) ## test log file logfile = kepmsg.test(logfile) ## clobber output file if clobber: status = kepio.clobber(outfile, logfile, verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPFT: ' + outfile + ' exists. Use --clobber' status = kepmsg.err(logfile, message, verbose) ## open input file if status == 0: instr, status = kepio.openfits(infile, 'readonly', logfile, verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys( instr, infile, logfile, verbose, status) ## fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr, file, logfile, verbose) ## read table columns if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile, instr[1].data, 'time', logfile, verbose) signal, status = kepio.readfitscol(infile, instr[1].data, fcol, logfile, verbose) if status == 0: barytime = barytime + bjdref ## remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] - median(outcols[1]) ## period to frequency conversion fmin = 1.0 / pmax fmax = 1.0 / pmin deltaf = (fmax - fmin) / nfreq ## loop through frequency steps; determine FT power if status == 0: fr, power = kepfourier.ft(barytime, signal, fmin, fmax, deltaf, True) ## write output file if status == 0: col1 = Column(name='FREQUENCY', format='E', unit='1/day', array=fr) col2 = Column(name='POWER', format='E', array=power) cols = ColDefs([col1, col2]) instr.append(new_table(cols)) instr[-1].header.update('EXTNAME', 'POWER SPECTRUM', 'extension name') instr.writeto(outfile) ## history keyword in output file if status == 0: status = kepkey.history(call, instr[0], outfile, logfile, verbose) ## close input file if status == 0: status = kepio.closefits(instr, logfile, verbose) ## data limits if status == 0: nrm = int(log10(power.max())) power = power / 10**nrm ylab = 'Power (x10$^{%d}$)' % nrm xmin = fr.min() xmax = fr.max() ymin = power.min() ymax = power.max() xr = xmax - xmin yr = ymax - ymin fr = insert(fr, [0], fr[0]) fr = append(fr, fr[-1]) power = insert(power, [0], 0.0) power = append(power, 0.0) ## plot power spectrum if status == 0 and plot: try: params = { 'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight': 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize } rcParams.update(params) except: print 'ERROR -- KEPFT: install latex for scientific plotting' status = 1 if status == 0 and plot: pylab.figure(1, figsize=[xsize, ysize]) pylab.clf() pylab.axes([0.06, 0.113, 0.93, 0.86]) pylab.plot(fr, power, color=lcolor, linestyle='-', linewidth=lwidth) fill(fr, power, color=fcolor, linewidth=0.0, alpha=falpha) xlim(xmin - xr * 0.01, xmax + xr * 0.01) if ymin - yr * 0.01 <= 0.0: ylim(1.0e-10, ymax + yr * 0.01) else: ylim(ymin - yr * 0.01, ymax + yr * 0.01) xlabel(r'Frequency (d$^{-1}$)', {'color': 'k'}) ylabel(ylab, {'color': 'k'}) grid() # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() ## end time if (status == 0): message = 'KEPFT completed at' else: message = '\nKEPFT aborted at' kepmsg.clock(message, logfile, verbose)
def kepwindow(infile, outfile, fcol, fmax, nfreq, plot, clobber, verbose, logfile, status, cmdLine=False): ## startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 ## log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile, hashline, verbose) call = 'KEPWINDOW -- ' call += 'infile=' + infile + ' ' call += 'outfile=' + outfile + ' ' call += 'fcol=' + fcol + ' ' call += 'fmax=' + str(fmax) + ' ' call += 'nfreq=' + str(nfreq) + ' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot=' + plotit + ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber=' + overwrite + ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose=' + chatter + ' ' call += 'logfile=' + logfile kepmsg.log(logfile, call + '\n', verbose) ## start time kepmsg.clock('KEPWINDOW started at', logfile, verbose) ## test log file logfile = kepmsg.test(logfile) ## clobber output file if clobber: status = kepio.clobber(outfile, logfile, verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPWINDOW: ' + outfile + ' exists. Use clobber=yes' status = kepmsg.err(logfile, message, verbose) ## open input file if status == 0: instr, status = kepio.openfits(infile, 'readonly', logfile, verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys( instr, infile, logfile, verbose, status) if status == 0: try: work = instr[0].header['FILEVER'] cadenom = 1.0 except: cadenom = cadence ## fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr, file, logfile, verbose) ## read table columns if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile, instr[1].data, 'time', logfile, verbose) signal, status = kepio.readfitscol(infile, instr[1].data, fcol, logfile, verbose) ## remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] ## reset signal data to zero if status == 0: signal = ones(len(outcols[1])) ## frequency steps if status == 0: deltaf = fmax / nfreq ## loop through frequency steps; determine FT power if status == 0: fr, power = kepfourier.ft(barytime, signal, 0.0, fmax, deltaf, True) power[0] = 1.0 ## mirror window function around ordinate if status == 0: work1 = [] work2 = [] for i in range(len(fr) - 1, 0, -1): work1.append(-fr[i]) work2.append(power[i]) for i in range(len(fr)): work1.append(fr[i]) work2.append(power[i]) fr = array(work1, dtype='float32') power = array(work2, dtype='float32') ## write output file if status == 0: col1 = Column(name='FREQUENCY', format='E', unit='days', array=fr) col2 = Column(name='POWER', format='E', array=power) cols = ColDefs([col1, col2]) instr.append(new_table(cols)) instr[-1].header.update('EXTNAME', 'WINDOW FUNCTION', 'extension name') ## comment keyword in output file if status == 0: status = kepkey.comment(call, instr[0], outfile, logfile, verbose) instr.writeto(outfile) ## close input file if status == 0: status = kepio.closefits(instr, logfile, verbose) ## data limits if status == 0: nrm = len(str(int(power.max()))) - 1 power = power / 10**nrm ylab = 'Power (x10$^%d$)' % nrm xmin = fr.min() xmax = fr.max() ymin = power.min() ymax = power.max() xr = xmax - xmin yr = ymax - ymin fr = insert(fr, [0], fr[0]) fr = append(fr, fr[-1]) power = insert(power, [0], 0.0) power = append(power, 0.0) ## plot power spectrum if status == 0 and plot: try: params = { 'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight': 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize } rcParams.update(params) except: print('ERROR -- KEPWINDOW: install latex for scientific plotting') status = 1 if status == 0 and plot: pylab.figure(1, figsize=[xsize, ysize]) pylab.axes([0.06, 0.113, 0.93, 0.86]) pylab.plot(fr, power, color=lcolor, linestyle='-', linewidth=lwidth) fill(fr, power, color=fcolor, linewidth=0.0, alpha=falpha) xlim(xmin - xr * 0.01, xmax + xr * 0.01) if ymin - yr * 0.01 <= 0.0: ylim(1.0e-10, ymax + yr * 0.01) else: ylim(ymin - yr * 0.01, ymax + yr * 0.01) xlabel(r'Frequency (d$^{-1}$)', {'color': 'k'}) ylabel('Power', {'color': 'k'}) # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() ## end time if (status == 0): message = 'KEPWINDOW completed at' else: message = '\nKEPWINDOW aborted at' kepmsg.clock(message, logfile, verbose)
def kepdynamic(infile,outfile,fcol,pmin,pmax,nfreq,deltat,nslice, plot,plotscale,cmap,clobber,verbose,logfile,status,cmdLine=False): # startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 12 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 numpy.seterr(all="ignore") # log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile,hashline,verbose) call = 'KEPDYNAMIC -- ' call += 'infile='+infile+' ' call += 'outfile='+outfile+' ' call += 'fcol='+fcol+' ' call += 'pmin='+str(pmin)+' ' call += 'pmax='+str(pmax)+' ' call += 'nfreq='+str(nfreq)+' ' call += 'deltat='+str(deltat)+' ' call += 'nslice='+str(nslice)+' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot='+plotit+ ' ' call += 'plotscale='+plotscale+ ' ' call += 'cmap='+str(cmap)+' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber='+overwrite+ ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose='+chatter+' ' call += 'logfile='+logfile kepmsg.log(logfile,call+'\n',verbose) # start time kepmsg.clock('Start time is',logfile,verbose) # test log file logfile = kepmsg.test(logfile) # error checking if status == 0 and pmin >= pmax: message = 'ERROR -- KEPDYNAMIC: PMIN must be less than PMAX' status = kepmsg.err(logfile,message,verbose) # clobber output file if clobber: status = kepio.clobber(outfile,logfile,verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPDYNAMIC: ' + outfile + ' exists. Use clobber' status = kepmsg.err(logfile,message,verbose) # plot color map if status == 0 and cmap == 'browse': status = keplab.cmap_plot() # open input file if status == 0: instr, status = kepio.openfits(infile,'readonly',logfile,verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys(instr,infile,logfile,verbose,status) if status == 0: try: work = instr[0].header['FILEVER'] cadenom = 1.0 except: cadenom = cadence # fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr,file,logfile,verbose) # read table columns if status == 0: barytime, status = kepio.readtimecol(infile,instr[1].data,logfile,verbose) if status == 0: signal, status = kepio.readfitscol(infile,instr[1].data,fcol,logfile,verbose) if status == 0: barytime = barytime + bjdref signal = signal / cadenom # remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] # period to frequency conversion if status == 0: fmin = 1.0 / pmax fmax = 1.0 / pmin deltaf = (fmax - fmin) / nfreq # determine bounds of time slices if status == 0: t1 = []; t2 = [] dt = barytime[-1] - barytime[0] dt -= deltat if dt < 0: message = 'ERROR -- KEPDYNAMIC: time slices are larger than data range' status = kepmsg.err(logfile,message,verbose) ds = dt / (nslice - 1) for i in range(nslice): t1.append(barytime[0] + ds * float(i)) t2.append(barytime[0] + deltat + ds * float(i)) # loop through time slices if status == 0: dynam = [] for i in range(nslice): x = []; y = [] for j in range(len(barytime)): if (barytime[j] >= t1[i] and barytime[j] <= t2[i]): x.append(barytime[j]) y.append(signal[j]) x = array(x,dtype='float64') y = array(y,dtype='float32') y = y - median(y) # determine FT power fr, power = kepfourier.ft(x,y,fmin,fmax,deltaf,False) for j in range(len(power)): dynam.append(power[j]) print('Timeslice: %.4f Pmax: %.2E' % ((t2[i] + t1[i]) / 2, power.max())) # define shape of results array dynam = array(dynam,dtype='float64') dynam.shape = len(t1),len(power) # write output file if status == 0: instr.append(ImageHDU()) instr[-1].data = dynam.transpose() instr[-1].header.update('EXTNAME','DYNAMIC FT','extension name') instr[-1].header.update('WCSAXES',2,'number of WCS axes') instr[-1].header.update('CRPIX1',0.5,'reference pixel along axis 1') instr[-1].header.update('CRPIX2',0.5,'reference pixel along axis 2') instr[-1].header.update('CRVAL1',t1[0],'time at reference pixel (BJD)') instr[-1].header.update('CRVAL2',fmin,'frequency at reference pixel (1/day)') instr[-1].header.update('CDELT1',(barytime[-1] - barytime[0]) / nslice, 'pixel scale in dimension 1 (days)') instr[-1].header.update('CDELT2',deltaf,'pixel scale in dimension 2 (1/day)') instr[-1].header.update('CTYPE1','BJD','data type of dimension 1') instr[-1].header.update('CTYPE2','FREQUENCY','data type of dimension 2') instr.writeto(outfile) # history keyword in output file if status == 0: status = kepkey.history(call,instr[0],outfile,logfile,verbose) # close input file if status == 0: status = kepio.closefits(instr,logfile,verbose) # clean up x-axis unit if status == 0: time0 = float(int(barytime[0] / 100) * 100.0) barytime = barytime - time0 xlab = 'BJD $-$ %d' % time0 # image intensity min and max if status == 0: if 'rithmic' in plotscale: dynam = numpy.log10(dynam) elif 'sq' in plotscale: dynam = numpy.sqrt(dynam) elif 'logoflog' in plotscale: dynam = numpy.log10(numpy.abs(numpy.log10(dynam))) # dynam = -dynam nstat = 2; pixels = [] for i in range(dynam.shape[0]): for j in range(dynam.shape[1]): pixels.append(dynam[i,j]) pixels = array(sort(pixels),dtype=float32) if int(float(len(pixels)) * 0.1 + 0.5) > nstat: nstat = int(float(len(pixels)) * 0.1 + 0.5) zmin = median(pixels[:nstat]) zmax = median(pixels[-1:]) if isnan(zmax): zmax = median(pixels[-nstat/2:]) if isnan(zmax): zmax = numpy.nanmax(pixels) # plot power spectrum if status == 0 and plot: params = {'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight' : 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize} rcParams.update(params) pylab.figure(1,figsize=[xsize,ysize]) pylab.clf() pylab.axes([0.08,0.113,0.91,0.86]) dynam = dynam.transpose() pylab.imshow(dynam,origin='lower',aspect='auto',cmap=cmap,vmin=zmin,vmax=zmax, extent=[barytime[0],barytime[-1],fmin,fmax],interpolation='bilinear') xlabel(xlab, {'color' : 'k'}) ylabel(r'Frequency (d$^{-1}$)', {'color' : 'k'}) grid() pylab.savefig(re.sub('\.\S+','.png',outfile),dpi=100) # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() return status ## end time if (status == 0): message = 'KEPDYNAMIC completed at' else: message = '\nKEPDYNAMIC aborted at' kepmsg.clock(message,logfile,verbose)
def keptrial(infile,outfile,datacol,errcol,fmin,fmax,nfreq,method, ntrials,plot,clobber,verbose,logfile,status,cmdLine=False): # startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 # log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile,hashline,verbose) call = 'KEPTRIAL -- ' call += 'infile='+infile+' ' call += 'outfile='+outfile+' ' call += 'datacol='+datacol+' ' call += 'errcol='+errcol+' ' call += 'fmin='+str(fmin)+' ' call += 'fmax='+str(fmax)+' ' call += 'nfreq='+str(nfreq)+' ' call += 'method='+method+' ' call += 'ntrials='+str(ntrials)+' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot='+plotit+ ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber='+overwrite+ ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose='+chatter+' ' call += 'logfile='+logfile kepmsg.log(logfile,call+'\n',verbose) # start time kepmsg.clock('KEPTRIAL started at',logfile,verbose) # test log file logfile = kepmsg.test(logfile) # clobber output file if clobber: status = kepio.clobber(outfile,logfile,verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPTRIAL: ' + outfile + ' exists. Use clobber=yes' kepmsg.err(logfile,message,verbose) status = 1 # open input file if status == 0: instr, status = kepio.openfits(infile,'readonly',logfile,verbose) # fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr,file,logfile,verbose) # input data if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile,instr[1].data,'time',logfile,verbose) if status == 0: signal, status = kepio.readfitscol(infile,instr[1].data,datacol,logfile,verbose) if status == 0: err, status = kepio.readfitscol(infile,instr[1].data,errcol,logfile,verbose) # remove infinite data from time series if status == 0: try: nanclean = instr[1].header['NANCLEAN'] except: incols = [barytime, signal, err] [barytime, signal, err] = kepstat.removeinfinlc(signal, incols) # set up plot if status == 0: plotLatex = True try: params = {'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight' : 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize} rcParams.update(params) except: print('WARNING: install latex for scientific plotting') plotLatex = False # frequency steps and Monte Carlo iterations if status == 0: deltaf = (fmax - fmin) / nfreq freq = []; pmax = []; trial = [] for i in range(ntrials): trial.append(i+1) # adjust data within the error bars work1 = kepstat.randarray(signal,err) # determine FT power fr, power = kepfourier.ft(barytime,work1,fmin,fmax,deltaf,False) # determine peak in FT pmax.append(-1.0e30) for j in range(len(fr)): if (power[j] > pmax[-1]): pmax[-1] = power[j] f1 = fr[j] freq.append(f1) # plot stop-motion histogram pylab.ion() pylab.figure(1,figsize=[7,10]) clf() pylab.axes([0.08,0.08,0.88,0.89]) pylab.gca().xaxis.set_major_formatter(pylab.ScalarFormatter(useOffset=False)) pylab.gca().yaxis.set_major_formatter(pylab.ScalarFormatter(useOffset=False)) n,bins,patches = pylab.hist(freq,bins=nfreq,range=[fmin,fmax], align='mid',rwidth=1,ec='#0000ff', fc='#ffff00',lw=2) # fit normal distribution to histogram x = zeros(len(bins)) for j in range(1,len(bins)): x[j] = (bins[j] + bins[j-1]) / 2 pinit = numpy.array([float(i),freq[-1],deltaf]) if i > 3: n = array(n,dtype='float32') coeffs, errors, covar, sigma, chi2, dof, fit, plotx, ploty, status = \ kepfit.leastsquare('gauss',pinit,x[1:],n,None,logfile,verbose) fitfunc = kepfunc.gauss() f = arange(fmin,fmax,(fmax-fmin)/100) fit = fitfunc(coeffs,f) pylab.plot(f,fit,'r-',linewidth=2) if plotLatex: xlabel(r'Frequency (d$^{-1}$)', {'color' : 'k'}) else: xlabel(r'Frequency (1/d)', {'color' : 'k'}) ylabel('N', {'color' : 'k'}) xlim(fmin,fmax) grid() # render plot if plot: if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() # period results if status == 0: p = 1.0 / coeffs[1] perr = p * coeffs[2] / coeffs[1] f1 = fmin; f2 = fmax gotbin = False for i in range(len(n)): if n[i] > 0 and not gotbin: f1 = bins[i] gotbin = True gotbin = False for i in range(len(n)-1,0,-1): if n[i] > 0 and not gotbin: f2 = bins[i+1] gotbin = True powave, powstdev = kepstat.stdev(pmax) # print result if status == 0: print(' best period: %.10f days (%.7f min)' % (p, p * 1440.0)) print(' 1-sigma period error: %.10f days (%.7f min)' % (perr, perr * 1440.0)) print(' search range: %.10f - %.10f days ' % (1.0 / fmax, 1.0 / fmin)) print(' 100%% confidence range: %.10f - %.10f days ' % (1.0 / f2, 1.0 / f1)) # print ' detection confidence: %.2f sigma' % (powave / powstdev) print(' number of trials: %d' % ntrials) print(' number of frequency bins: %d' % nfreq) # history keyword in output file if status == 0: status = kepkey.history(call,instr[0],outfile,logfile,verbose) ## write output file if status == 0: col1 = Column(name='TRIAL',format='J',array=trial) col2 = Column(name='FREQUENCY',format='E',unit='1/day',array=freq) col3 = Column(name='POWER',format='E',array=pmax) cols = ColDefs([col1,col2,col3]) instr.append(new_table(cols)) try: instr[-1].header.update('EXTNAME','TRIALS','Extension name') except: status = 1 try: instr[-1].header.update('SEARCHR1',1.0 / fmax,'Search range lower bound (days)') except: status = 1 try: instr[-1].header.update('SEARCHR2',1.0 / fmin,'Search range upper bound (days)') except: status = 1 try: instr[-1].header.update('NFREQ',nfreq,'Number of frequency bins') except: status = 1 try: instr[-1].header.update('PERIOD',p,'Best period (days)') except: status = 1 try: instr[-1].header.update('PERIODE',perr,'1-sigma period error (days)') except: status = 1 # instr[-1].header.update('DETNCONF',powave/powstdev,'Detection significance (sigma)') try: instr[-1].header.update('CONFIDR1',1.0 / f2,'Trial confidence lower bound (days)') except: status = 1 try: instr[-1].header.update('CONFIDR2',1.0 / f1,'Trial confidence upper bound (days)') except: status = 1 try: instr[-1].header.update('NTRIALS',ntrials,'Number of trials') except: status = 1 instr.writeto(outfile) # close input file if status == 0: status = kepio.closefits(instr,logfile,verbose) ## end time if (status == 0): message = 'KEPTRAIL completed at' else: message = '\nKEPTRIAL aborted at' kepmsg.clock(message,logfile,verbose)
def kepwindow(infile,outfile,fcol,fmax,nfreq,plot,clobber,verbose,logfile,status, cmdLine=False): ## startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 ## log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile,hashline,verbose) call = 'KEPWINDOW -- ' call += 'infile='+infile+' ' call += 'outfile='+outfile+' ' call += 'fcol='+fcol+' ' call += 'fmax='+str(fmax)+' ' call += 'nfreq='+str(nfreq)+' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot='+plotit+ ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber='+overwrite+ ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose='+chatter+' ' call += 'logfile='+logfile kepmsg.log(logfile,call+'\n',verbose) ## start time kepmsg.clock('KEPWINDOW started at',logfile,verbose) ## test log file logfile = kepmsg.test(logfile) ## clobber output file if clobber: status = kepio.clobber(outfile,logfile,verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPWINDOW: ' + outfile + ' exists. Use clobber=yes' status = kepmsg.err(logfile,message,verbose) ## open input file if status == 0: instr, status = kepio.openfits(infile,'readonly',logfile,verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys(instr,infile,logfile,verbose,status) if status == 0: try: work = instr[0].header['FILEVER'] cadenom = 1.0 except: cadenom = cadence ## fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr,file,logfile,verbose) ## read table columns if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile,instr[1].data,'time',logfile,verbose) signal, status = kepio.readfitscol(infile,instr[1].data,fcol,logfile,verbose) ## remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] ## reset signal data to zero if status == 0: signal = ones(len(outcols[1])) ## frequency steps if status == 0: deltaf = fmax / nfreq ## loop through frequency steps; determine FT power if status == 0: fr, power = kepfourier.ft(barytime,signal,0.0,fmax,deltaf,True) power[0] = 1.0 ## mirror window function around ordinate if status == 0: work1 = []; work2 = [] for i in range(len(fr)-1, 0, -1): work1.append(-fr[i]) work2.append(power[i]) for i in range(len(fr)): work1.append(fr[i]) work2.append(power[i]) fr = array(work1,dtype='float32') power = array(work2,dtype='float32') ## write output file if status == 0: col1 = Column(name='FREQUENCY',format='E',unit='days',array=fr) col2 = Column(name='POWER',format='E',array=power) cols = ColDefs([col1,col2]) instr.append(new_table(cols)) instr[-1].header.update('EXTNAME','WINDOW FUNCTION','extension name') ## comment keyword in output file if status == 0: status = kepkey.comment(call,instr[0],outfile,logfile,verbose) instr.writeto(outfile) ## close input file if status == 0: status = kepio.closefits(instr,logfile,verbose) ## data limits if status == 0: nrm = len(str(int(power.max())))-1 power = power / 10**nrm ylab = 'Power (x10$^%d$)' % nrm xmin = fr.min() xmax = fr.max() ymin = power.min() ymax = power.max() xr = xmax - xmin yr = ymax - ymin fr = insert(fr,[0],fr[0]) fr = append(fr,fr[-1]) power = insert(power,[0],0.0) power = append(power,0.0) ## plot power spectrum if status == 0 and plot: try: params = {'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight' : 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize} rcParams.update(params) except: print('ERROR -- KEPWINDOW: install latex for scientific plotting') status = 1 if status == 0 and plot: pylab.figure(1,figsize=[xsize,ysize]) pylab.axes([0.06,0.113,0.93,0.86]) pylab.plot(fr,power,color=lcolor,linestyle='-',linewidth=lwidth) fill(fr,power,color=fcolor,linewidth=0.0,alpha=falpha) xlim(xmin-xr*0.01,xmax+xr*0.01) if ymin-yr*0.01 <= 0.0: ylim(1.0e-10,ymax+yr*0.01) else: ylim(ymin-yr*0.01,ymax+yr*0.01) xlabel(r'Frequency (d$^{-1}$)', {'color' : 'k'}) ylabel('Power', {'color' : 'k'}) # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() ## end time if (status == 0): message = 'KEPWINDOW completed at' else: message = '\nKEPWINDOW aborted at' kepmsg.clock(message,logfile,verbose)
def kepft(infile,outfile,fcol,pmin,pmax,nfreq,plot,clobber,verbose,logfile,status, cmdLine=False): ## startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 18 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 ## log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile,hashline,verbose) call = 'KEPFT -- ' call += 'infile='+infile+' ' call += 'outfile='+outfile+' ' call += 'fcol='+fcol+' ' call += 'pmin='+str(pmin)+' ' call += 'pmax='+str(pmax)+' ' call += 'nfreq='+str(nfreq)+' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot='+plotit+ ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber='+overwrite+ ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose='+chatter+' ' call += 'logfile='+logfile kepmsg.log(logfile,call+'\n',verbose) ## start time kepmsg.clock('Start time is',logfile,verbose) ## test log file logfile = kepmsg.test(logfile) ## clobber output file if clobber: status = kepio.clobber(outfile,logfile,verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPFT: ' + outfile + ' exists. Use --clobber' status = kepmsg.err(logfile,message,verbose) ## open input file if status == 0: instr, status = kepio.openfits(infile,'readonly',logfile,verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys(instr,infile,logfile,verbose,status) ## fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr,file,logfile,verbose) ## read table columns if status == 0: try: barytime = instr[1].data.field('barytime') except: barytime, status = kepio.readfitscol(infile,instr[1].data,'time',logfile,verbose) signal, status = kepio.readfitscol(infile,instr[1].data,fcol,logfile,verbose) if status == 0: barytime = barytime + bjdref ## remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] - median(outcols[1]) ## period to frequency conversion fmin = 1.0 / pmax fmax = 1.0 / pmin deltaf = (fmax - fmin) / nfreq ## loop through frequency steps; determine FT power if status == 0: fr, power = kepfourier.ft(barytime,signal,fmin,fmax,deltaf,True) ## write output file if status == 0: col1 = Column(name='FREQUENCY',format='E',unit='1/day',array=fr) col2 = Column(name='POWER',format='E',array=power) cols = ColDefs([col1,col2]) instr.append(new_table(cols)) instr[-1].header.update('EXTNAME','POWER SPECTRUM','extension name') instr.writeto(outfile) ## history keyword in output file if status == 0: status = kepkey.history(call,instr[0],outfile,logfile,verbose) ## close input file if status == 0: status = kepio.closefits(instr,logfile,verbose) ## data limits if status == 0: nrm = int(log10(power.max())) power = power / 10**nrm ylab = 'Power (x10$^{%d}$)' % nrm xmin = fr.min() xmax = fr.max() ymin = power.min() ymax = power.max() xr = xmax - xmin yr = ymax - ymin fr = insert(fr,[0],fr[0]) fr = append(fr,fr[-1]) power = insert(power,[0],0.0) power = append(power,0.0) ## plot power spectrum if status == 0 and plot: try: params = {'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight' : 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize} rcParams.update(params) except: print 'ERROR -- KEPFT: install latex for scientific plotting' status = 1 if status == 0 and plot: pylab.figure(1,figsize=[xsize,ysize]) pylab.clf() pylab.axes([0.06,0.113,0.93,0.86]) pylab.plot(fr,power,color=lcolor,linestyle='-',linewidth=lwidth) fill(fr,power,color=fcolor,linewidth=0.0,alpha=falpha) xlim(xmin-xr*0.01,xmax+xr*0.01) if ymin-yr*0.01 <= 0.0: ylim(1.0e-10,ymax+yr*0.01) else: ylim(ymin-yr*0.01,ymax+yr*0.01) xlabel(r'Frequency (d$^{-1}$)', {'color' : 'k'}) ylabel(ylab, {'color' : 'k'}) grid() # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() ## end time if (status == 0): message = 'KEPFT completed at' else: message = '\nKEPFT aborted at' kepmsg.clock(message,logfile,verbose)
def kepdynamic(infile, outfile, fcol, pmin, pmax, nfreq, deltat, nslice, plot, plotscale, cmap, clobber, verbose, logfile, status, cmdLine=False): # startup parameters status = 0 labelsize = 24 ticksize = 16 xsize = 12 ysize = 6 lcolor = '#0000ff' lwidth = 1.0 fcolor = '#ffff00' falpha = 0.2 numpy.seterr(all="ignore") # log the call hashline = '----------------------------------------------------------------------------' kepmsg.log(logfile, hashline, verbose) call = 'KEPDYNAMIC -- ' call += 'infile=' + infile + ' ' call += 'outfile=' + outfile + ' ' call += 'fcol=' + fcol + ' ' call += 'pmin=' + str(pmin) + ' ' call += 'pmax=' + str(pmax) + ' ' call += 'nfreq=' + str(nfreq) + ' ' call += 'deltat=' + str(deltat) + ' ' call += 'nslice=' + str(nslice) + ' ' plotit = 'n' if (plot): plotit = 'y' call += 'plot=' + plotit + ' ' call += 'plotscale=' + plotscale + ' ' call += 'cmap=' + str(cmap) + ' ' overwrite = 'n' if (clobber): overwrite = 'y' call += 'clobber=' + overwrite + ' ' chatter = 'n' if (verbose): chatter = 'y' call += 'verbose=' + chatter + ' ' call += 'logfile=' + logfile kepmsg.log(logfile, call + '\n', verbose) # start time kepmsg.clock('Start time is', logfile, verbose) # test log file logfile = kepmsg.test(logfile) # error checking if status == 0 and pmin >= pmax: message = 'ERROR -- KEPDYNAMIC: PMIN must be less than PMAX' status = kepmsg.err(logfile, message, verbose) # clobber output file if clobber: status = kepio.clobber(outfile, logfile, verbose) if kepio.fileexists(outfile): message = 'ERROR -- KEPDYNAMIC: ' + outfile + ' exists. Use clobber' status = kepmsg.err(logfile, message, verbose) # plot color map if status == 0 and cmap == 'browse': status = keplab.cmap_plot() # open input file if status == 0: instr, status = kepio.openfits(infile, 'readonly', logfile, verbose) if status == 0: tstart, tstop, bjdref, cadence, status = kepio.timekeys( instr, infile, logfile, verbose, status) if status == 0: try: work = instr[0].header['FILEVER'] cadenom = 1.0 except: cadenom = cadence # fudge non-compliant FITS keywords with no values if status == 0: instr = kepkey.emptykeys(instr, file, logfile, verbose) # read table columns if status == 0: barytime, status = kepio.readtimecol(infile, instr[1].data, logfile, verbose) if status == 0: signal, status = kepio.readfitscol(infile, instr[1].data, fcol, logfile, verbose) if status == 0: barytime = barytime + bjdref signal = signal / cadenom # remove infinite data from time series if status == 0: incols = [barytime, signal] outcols = kepstat.removeinfinlc(signal, incols) barytime = outcols[0] signal = outcols[1] # period to frequency conversion if status == 0: fmin = 1.0 / pmax fmax = 1.0 / pmin deltaf = (fmax - fmin) / nfreq # determine bounds of time slices if status == 0: t1 = [] t2 = [] dt = barytime[-1] - barytime[0] dt -= deltat if dt < 0: message = 'ERROR -- KEPDYNAMIC: time slices are larger than data range' status = kepmsg.err(logfile, message, verbose) ds = dt / (nslice - 1) for i in range(nslice): t1.append(barytime[0] + ds * float(i)) t2.append(barytime[0] + deltat + ds * float(i)) # loop through time slices if status == 0: dynam = [] for i in range(nslice): x = [] y = [] for j in range(len(barytime)): if (barytime[j] >= t1[i] and barytime[j] <= t2[i]): x.append(barytime[j]) y.append(signal[j]) x = array(x, dtype='float64') y = array(y, dtype='float32') y = y - median(y) # determine FT power fr, power = kepfourier.ft(x, y, fmin, fmax, deltaf, False) for j in range(len(power)): dynam.append(power[j]) print('Timeslice: %.4f Pmax: %.2E' % ((t2[i] + t1[i]) / 2, power.max())) # define shape of results array dynam = array(dynam, dtype='float64') dynam.shape = len(t1), len(power) # write output file if status == 0: instr.append(ImageHDU()) instr[-1].data = dynam.transpose() instr[-1].header.update('EXTNAME', 'DYNAMIC FT', 'extension name') instr[-1].header.update('WCSAXES', 2, 'number of WCS axes') instr[-1].header.update('CRPIX1', 0.5, 'reference pixel along axis 1') instr[-1].header.update('CRPIX2', 0.5, 'reference pixel along axis 2') instr[-1].header.update('CRVAL1', t1[0], 'time at reference pixel (BJD)') instr[-1].header.update('CRVAL2', fmin, 'frequency at reference pixel (1/day)') instr[-1].header.update('CDELT1', (barytime[-1] - barytime[0]) / nslice, 'pixel scale in dimension 1 (days)') instr[-1].header.update('CDELT2', deltaf, 'pixel scale in dimension 2 (1/day)') instr[-1].header.update('CTYPE1', 'BJD', 'data type of dimension 1') instr[-1].header.update('CTYPE2', 'FREQUENCY', 'data type of dimension 2') instr.writeto(outfile) # history keyword in output file if status == 0: status = kepkey.history(call, instr[0], outfile, logfile, verbose) # close input file if status == 0: status = kepio.closefits(instr, logfile, verbose) # clean up x-axis unit if status == 0: time0 = float(int(barytime[0] / 100) * 100.0) barytime = barytime - time0 xlab = 'BJD $-$ %d' % time0 # image intensity min and max if status == 0: if 'rithmic' in plotscale: dynam = numpy.log10(dynam) elif 'sq' in plotscale: dynam = numpy.sqrt(dynam) elif 'logoflog' in plotscale: dynam = numpy.log10(numpy.abs(numpy.log10(dynam))) # dynam = -dynam nstat = 2 pixels = [] for i in range(dynam.shape[0]): for j in range(dynam.shape[1]): pixels.append(dynam[i, j]) pixels = array(sort(pixels), dtype=float32) if int(float(len(pixels)) * 0.1 + 0.5) > nstat: nstat = int(float(len(pixels)) * 0.1 + 0.5) zmin = median(pixels[:nstat]) zmax = median(pixels[-1:]) if isnan(zmax): zmax = median(pixels[-nstat / 2:]) if isnan(zmax): zmax = numpy.nanmax(pixels) # plot power spectrum if status == 0 and plot: params = { 'backend': 'png', 'axes.linewidth': 2.5, 'axes.labelsize': labelsize, 'axes.font': 'sans-serif', 'axes.fontweight': 'bold', 'text.fontsize': 12, 'legend.fontsize': 12, 'xtick.labelsize': ticksize, 'ytick.labelsize': ticksize } rcParams.update(params) pylab.figure(1, figsize=[xsize, ysize]) pylab.clf() pylab.axes([0.08, 0.113, 0.91, 0.86]) dynam = dynam.transpose() pylab.imshow(dynam, origin='lower', aspect='auto', cmap=cmap, vmin=zmin, vmax=zmax, extent=[barytime[0], barytime[-1], fmin, fmax], interpolation='bilinear') xlabel(xlab, {'color': 'k'}) ylabel(r'Frequency (d$^{-1}$)', {'color': 'k'}) grid() pylab.savefig(re.sub('\.\S+', '.png', outfile), dpi=100) # render plot if cmdLine: pylab.show() else: pylab.ion() pylab.plot([]) pylab.ioff() return status ## end time if (status == 0): message = 'KEPDYNAMIC completed at' else: message = '\nKEPDYNAMIC aborted at' kepmsg.clock(message, logfile, verbose)