def INS_read_plot(inpath, outpath, obs, repo_dir):

    if not os.path.exists(outpath):
        os.makedirs(outpath)

    fig_titles = {'All': 'All Baselines', 'Unflagged': 'Post-Flagging'}
    for flag in fig_titles:
        if flag in inpath:
            fig_title = fig_titles[flag]
            flag_slice = flag

    INS = np.load(inpath)
    INS_frac_diff = INS / INS.mean(axis=1) - 1

    fig, ax, pols, xticks, xminors, yminors, xticklabels = \
        plot_lib.four_panel_tf_setup(np.load('%sUseful_Information/MWA_Highband_Freq_Array.npy' %
                                             (repo_dir)))
    fig.suptitle('%s Mean-Subtracted Incoherent Noise Spectrum, %s' %
                 (obs, fig_title))

    for m, pol in enumerate(pols):
        plot_lib.image_plot(fig,
                            ax[m / 2][m % 2],
                            INS_frac_diff[:, 0, :, m],
                            cmap=cm.coolwarm,
                            title=pol,
                            cbar_label='Fraction of Mean',
                            xticks=xticks,
                            xminors=xminors,
                            yminors=yminors,
                            xticklabels=xticklabels,
                            zero_mask=False,
                            mask_color='black')

    fig.savefig('%s%s_INS_frac_diff_%s.png' % (outpath, obs, flag_slice))
    np.save('%s%s_INS_frac_diff_%s.npy' % (outpath, obs, flag_slice),
            INS_frac_diff)

    return (INS, INS_frac_diff)
Exemple #2
0
INS_m = INS_total.mean(axis=0)
frac_diff_m = frac_diff_total.mean(axis=0)

fig_INS, ax_INS, pols, xticks, xminors, yminors, xticklabels = pl.four_panel_tf_setup(freq_array)
fig_fd, ax_fd = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
fig_INS_s, ax_INS_s = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
fig_FD_s, ax_FD_s = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
fig_m, ax_m = plt.subplots(figsize=(14, 8), nrows=2)
fig_mp, ax_mp = plt.subplots(figsize=(14, 8), nrows=2)

avg_title = ['Golden Set INS Averaged Across Obs', 'Golden Set Frac Diff Averaged Across Obs']
ylabels = ['Amplitude (UNCALIB)', 'Fraction']

for m in range(4):
    pl.image_plot(fig_INS, ax_INS[m / 2][m % 2], INS_total[:, 0, :, m],
                  title=pols[m], ylabel='Obs', cbar_label='Amplitude (UNCALIB)',
                  xticks=xticks, xminors=xminors, yminors=yminors,
                  xticklabels=xticklabels, zero_mask=False)
    pl.image_plot(fig_fd, ax_fd[m / 2][m % 2], frac_diff_total[:, 0, :, m],
                  cmap=cm.coolwarm, title=pols[m], xlabel='Frequency (Mhz)',
                  ylabel='Obs', cbar_label='Fraction', xticks=xticks, xminors=xminors,
                  yminors=yminors, xticklabels=xticklabels, zero_mask=False,
                  mask_color='black')
    pl.image_plot(fig_INS_s, ax_INS_s[m / 2][m % 2], INS_stack[:, 0, :, m],
                  title=pols[m], cbar_label='Amplitude (UNCALIB)', xticks=xticks,
                  aspect_ratio=0.1, xminors=xminors, xticklabels=xticklabels,
                  zero_mask=False)
    pl.image_plot(fig_FD_s, ax_FD_s[m / 2][m % 2], FD_stack[:, 0, :, m],
                  cmap=cm.coolwarm, title=pols[m], cbar_label='Fraction',
                  aspect_ratio=0.1, xticks=xticks, xminors=xminors,
                  xticklabels=xticklabels, zero_mask=False, mask_color='black')
        occ_den[sig_thresh - 4] += np.prod(INS.shape)
        if np.count_nonzero(INS.mask) > 0:
            occ_freq_num[sig_thresh - 4, :] += np.count_nonzero(INS.mask,
                                                                axis=(0, 1, 3))
        occ_freq_den[sig_thresh - 4] += INS.shape[0] * INS.shape[3]

        fig, ax, pols, xticks, xminors, yminors, xticklabels = pl.four_panel_tf_setup(
            freq_array[0, :])
        for m in range(4):
            pl.image_plot(fig,
                          ax[m / 2][m % 2],
                          MS[:, 0, :, m],
                          cmap=cm.coolwarm,
                          title=pols[m],
                          xlabel='Frequency (Mhz)',
                          ylabel='Time Pair',
                          cbar_label='Fraction of Mean',
                          xticks=xticks,
                          xminors=xminors,
                          yminors=yminors,
                          xticklabels=xticklabels,
                          zero_mask=False,
                          mask_color='black')

        if not os.path.exists('%s%i/' % (outpath, sig_thresh)):
            os.makedirs('%s%i/' % (outpath, sig_thresh))
        fig.savefig('%s%i/%s_match_filter_MS.png' % (outpath, sig_thresh, obs))
        plt.close(fig)

occ = occ_num / occ_den * 100
occ_freq = (occ_freq_num.transpose() / occ_freq_den).transpose() * 100
np.save('%sRFI_occupancy_sigma.npy' % (outpath), occ)
Exemple #4
0
                test_args = {'ks_test': (MS[:, :, :, m], event),
                             'chisq_test': (MS[:, :, :, m], sig_thresh, event)}
                stat, p, counts, exp, var, bins = getattr(rfiutil, test)(*test_args[test])
                x = bins[:-1] + 0.5 * np.diff(bins)
                pl.error_plot(fig, ax[m / 2][m % 2], x, counts, None, None, label='Measurements', drawstyle='steps-mid')
                pl.error_plot(fig, ax[m / 2][m % 2], x, exp, None, np.sqrt(var), label='Fit', drawstyle='steps-mid',
                              title=pols[m], xlabel='$\sigma$', ylabel='Counts')
                if p < alpha:
                    p_min = p
            if p_min < 1:
                INS[:, event[0], event[1]] = np.ma.masked
            fig.savefig('%s/%s/%s_%s.png' % (outpath, obs, obs, slc))
            plt.close(fig)"""

    fig, ax = plt.subplots(figsize=(14, 8))
    pl.image_plot(fig, ax, INS[:, 0, :], title='%s Match Filtered, %s' % (obs, test),
                  **image_plot_kwargs)
    fig.savefig('%s/%s_INS_Filtered_%s.png' % (outpath, obs, test))
    plt.close(fig)

    """for m, (event, hist) in enumerate(zip(events, hists)):
        N = np.sum(hist[0])
        p = scipy.stats.norm.cdf(hist[1][1:]) - scipy.stats.norm.cdf(hist[1][:-1])
        fit = N * p
        error = np.sqrt(N * p * (1 - p))
        x = hist[1][:-1] + 0.5 * np.diff(hist[1])
        title_tuple = (obs,
                       min(freqs[event[0], event[1]]) * 10 ** (-6),
                       max(freqs[event[0], event[1]]) * 10 ** (-6))

        tag_tuple = (outpath,
                     obs, obs,
Exemple #5
0
import plot_lib
from matplotlib import cm

UV = UVData()
UV.read_uvfits('/Users/mike_e_dubs/MWA/Data/uvfits/1061313128.uvfits')

ind_0 = np.where(UV.nsample_array == 0)
cond = np.logical_and(UV.nsample_array > 0, UV.flag_array).reshape(
    [UV.Ntimes, UV.Nbls, UV.Nspws, UV.Nfreqs, UV.Npols]).sum(axis=1)

fig, ax, pols, xticks, xminors, yminors, xticklabels = plot_lib.four_panel_tf_setup(
    UV.freq_array[0, :])

for m in range(4):
    plot_lib.image_plot(fig,
                        ax[m / 2][m % 2],
                        cond[:, 0, :, m],
                        cmap=cm.plasma,
                        title=pols[m],
                        ylabel='Time (2s)',
                        cbar_label='Nbls',
                        xticks=xticks,
                        xminors=xminors,
                        yminors=yminors,
                        xticklabels=xticklabels,
                        mask_color='white')

fig.savefig(
    '/Users/mike_e_dubs/MWA/Test_Plots/nsample_test/1061313128_nsample_where_flag.png'
)
Exemple #6
0
for obs in obs_list:
    arr = '%s%i_Vis_Avg_Amp_All.npy' % (arr_path, obs)
    INS = np.ma.masked_array(np.load(arr))
    FD_CB = np.zeros(INS.shape)
    for m in range(24):
        INS_CBM = np.array([np.median(INS[:, :, 16 * m:16 * (m + 1), :], axis=2) for k in range(16)]).transpose((1, 2, 0, 3))
        FD_CB[:, :, 16 * m:16 * (m + 1), :] = INS[:, :, 16 * m:16 * (m + 1), :] / INS_CBM - 1

    INS[:, :, centers, :] = np.ma.masked
    INS[:, :, LEdges, :] = np.ma.masked
    INS[:, :, REdges, :] = np.ma.masked

    FD_CB = np.ma.masked_where(np.logical_and(FD_CB > 0.1, ~INS.mask), FD_CB)
    if np.any(FD_CB.mask):
        FD_CB.mask[:, :, centers, :] = False
        FD_CB.mask[:, :, LEdges, :] = False
        FD_CB.mask[:, :, REdges, :] = False
    if obs == 1061312392:
        FD_CB[:, :, centers, :] = np.ma.masked
        FD_CB[:, :, LEdges, :] = np.ma.masked
        FD_CB[:, :, REdges, :] = np.ma.masked

    fig, ax, pols, xticks, xminors, yminors, xticklabels = pl.four_panel_tf_setup(freq_array)
    for m in range(4):
        pl.image_plot(fig, ax[m / 2][m % 2], FD_CB[:, 0, :, m], cmap=cm.coolwarm,
                      title=pols[m], cbar_label='Fraction', xticks=xticks,
                      xminors=xminors, yminors=yminors, xticklabels=xticklabels,
                      zero_mask=False, mask_color='black')
    fig.savefig('%s%i_Narrowband_FD_CB.png' % (outpath, obs))
    plt.close(fig)
Exemple #7
0
xticks = [UV2.Nfreqs * k / 5 for k in range(5)]
xticks.append(UV2.Nfreqs - 1)
xticklabels = [
    '%.1f' % (UV2.freq_array[0, tick] * 10**(-6)) for tick in xticks
]
xminors = AutoMinorLocator(2)

pols = ['XX', 'YY']

for m in range(2):
    plot_lib.image_plot(fig1,
                        ax1[m],
                        fhd_flags[:, 0, :, m],
                        cmap=cm.binary,
                        title=pols[m],
                        aspect_ratio=1.6,
                        ylabel='Time (2s)',
                        cbar_label='Baselines Flagged',
                        xticks=xticks,
                        xticklabels=xticklabels,
                        zero_mask=False,
                        xminors=xminors)
    plot_lib.image_plot(fig2,
                        ax2[m],
                        dirty_flags[:, 0, :, m],
                        cmap=cm.binary,
                        title=pols[m],
                        aspect_ratio=1.6,
                        ylabel='Time (2s)',
                        cbar_label='Baselines Flagged',
                        xticks=xticks,
                        xticklabels=xticklabels,
    fig_exc, ax_exc = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
    fig_ratio, ax_ratio = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
    fig_line, ax_line = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
    fig_scatter, ax_scatter = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
    fig_exc.suptitle('%s Deep Waterfall Excess' % (obslist[n]))
    fig_ratio.suptitle('%s Deep Waterfall Ratio' % (obslist[n]))
    fig_line.suptitle('%s Deep Waterfall Time Average' % (obslist[n]))
    fig_scatter.suptitle('%s Mean vs. Rayleigh Fit Correlation' % (obslist[n]))

    # Do the plotting...
    for m in range(avg.shape[2]):
        plot_lib.image_plot(fig_exc,
                            ax_exc[m / 2][m % 2],
                            excess[:, :, m],
                            title=pol_titles[m],
                            cbar_label='Amplitude (UNCALIB)',
                            xticks=xticks,
                            xticklabels=xticklabels,
                            xminors=xminors,
                            zero_mask=False,
                            cmap=cm.coolwarm)
        plot_lib.image_plot(fig_ratio,
                            ax_ratio[m / 2][m % 2],
                            ratio[:, :, m],
                            title=pol_titles[m],
                            cbar_label='Excess/Average',
                            xticks=xticks,
                            xticklabels=xticklabels,
                            xminors=xminors,
                            zero_mask=False,
                            cmap=cm.coolwarm)
        plot_lib.line_plot(
Exemple #9
0
    fig, ax = plt.subplots(figsize=(14, 8))
    fig_im, ax_im, pols, xticks, xminors, yminors, xticklabels = plot_lib.four_panel_tf_setup(
        freq_arr)
    fig_im.suptitle('%s Streak Flagging Test' % (obs))

    frac_diff = rfiu.streak_detect(frac_diff)

    # plot_lib.line_plot(fig, ax, [edge[:, 0, m] for m in range(edge.shape[2])],
    # title='%s Streak Detection' % (obs), xlabel='Time', ylabel='Gradient',
    # labels=['XX', 'YY', 'XY', 'YX'])
    for m in range(frac_diff.shape[3]):
        plot_lib.image_plot(fig_im,
                            ax_im[m / 2][m % 2],
                            frac_diff[:, 0, :, m],
                            cmap=cm.coolwarm,
                            xlabel='Frequency (Mhz)',
                            ylabel='Time Pair',
                            cbar_label='Amplitude (UNCALIB)',
                            zero_mask=False,
                            mask_color='black',
                            title=pols[m],
                            xticks=xticks,
                            xticklabels=xticklabels,
                            xminors=xminors,
                            yminors=yminors)

    fig_im.savefig('%s%s_streak_detect.png' % (outpath, obs))
    #fig.savefig('%s%s_edge_detect.png' % (outpath, obs))
    plt.close(fig)
    plt.close(fig_im)
Exemple #10
0
    fig_Cal, ax_Cal = plt.subplots(nrows=2, figsize=(14, 8))
    fig_UV, ax_UV = plt.subplots(nrows=2, figsize=(14, 8))

    fig_Cal.suptitle('Calibration Flags %s' % (obs_str[n]))
    fig_UV.suptitle('COTTER Flags %s' % (obs_str[n]))

    pols = ['XX', 'YY']

    for m in range(Cal.flag_array.shape[-1]):
        plot_lib.image_plot(fig_Cal,
                            ax_Cal[m],
                            Cal.flag_array[:, 0, :, 0, m],
                            cmap=cm.binary,
                            title=pols[m],
                            aspect_ratio=0.33,
                            ylabel='Antenna Index',
                            cbar_label='True/False',
                            xticks=xticks,
                            xticklabels=xticklabels,
                            zero_mask=False,
                            xminors=xminors)

        plot_lib.image_plot(fig_UV,
                            ax_UV[m],
                            H[:, :, m],
                            cmap=cm.binary,
                            title=pols[m],
                            aspect_ratio=0.33,
                            ylabel='Antenna Index',
                            cbar_label='True/False Average',
                            xticks=xticks,
outpath = '/Users/mike_e_dubs/MWA/Test_Plots/Match_Test_Samp_Thresh'
C = (4 / np.pi - 1)
pols = ['XX', 'YY', 'XY', 'YX']

for arr in arrs:
    obs = arr[len(indir) + 1:len(indir) + 11]
    for samp_thresh in range(10, 55, 5):
        INS = np.ma.masked_array(np.load(arr))
        Nbls = 8001 * np.ones(INS.shape)
        MS = (INS / INS.mean(axis=0) - 1) * np.sqrt(Nbls / C)
        INS, MS, events, hists = rfiutil.match_filter(INS,
                                                      MS,
                                                      Nbls,
                                                      outpath,
                                                      freq_array,
                                                      sig_thresh=4,
                                                      shape_dict=shape_dict,
                                                      samp_thresh=samp_thresh)
        fig, ax = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
        for i in range(4):
            pl.image_plot(fig,
                          ax[i / 2][i % 2],
                          INS[:, 0, :, i],
                          title=pols[i],
                          cbar_label='Amplitude (UNCALIB)')
        if not os.path.exists('%s/%i' % (outpath, samp_thresh)):
            os.makedirs('%s/%i' % (outpath, samp_thresh))
        fig.savefig('%s/%i/%s_INS_MF_ST%i.png' %
                    (outpath, samp_thresh, obs, samp_thresh))
        plt.close(fig)
Exemple #12
0
 p_hist_sim, _ = np.histogram(p_sim, bins=p_bins)
 hists = [[D_hist, D_hist_sim], [p_hist, p_hist_sim]]
 bins = [D_bins, p_bins]
 fig, ax = plt.subplots(figsize=(14, 8), nrows=2, ncols=2)
 fig.suptitle('%i ks test, $\sigma$=%i' % (obs, sig_thresh))
 kwargs = {'cmap': cm.coolwarm,
           'xlabel': 'Frequency (Mhz)',
           'cbar_label': '$\sigma$',
           'xticks': xticks,
           'xticklabels': xticklabels,
           'xminors': AutoMinorLocator(4),
           'mask_color': 'black'}
 for i in range(4):
     args = (fig, ax[i / 2][i % 2], MS[:, 0, :, i])
     kwargs['title'] = pols[i]
     pl.image_plot(*args, **kwargs)
     fig.savefig('%s/%i_KS_%i.png' % (outpath, obs, sig_thresh))
 plt.close(fig)
 titles = ['KS Statistic Histogram', 'KS P-Value Histogram']
 tags = ['KS_Stat', 'KS_P']
 xlabels = ['$D_n$', 'p']
 for hist, bin, title, tag, xlabel in zip(hists, bins, titles, tags, xlabels):
     fig, ax = plt.subplots(figsize=(14, 8))
     args = (fig, ax, bin, hist)
     kwargs = {'xlog': True,
               'ylog': True,
               'xlabel': xlabel,
               'title': title,
               'legend': True}
     pl.one_d_hist_plot(*args, labels=['Measurements', 'Simulation'], **kwargs)
     fig.savefig('%s/%i_%s_loglog.png' % (outpath, obs, tag))