def quicklook(filename):
    h5 = tb.open_file(filename)

    T_ant = apply_calibration(h5)
    f_leda = T_ant['f']

    ant_ids = ['252A', '254A', '255A']
    pol_id = 'y'

    print("Plotting...")
    fig, ax = plt.subplots(figsize=(8, 6))

    mid = T_ant["252A"].shape[0] / 2
    sl = 250

    d0 = T_ant[ant_ids[0]][mid - sl:mid + sl]
    d1 = T_ant[ant_ids[1]][mid - sl:mid + sl]
    d2 = T_ant[ant_ids[2]][mid - sl:mid + sl]

    n_chans = 42

    d0 = rfi_flag(d0,
                  thr_f=0.15,
                  thr_t=0.15,
                  rho=1.5,
                  bp_window_f=16,
                  bp_window_t=16,
                  max_frac_f=0.9,
                  max_frac_t=0.9)

    d0 = useful.rebin(d0, 1, n_chans)
    f_leda = useful.rebin(f_leda, n_chans)

    d0_s = np.std(d0, axis=0) / np.sqrt(n_chans)**2
    d0 = np.median(d0, axis=0)

    #d1 = rfi_flag(d1, thr_f=0.15, thr_t=0.15, rho=1.5,
    #         bp_window_f=16, bp_window_t=16,
    #         max_frac_f=0.9, max_frac_t=0.9)
    #d1 = np.median(d1, axis=0)
    #
    #d2 = rfi_flag(d2, thr_f=0.15, thr_t=0.15, rho=1.5,
    #         bp_window_f=16, bp_window_t=16,
    #         max_frac_f=0.9, max_frac_t=0.9)
    #d2 = np.median(d2, axis=0)

    #plt.imshow(d0, cmap='viridis', aspect='auto')
    #plt.colorbar()
    #plt.show()
    #exit()

    return f_leda, d0, d0_s
Exemplo n.º 2
0
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()