def quicklook(filename): n = 1 fs, fe = 40, 83 h5 = tb.open_file(filename) T_ant = apply_calibration(h5) f_leda = T_ant['f'] lst_leda = T_ant["lst"] print T_ant.keys() ant_ids = ['252A']#, '254A', '255A', '254B', '255B'] print("Plotting...") T0_all = [] alpha_all = [] lst_trials = np.arange(1, 23, 0.5) for ll in lst_trials: mid = closest(lst_leda, ll) sl = 100 for ant_id in ant_ids: T_flagged = T_ant[ant_id][mid-sl:mid+sl] print T_ant[ant_id].shape T_flagged = rfi_flag(T_flagged, freqs=f_leda) #T_flagged = np.ma.array(T_flagged) d = T_flagged.mean(axis=0) d_std = T_flagged.std(axis=0) print d.shape, f_leda.shape print ant_id, mid, sl f_t, d_t = trim(f_leda, d, fs, fe) f_t, d_std_t = trim(f_leda, d_std, fs, fe) f_t = np.ma.array(f_t) f_t.mask = d_t.mask params = Parameters() params.add('a0', value=1e6) params.add('b', value=-2.49) fc = f_t.compressed() dc = d_t.compressed() dc_errs = d_std_t.compressed() out = minimize(residual, params, args=(model, fc, dc, dc_errs)) print report_fit(out) alpha_all.append(out.params['b'].value) T0_all.append(out.params['a0'].value) print "B: ", out.params['b'].value # print out.values #p = fit_poly(f_leda, d, n=n, print_fit=True) p = model(out.params, fc) print p.shape plt.figure("ANTZ") plt.plot(fc, dc, label=ant_id) #plt.plot(fc, p, label='fit') plt.xlim(fs, fe) plt.minorticks_on() plt.ylim(500, 7000) plt.xlabel("Frequency [MHz]") plt.ylabel("Temperature [K]") plt.legend(frameon=False) plt.text(0.005, 0.005, get_repo_fingerprint(), transform=fig.transFigure, size=8) plt.show() alpha = np.array(alpha_all) print "mean std max min" print np.mean(alpha), np.std(alpha), np.max(alpha), np.min(alpha) plt.plot(lst_trials, alpha, c='#333333') plt.xlabel("Sidereal time [hr]") plt.ylabel("Spectral index $\\alpha$") plt.minorticks_on() plt.ylim(-2.4, -2.27) plt.twinx() plt.plot(lst_trials, T0_all, c='#cc0000', ls='dashed') plt.ylabel("$T_{70}$ [K]", color='#cc0000') plt.tight_layout() plt.minorticks_on() plt.xlim(0, 24) plt.ylim(1500, 3300) plt.text(0.005, 0.005, get_repo_fingerprint(), transform=fig.transFigure, size=8) plt.savefig("figures/spectral-index.pdf") plt.show()
def quicklook(filename): n = 1 fs, fe = 40, 80 h5 = tb.open_file(filename) T_ant = apply_calibration(h5) f_leda = T_ant['f'] print T_ant.keys() ant_ids = ['252A', '254A', '255A'] pol_id = 'y' print("Plotting...") fig, ax = plt.subplots(figsize=(8, 6)) mid = T_ant["252A"].shape[0] / 2 print T_ant['lst'][mid] sl = 250 f0 = np.arange(40, 70) f1 = f0 + 10 f_trials = zip(f0, f1) f_trials.append((40, 80)) alpha_out = [] for fs, fe in f_trials: T_flagged = T_ant[ant_ids[0]][mid - sl:mid + sl] T_flagged = rfi_flag(T_flagged, freqs=f_leda) d = np.median(T_flagged, axis=0) d_errs = np.std(T_flagged, axis=0) f_trim, d = trim(f_leda, d, fs, fe) f_trim = np.ma.array(f_trim) f_trim.mask = d.mask f_trim2, d_errs = trim(f_leda, d_errs, fs, fe) d_errs = np.ma.array(d_errs) d_errs.mask = d.mask params = Parameters() params.add('amp', value=1e8, min=1e4, max=1e10) params.add('alpha', value=-2.5, min=-4, max=-1) fc = f_trim.compressed() dc = d.compressed() dc_errs = d_errs.compressed() print dc.shape, dc_errs.shape out = minimize(residual, params, args=(model, fc, dc, dc_errs)) print report_fit(out) # print out.values #p = fit_poly(f_leda, d, n=n, print_fit=True) p = model(out.params, fc) alpha_out.append(out.params['alpha'].value) """ plt.plot(fc, dc, label=ant_ids[0]) plt.plot(fc, p, label='fit') plt.xlim(fs, fe) plt.minorticks_on() plt.ylim(500, 7000) ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator()) ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator()) plt.xlabel("Frequency [MHz]") plt.ylabel("Temperature [K]") plt.legend(frameon=False) plt.show() """ print "HERE", f0.shape, len(alpha_out) plt.plot(f0, alpha_out[:-1]) plt.figure() res = dc - p res_1p = dc - poly_fit(fc, dc, 1, log=True) #res_2p = dc - poly_fit(fc, dc, 2, log=True) res_3p = dc - poly_fit(fc, dc, 3, log=True) #res_4p = dc - poly_fit(fc, dc, 4, log=True) res_5p = dc - poly_fit(fc, dc, 5, log=True) res_7p = dc - poly_fit(fc, dc, 7, log=True) #res_3p3f = res_3p - fourier_fit(res_3p, 0, 3) #plt.plot(fc, res) plt.plot(rebin(fc, 8), rebin(res_1p, 8)) plt.plot(rebin(fc, 8), rebin(res_3p, 8)) plt.plot(rebin(fc, 8), rebin(res_5p, 8)) plt.plot(rebin(fc, 8), rebin(res_7p, 8)) #plt.plot(rebin(fc, 8), rebin(res_5p, 8)) print np.std(rebin(res_1p, 8)) print np.std(rebin(res_3p, 8)) print np.std(rebin(res_5p, 8)) print np.std(rebin(res_7p, 8)) #print np.std(rebin(res_5p, 8)) #plt.plot(rebin(fc, 8), rebin(res_3p3f, 8)) plt.text(0.005, 0.005, get_repo_fingerprint(), transform=fig.transFigure, size=8) plt.show()