) args = parser.parse_args() bgcounts = np.recfromtxt(args.bgfile, comments="#", delimiter="\t", dtype=int, names=True) counts = np.recfromtxt(args.file, comments="#", delimiter="\t", names=True, dtype=int) dp = DataPrep(counts, bgcounts, crop=args.crop, fill=args.fill, normalize=False, down_sampling=args.dsfac) dp.gap_stats() if args.lomb_scargle: # calculate the LombScargle Periodigram in the # frequency range of interessest freq_ls = np.linspace(5.0e-7, 5.0e-4, 500) ls = LombScargle(np.float_(dp.position), np.float_(dp.counts), freq_ls) f, pgram = ls() ax = plots.samples(f, pgram, window_title="Lomb-Scargle Periodigram") ax.semilogy() if args.welch: plots.samples(dp.position, dp.counts, window_title="Raw data") # xlim = (0.0, 5e-5) fs = 1.0 / np.diff(dp.position).min() plots.psd( dp.counts, xlim=args.frange, Fs=fs, NFFT=args.nfft, window=mlab.window_none, window_title="Welch Periodigram", )
from matplotlib import mlab from dataprep import LombScargle import plots f1 = 5. f2 = 10. pi2 = 2*np.pi srate = 100 x = np.arange(0, 20, 1./srate) x0 = np.random.permutation(x)[:10*srate] x0 = np.sort(x0) yfunc = lambda t, w1, w2: np.sin(w1*t) + np.sin(w2*t) y = yfunc(x, f1*pi2, f2*pi2) y0 = yfunc(x0, f1, f2) fmin = 1./x.size # = delta_f fmax = srate/2.0 f = np.arange(1, 50, 0.5, dtype=float) lb = LombScargle(x0, y0, f) f, pgram = lb() plots.samples(x0, y0, window_title="Data Series") plots.samples(f, pgram, window_title="Lomb-Scargle Periodigram") plots.psd(y, Fs=srate, NFFT=y.size, window_title="Welch Periodigram", window=mlab.window_none) plots.show()