Exemple #1
0
def make_sig_plots(outdir, dlist, elist, freqs, sig_fig, obslist):

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

    for dpath, epath, obs in zip(dlist, elist, obslist):
        ins = INS(dpath, match_events_file=epath)
        shape_sig_arr = np.ma.copy(ins.metric_ms)
        tcolor_arr = np.ma.zeros(ins.metric_ms.shape)

        Nevent = len(ins.match_events)
        for event_ind, event in enumerate(ins.match_events):
            shape_sig_arr[event[:2]] = event[-1]
            tcolor_arr[event[:2]] = event_ind
        tcolor_arr[tcolor_arr == 0] = np.ma.masked

        fig, ax = plt.subplots(nrows=4, ncols=2, figsize=(16, 9))
        xticks, xticklabels = util.make_ticks_labels(freqs, ins.freq_array, sig_fig=0)
        for pol_ind in range(4):
            plot_lib.image_plot(fig, ax[pol_ind][0], shape_sig_arr[:, :, pol_ind],
                                ylabel='Time (2 s)', xlabel='Frequency (Mhz)',
                                xticks=xticks, xticklabels=xticklabels,
                                cbar_label='Deviation ($\hat{\sigma}$)',
                                vmin=vmin, vmax=vmax, cmap=cm.coolwarm, symlog=True,
                                title=pol_dict[ins.polarization_array[pol_ind]])
            plot_lib.image_plot(fig, ax[pol_ind][1], tcolor_arr[:, :, pol_ind],
                                ylabel='Time (2 s)', xlabel='Frequency (Mhz)',
                                xticks=xticks, xticklabels=xticklabels,
                                cbar_label='Flagging Iteration',
                                cmap=cm.viridis_r, mask_color='white',
                                title=pol_dict[ins.polarization_array[pol_ind]])
        fig.savefig('%s/%s_flag_metaplot.pdf' % (outdir, obs))
        plt.close(fig)
Exemple #2
0
import numpy as np
from SSINS import plot_lib
import matplotlib.pyplot as plt
from pyuvdata import UVData

UV = UVData()
UV.read('/Users/mike_e_dubs/MWA/Data/uvfits/1061313128_SSINS_reflag.uvfits',
        polarizations=[-5])
print(UV.flag_array.shape)
UV.flag_array = UV.flag_array.reshape(
    [UV.Ntimes, UV.Nbls, UV.Nspws, UV.Nfreqs, UV.Npols])
print(UV.flag_array.shape)
BL_Count = np.count_nonzero(UV.flag_array, axis=1)
np.save('/Users/mike_e_dubs/MWA/PS/SSINS_Reflag_BL_Count.npy', BL_Count)

fig, ax = plt.subplots(figsize=(14, 8))
plot_lib.image_plot(fig,
                    ax,
                    BL_Count[:, 0, :, 0],
                    xlabel='Channel #',
                    cbar_label='# Baselines')
fig.savefig('/Users/mike_e_dubs/MWA/PS/SSINS_Reflag_BL_Count.png')
Exemple #3
0
for obs in args.obslist:
    UV = UVData()
    UV.read('%s/%s.uvfits' % (indir, obs),
            file_type='uvfits',
            polarizations=-5)
    UV.select(times=np.unique(UV.time_array)[1:-3], ant_str='cross')
    ss = SS(UV=UV,
            outpath='/Users/mikewilensky/SSINS_Paper',
            obs=obs,
            flag_choice='original')
    ss.INS_prepare()
    fig, ax = plt.subplots(figsize=(16, 9))
    plot_lib.image_plot(fig,
                        ax,
                        ss.INS.data[:, 0, :, 0],
                        aspect='auto',
                        freq_array=UV.freq_array[0],
                        ylabel='Time (2 s)',
                        xlabel='Frequency (Mhz)',
                        cbar_label='Amplitude (UNCALIB)')
    fig_ms, ax_ms = plt.subplots(figsize=(16, 9))
    plot_lib.image_plot(fig_ms,
                        ax_ms,
                        ss.INS.data_ms[:, 0, :, 0],
                        aspect='auto',
                        freq_array=UV.freq_array[0],
                        ylabel='Time (2 s)',
                        xlabel='Frequency (Mhz)',
                        cmap=cm.coolwarm,
                        cbar_label='Deviation ($\hat{\sigma}$)',
                        mask_color='black')
    fig.savefig('%s/%s_INS_original_data.pdf' % (ss.outpath, obs))
           flag_choice='original',
           outpath=outpath)

ins = INS(read_paths=read_paths, obs=obs, outpath=outpath)
aspect = ins.data.shape[2] / ins.data.shape[0]

fig, ax = plt.subplots(figsize=(16, 9), ncols=2)

#plot_lib.image_plot(fig, ax[0], ins.data[:, 0, :, 0], freq_array=ins.freq_array[0],
#cbar_label='Amplitude (UNCALIB)', aspect=aspect, vmax=0.03,
#ylabel='Time (10 s)')
plot_lib.image_plot(fig,
                    ax[0],
                    ins.data_ms[:, 0, :, 0],
                    freq_array=ins.freq_array[0],
                    cmap=cm.coolwarm,
                    aspect=aspect,
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    vmin=-5,
                    vmax=5,
                    ylabel='Time (10 s)')

fig_mf, ax_mf = plt.subplots(figsize=(16, 9), ncols=2)
ins.data.mask[:, 0, :82, 0] = True
ins.data.mask[:, 0, -21:, 0] = True
ins.data_ms = ins.mean_subtract(order=1)
mf = MF(ins,
        sig_thresh=5,
        N_thresh=0,
        shape_dict={
            'TV4': [1.74e8, 1.82e8],
            'TV5': [1.82e8, 1.9e8],
Exemple #5
0
def INS_plot(INS,
             prefix,
             file_ext='pdf',
             xticks=None,
             yticks=None,
             vmin=None,
             vmax=None,
             ms_vmin=None,
             ms_vmax=None,
             data_cmap=None,
             xticklabels=None,
             yticklabels=None,
             aspect='auto',
             cbar_ticks=None,
             ms_cbar_ticks=None,
             cbar_label='',
             xlabel='',
             ylabel='',
             log=False,
             title=None,
             title_x=0.5,
             title_y=.98):
    """Plots an incoherent noise specturm and its mean-subtracted spectrum

    Args:
        INS (INS): The INS whose data is to be plotted. *Required*
        prefix (str): A prefix for the output filepath e.g. "/outdir/plots/obsid" *Required*
        file_ext (str): The type of image file to output
        xticks (sequence): The frequency channel indices to tick in INS waterfall plots.
        yticks (sequence): The time indices to tick in INS waterfall plots.
        vmin (float): The minimum of the colormap for the INS (non-mean-subtracted)
        vmax (float): The maximum of the colormap for the INS (non-mean-subtracted)
        ms_vmin (float): The minimum of the colormap for the mean-subtracted INS
        ms_vmax (float): The maximum of the colormap for the mean-subtracted INS
        data_cmap (colormap): The colormap for the non-mean-subtracted data
        xticklabels (sequence of str): The labels for the frequency ticks
        yticklabels (sequence of str): The labels for the time ticks
        aspect (float or 'auto' or 'equal'): Set the aspect ratio of the waterfall plots.
        title (str): The title to use for the plot.
        title_x (float): x-coordinate of title center (in figure coordinates)
        title_y (float): y-coordinate of title center (in figure coordinates)
    """

    from matplotlib import cm, use
    use('Agg')
    import matplotlib.pyplot as plt

    outdir = prefix[:prefix.rfind('/')]

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

    im_kwargs = {
        'xticks': xticks,
        'yticks': yticks,
        'xticklabels': xticklabels,
        'yticklabels': yticklabels,
        'aspect': aspect
    }

    data_kwargs = [{
        'cbar_label': cbar_label,
        'mask_color': 'white',
        'vmin': vmin,
        'vmax': vmax,
        'cmap': data_cmap,
        'cbar_ticks': cbar_ticks,
        'log': log
    }, {
        'cbar_label': 'Deviation $\hat{\sigma}$',
        'mask_color': 'black',
        'cmap': cm.coolwarm,
        'vmin': ms_vmin,
        'vmax': ms_vmax,
        'cbar_ticks': ms_cbar_ticks,
        'midpoint': True
    }]

    fig, ax = plt.subplots(nrows=INS.metric_array.shape[2],
                           ncols=2,
                           squeeze=False,
                           figsize=(16, 9))
    if title is not None:
        fig.suptitle(title, x=title_x, y=title_y)

    for i, data in enumerate(['array', 'ms']):
        im_kwargs.update(data_kwargs[i])
        for pol_ind in range(INS.metric_array.shape[2]):
            image_plot(fig,
                       ax[pol_ind, i],
                       getattr(INS, 'metric_%s' % data)[:, :, pol_ind],
                       title=pol_dict[INS.polarization_array[pol_ind]],
                       xlabel=xlabel,
                       ylabel=ylabel,
                       **im_kwargs)
    plt.tight_layout(h_pad=1, w_pad=1)
    fig.savefig('%s_SSINS.%s' % (prefix, file_ext))
    plt.close(fig)
Exemple #6
0
titles = ['', ' (Mean-Subtracted)']
cbar_labels = [ins.vis_units, 'Deviation ($\hat{\sigma}$)']
cmaps = [cm.viridis, cm.coolwarm]
for i in range(2):
    fig, ax = plt.subplots(figsize=(16, 9))
    if i:
        vmin = -4
        vmax = 4
    else:
        vmin = None
        vmax = None
    pl.image_plot(fig,
                  ax,
                  getattr(ins, 'data%s' % labels[i])[:, 0, :, 0],
                  xlabel='Frequency (Mhz)',
                  title='MWA Incoherent Noise Spectrum %s' % titles[i],
                  freq_array=ins.freq_array[0],
                  cbar_label=cbar_labels[i],
                  cmap=cmaps[i],
                  aspect=ins.data_ms.shape[2] / ins.data_ms.shape[0])
    fig.savefig('%s/%s_INS%s_master.png' % (outpath, obs, labels[i]))
    plt.close(fig)
for i, event in enumerate(ins.match_events):
    ins.outpath = '%s_%i' % (outpath, i + 1)
    ins.data[tuple(event)] = np.ma.masked
    ins.data_ms = ins.mean_subtract(order=order)
    fig, ax = plt.subplots(figsize=(16, 9))
    pl.image_plot(fig,
                  ax,
                  ins.data_ms[:, 0, :, 0],
                  xlabel='Frequency (Mhz)',
import matplotlib.pyplot as plt
from matplotlib import cm

obs = '1063126480'
indir = '/Users/mike_e_dubs/MWA/INS/Long_Run/All'
outpath = '/Users/mike_e_dubs/General/%s' % obs

read_paths = util.read_paths_construct(indir, None, obs, 'INS')
ins = INS(read_paths=read_paths, obs=obs, outpath=outpath)
mf = MF(ins, sig_thresh=5)

fig, ax = plt.subplots(figsize=(14, 8), nrows=2)
plot_lib.image_plot(fig,
                    ax[0],
                    ins.data_ms[:, 0, :, 0],
                    cmap=cm.coolwarm,
                    freq_array=ins.freq_array[0],
                    title='MWA Soft Breather',
                    cbar_label='Deviation ($\hat{\sigma}$)')

mf.apply_match_test()
plot_lib.image_plot(fig,
                    ax[1],
                    ins.data_ms[:, 0, :, 0],
                    cmap=cm.coolwarm,
                    vmin=-5,
                    vmax=5,
                    freq_array=ins.freq_array[0],
                    title='MWA Soft Breather',
                    mask_color='black',
                    cbar_label='Deviation ($\hat{\sigma}$)')
from matplotlib import cm

obs = '1066742016'
indir = '/Users/mike_e_dubs/MWA/INS/Long_Run/All'
outpath = '/Users/mike_e_dubs/General/1066742016'
if not os.path.exists(outpath):
    os.makedirs(outpath)

read_paths = util.read_paths_construct(indir, None, obs, 'INS')
ins = INS(read_paths=read_paths, outpath=outpath, obs=obs)
fig, ax = plt.subplots(figsize=(56 / 9, 7))
fig_diff, ax_diff = plt.subplots(figsize=(4, 4.5))

plot_lib.image_plot(
    fig,
    ax,
    ins.data[:, 0, :, 0],
    freq_array=ins.freq_array[0],
    aspect=ins.data.shape[2] / ins.data.shape[0],
    cbar_label='Amplitude (arbs)',
)
plot_lib.image_plot(fig_diff,
                    ax_diff,
                    ins.data_ms[:, 0, :, 0],
                    freq_array=ins.freq_array[0],
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    aspect=ins.data.shape[2] / ins.data.shape[0],
                    cmap=cm.coolwarm)
fig.savefig('%s/1066742016_ins.png' % outpath)
fig_diff.savefig('%s/1066742016_ms_nopin.png' % outpath)
Exemple #9
0
ssins = readsav('%s/1061313128_SSINS_cal.sav' % indir)

pols = ['X', 'Y']
funcs = ['absolute', 'angle']
titles = ['Amplitude', 'Phase']
colormaps = [cm.viridis, cm.hsv]
res_colormap = [cm.coolwarm, cm.hsv]

for i in range(2):
    fig, ax = plt.subplots(figsize=(14, 8), nrows=3, ncols=2)
    for k in range(2):
        plot_lib.image_plot(fig,
                            ax[0, k],
                            getattr(np, funcs[i])(noflag.cal.gain[0][k]),
                            xlabel='Channel #',
                            ylabel='Antenna',
                            cbar_label='No Flagging',
                            title='%s %s' % (pols[k], titles[i]),
                            aspect=3,
                            cmap=colormaps[i])
        plot_lib.image_plot(fig,
                            ax[2, k],
                            getattr(np, funcs[i])(noflag.cal.gain[0][k]) -
                            getattr(np, funcs[i])(ssins.cal.gain[0][k]),
                            xlabel='Channel #',
                            ylabel='Antenna',
                            cbar_label='Residual',
                            title='%s %s' % (pols[k], titles[i]),
                            aspect=3,
                            cmap=res_colormap[i])
        plot_lib.image_plot(fig,
Exemple #10
0
inpath = '/Users/mike_e_dubs/MWA/Data/uvfits/1061313128.uvfits'
inpath2 = '/Users/mike_e_dubs/MWA/Data/uvfits/1061313128_noflag.uvfits'
outpath = '/Users/mike_e_dubs/General/1061313128'

if not os.path.exists('%s/arrs/%s_original_INS_data.npym' % (outpath, obs)):
    ss = SS(obs=obs,
            inpath=inpath,
            bad_time_indices=[0, -1, -2, -3],
            read_kwargs={'ant_str': 'cross'},
            flag_choice='original',
            outpath=outpath)
    ss.INS_prepare()
    ss.INS.save()
    ins = ss.INS
else:
    read_paths = util.read_paths_construct(outpath, 'original', obs, 'INS')
    ins = INS(read_paths=read_paths,
              outpath=outpath,
              obs=obs,
              flag_choice='original')
fig, ax = plt.subplots(figsize=(8, 9))
plot_lib.image_plot(fig,
                    ax,
                    ins.data_ms[:, 0, :, 0],
                    cmap=cm.coolwarm,
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    aspect=ins.data.shape[2] / ins.data.shape[0],
                    freq_array=ins.freq_array[0],
                    mask_color='black')
fig.savefig('%s/1061313128_AOFlagger_INS_ms.png' % outpath)
Exemple #11
0
    attr = ['data', 'data_ms']
    cbar_label = ['UNCALIB', 'Deviation ($\hat{\sigma}$)']
    kwargs = [{
        'cmap': cm.viridis,
        'vmax': 0.1
    }, {
        'cmap': cm.coolwarm,
        'vmin': -5,
        'vmax': 5,
        'mask_color': 'black'
    }]
    for i in range(2):
        for k, obj in zip([0, 2], [raw_ins, OR_ins]):
            pl.image_plot(fig,
                          ax[k, i],
                          getattr(obj, attr[i])[:, 0, :, 0],
                          cbar_label=cbar_label[i],
                          freq_array=obj.freq_array[0],
                          **kwargs[i])

    raw_ins.data[:, 0, :82] = np.ma.masked
    raw_ins.data[:, 0, -21:] = np.ma.masked
    mf = MF(raw_ins, sig_thresh=5, shape_dict=shape_dict, N_thresh=20)
    raw_ins.data_ms = raw_ins.mean_subtract(order=1)
    mf.apply_match_test(apply_N_thresh=True, order=1)
    raw_ins.data_ms = raw_ins.mean_subtract()
    for i in range(2):
        pl.image_plot(fig,
                      ax[1, i],
                      getattr(raw_ins, attr[i])[:, 0, :, 0],
                      cbar_label=cbar_label[i],
                      freq_array=raw_ins.freq_array[0],
Exemple #12
0
def INS_plot(INS,
             prefix,
             file_ext='pdf',
             xticks=None,
             yticks=None,
             vmin=None,
             vmax=None,
             ms_vmin=None,
             ms_vmax=None,
             data_cmap=None,
             xticklabels=None,
             yticklabels=None,
             aspect='auto',
             cbar_ticks=None,
             ms_cbar_ticks=None,
             cbar_label='',
             xlabel='',
             ylabel='',
             log=False,
             sig_event_plot=True,
             sig_event_vmax=None,
             sig_event_vmin=None,
             sig_log=True,
             sig_cmap=None,
             symlog=False,
             linthresh=1,
             sample_sig_vmin=None,
             sample_sig_vmax=None,
             title=None,
             title_x=0.5,
             title_y=.98):
    """Plots an incoherent noise specturm and its mean-subtracted spectrum

    Args:
        INS (INS): The INS whose data is to be plotted. *Required*
        prefix (str): A prefix for the output filepath e.g. "/outdir/plots/obsid" *Required*
        file_ext (str): The type of image file to output
        xticks (sequence): The frequency channel indices to tick in INS waterfall plots.
        yticks (sequence): The time indices to tick in INS waterfall plots.
        vmin (float): The minimum of the colormap for the INS (non-mean-subtracted)
        vmax (float): The maximum of the colormap for the INS (non-mean-subtracted)
        ms_vmin (float): The minimum of the colormap for the mean-subtracted INS
        ms_vmax (float): The maximum of the colormap for the mean-subtracted INS
        data_cmap (colormap): The colormap for the non-mean-subtracted data
        xticklabels (sequence of str): The labels for the frequency ticks
        yticklabels (sequence of str): The labels for the time ticks
        aspect (float or 'auto' or 'equal'): Set the aspect ratio of the waterfall plots.
        title (str): The title to use for the plot.
        title_x (float): x-coordinate of title center (in figure coordinates)
        title_y (float): y-coordinate of title center (in figure coordinates)
    """

    from matplotlib import cm, use
    use('Agg')
    import matplotlib.pyplot as plt

    outdir = prefix[:prefix.rfind('/')]

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

    im_kwargs = {
        'xticks': xticks,
        'yticks': yticks,
        'xticklabels': xticklabels,
        'yticklabels': yticklabels,
        'aspect': aspect
    }

    data_kwargs = [{
        'cbar_label': cbar_label,
        'mask_color': 'white',
        'vmin': vmin,
        'vmax': vmax,
        'cmap': data_cmap,
        'cbar_ticks': cbar_ticks,
        'log': log,
        'symlog': symlog,
        'linthresh': linthresh
    }, {
        'cbar_label': 'Deviation ($\hat{\sigma})$',
        'mask_color': 'black',
        'cmap': cm.coolwarm,
        'vmin': ms_vmin,
        'vmax': ms_vmax,
        'cbar_ticks': ms_cbar_ticks,
        'midpoint': True
    }]

    sig_event_kwargs = [{
        'cbar_label': 'Significance ($\hat{\sigma}$)',
        'vmin': sig_event_vmin,
        'vmax': sig_event_vmax,
        'log': sig_log,
        'cmap': sig_cmap,
        'midpoint': False
    }, {
        'cbar_label': 'Event Index',
        'cmap': cm.viridis_r,
        'mask_color': 'white',
        'midpoint': False,
        'log': False,
        'symlog': False
    }, {
        'cbar_label': 'Significance ($\hat{\sigma}$)',
        'vmin': sample_sig_vmin,
        'vmax': sample_sig_vmax,
        'midpoint': True,
        'cmap': cm.coolwarm,
        'mask_color': 'black'
    }]

    fig, ax = plt.subplots(nrows=INS.metric_array.shape[2],
                           ncols=2,
                           squeeze=False,
                           figsize=(16, 9))
    if title is not None:
        fig.suptitle(title, x=title_x, y=title_y)

    for data_ind, data in enumerate(['array', 'ms']):
        im_kwargs.update(data_kwargs[data_ind])
        for pol_ind in range(INS.metric_array.shape[2]):
            image_plot(fig,
                       ax[pol_ind, data_ind],
                       getattr(INS, 'metric_%s' % data)[:, :, pol_ind],
                       title=pol_dict[INS.polarization_array[pol_ind]],
                       xlabel=xlabel,
                       ylabel=ylabel,
                       **im_kwargs)
    plt.tight_layout(h_pad=1, w_pad=1)
    fig.savefig('%s_SSINS.%s' % (prefix, file_ext))
    plt.close(fig)

    if sig_event_plot:
        if len(INS.match_events):
            fig, ax = plt.subplots(nrows=INS.metric_array.shape[2],
                                   ncols=3,
                                   squeeze=False,
                                   figsize=(16, 9))
            event_sig_arr = np.zeros(INS.metric_array.shape)
            event_ind_arr = np.ma.zeros(INS.metric_array.shape, dtype=int)

            # iterate backwards so that the most significant events are shown at the topmost layer
            for event_ind in range(len(INS.match_events) - 1, -1, -1):
                event_sig_arr[INS.match_events[event_ind]
                              [:2]] = INS.match_events[event_ind][-1]
                event_ind_arr[INS.match_events[event_ind][:2]] = event_ind
            event_sig_arr_wh_0 = np.where(event_sig_arr == 0)
            event_sig_arr[event_sig_arr_wh_0] = INS.metric_ms[
                event_sig_arr_wh_0]
            event_ind_arr[event_sig_arr_wh_0] = np.ma.masked

            for data_ind, data in enumerate(
                [event_sig_arr, event_ind_arr, INS.sig_array]):
                im_kwargs.update(sig_event_kwargs[data_ind])
                for pol_ind in range(INS.metric_array.shape[2]):
                    image_plot(fig,
                               ax[pol_ind, data_ind],
                               data[:, :, pol_ind],
                               title=pol_dict[INS.polarization_array[pol_ind]],
                               xlabel=xlabel,
                               ylabel=ylabel,
                               **im_kwargs)
            plt.tight_layout(h_pad=1, w_pad=1)
            fig.savefig('%s_SSINS_sig.%s' % (prefix, file_ext))
            plt.close(fig)
Exemple #13
0
im_kwargs = [{
    'cbar_label': 'Amplitude (UNCALIB)'
}, {
    'vmin': -5,
    'vmax': 5,
    'cmap': cm.coolwarm,
    'mask_color': 'black',
    'cbar_label': 'Deviation ($\hat{\sigma}$)'
}]

data = [ins.data, ins.data_ms]
for i in range(2):
    plot_lib.image_plot(fig1,
                        ax1[i],
                        data[i][:, 0, :, 0],
                        freq_array=ins.freq_array[0],
                        **im_kwargs[i])
if not os.path.exists(outpath):
    os.makedirs(outpath)

shape_dict = {}
ins.data_ms = ins.mean_subtract(order=0)
mf = MF(ins, sig_thresh=5, N_thresh=20, shape_dict=shape_dict)
mf.apply_match_test(apply_N_thresh=True, order=0)
plot_lib.image_plot(fig2,
                    ax2[0],
                    ins.data_ms[:, 0, :, 0],
                    freq_array=ins.freq_array[0],
                    **im_kwargs[1])
Exemple #14
0
from SSINS import INS, util, plot_lib, MF
from matplotlib import cm
import matplotlib.pyplot as plt

obs = '1093972368'
inpath = '/Users/mike_e_dubs/General/1093972368'
outpath = inpath

read_paths = util.read_paths_construct(inpath, None, obs, 'INS')
ins = INS(read_paths=read_paths, outpath=outpath, obs=obs)
aspect = float(ins.data.shape[2]) / ins.data.shape[0]

fig, ax = plt.subplots(figsize=(8, 9))
plot_lib.image_plot(fig,
                    ax,
                    ins.data[:, 0, :, 0],
                    cbar_label='Amplitude (UNCALIB)',
                    freq_array=ins.freq_array[0],
                    aspect=aspect)

fig.savefig('%s/%s_INS.png' % (outpath, obs))

fig_new, ax_new = plt.subplots(figsize=(16, 9), ncols=2)

plot_lib.image_plot(fig,
                    ax_new[0],
                    ins.data_ms[:, 0, :, 0],
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    freq_array=ins.freq_array[0],
                    cmap=cm.coolwarm,
                    aspect=aspect)
ylabel = ['Time (2s)', 'Time Pair']
tag = ['vis', 'diff']
title = ['MWA Single Baseline Visibilities', 'MWA Single Baseline Visibility Differences']
for i in range(UV.Nbls):
    im_dat = UV.data_array[:, i, 0, :, 0]
    for k in range(2):
        title = 'MWA Single Baseline Visibilities'
        if k:
            im_dat = np.diff(im_dat, axis=0)
            title = 'MWA Single Baseline Visibility Differences'
        for label in ['Real', 'Imag']:
            fig, ax = plt.subplots(figsize=(14, 8))
            if getattr(im_dat, label.lower()).size:
                plot_lib.image_plot(fig, ax, getattr(im_dat, label.lower()), ylabel=ylabel[k],
                                    cmap=cm.RdGy_r,
                                    title='%s (%s)' % (title, label),
                                    freq_array=UV.freq_array[0], cbar_label=UV.vis_units)
                fig.savefig('%s/%s_%i_%s_%s.png' % (args.outpath, args.obs, i, tag[k], label))
                plt.close(fig)
            else:
                print('baseline %i was empty for %s attr' % (i, label))
        if im_dat.size:
            fig, ax = plt.subplots(figsize=(14, 8))
            plot_lib.image_plot(fig, ax, np.absolute(im_dat), cbar_label=UV.vis_units,
                                title='%s (Amplitude)' % title,
                                freq_array=UV.freq_array[0], ylabel=ylabel[k])
            fig.savefig('%s/%s_%i_%s_amplitude.png' % (args.outpath, args.obs, i, tag[k]))
            plt.close(fig)
        else:
            print('im_dat was empty for baseline %i', i)
xticklabels_quad = ['%.4f' % ticklabel for ticklabel in xticklabels_quad]
xticklabels_lin = lin_bins[::2]
xticklabels_lin = ['%.2f' % ticklabel for ticklabel in xticklabels_lin]
yticklabels = max_bins[::2]
yticklabels = ['%.2f' % ticklabel for ticklabel in yticklabels]
yticklabels.reverse()

fig_quad, ax_quad = plt.subplots()
fig_lin, ax_lin = plt.subplots()

plot_lib.image_plot(fig_quad,
                    ax_quad,
                    quad_counts,
                    xticks=ticks,
                    xticklabels=xticklabels_quad,
                    yticklabels=yticklabels,
                    yticks=ticks,
                    title='Quad 2d Histogram',
                    ylabel='Peak Max',
                    xlabel='Quad Coefficient',
                    aspect=1)
plot_lib.image_plot(fig_lin,
                    ax_lin,
                    lin_counts,
                    xticks=ticks,
                    yticks=ticks,
                    xticklabels=xticklabels_lin,
                    yticklabels=yticklabels,
                    title='Lin 2d Histogram',
                    ylabel='Peak Max',
                    xlabel='Lin Coefficient',
Exemple #17
0
outdir = '%s_Filtered' % indir
obs = '1061318984'
read_paths = util.read_paths_construct(indir, None, obs, 'INS')

sig_thresh = 5

ins = INS(read_paths=read_paths, obs=obs, outpath=outdir)
mf = MF(ins, sig_thresh=sig_thresh, N_thresh=15)
mf.apply_match_test()
fig, ax = plt.subplots(figsize=(14, 8), nrows=3)
fig.suptitle('Narrowband SSINS')
plot_lib.image_plot(fig,
                    ax[0],
                    ins.data_ms[:, 0, :, 0],
                    cmap=cm.coolwarm,
                    vmin=-5,
                    vmax=5,
                    title='Before N Sample Test',
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    mask_color='black',
                    freq_array=ins.freq_array[0])
ax[0].set_xlabel('')
plot_lib.image_plot(fig,
                    ax[1],
                    ins.data[:, 0, :, 0],
                    cmap=cm.viridis,
                    mask_color='white',
                    cbar_label='Deviation ($\hat{\sigma}$)',
                    freq_array=ins.freq_array[0])
ax[1].set_xlabel('')
ins.data.mask = False
ins.data_ms = ins.mean_subtract()
Exemple #18
0
def INS_plot(INS,
             prefix,
             file_ext='pdf',
             xticks=None,
             yticks=None,
             vmin=None,
             vmax=None,
             ms_vmin=None,
             ms_vmax=None,
             data_cmap=None,
             xticklabels=None,
             yticklabels=None,
             aspect='auto',
             cbar_ticks=None,
             ms_cbar_ticks=None,
             cbar_label='',
             xlabel='',
             ylabel='',
             log=False,
             sig_event_plot=True,
             sig_event_vmax=None,
             sig_event_vmin=None,
             sig_log=True,
             sig_cmap=None,
             symlog=False,
             linthresh=1,
             sample_sig_vmin=None,
             sample_sig_vmax=None,
             title=None,
             title_x=0.5,
             title_y=.98,
             use_extent=True,
             backend=None,
             extent_time_format='jd',
             convert_times=True):
    """Plots an incoherent noise specturm and its mean-subtracted spectrum

    Args:
        INS (INS): The INS whose data is to be plotted. *Required*
        prefix (str): A prefix for the output filepath e.g. "/outdir/plots/obsid" *Required*
        file_ext (str): The type of image file to output
        xticks (sequence): The frequency channel indices to tick in INS waterfall plots.
        yticks (sequence): The time indices to tick in INS waterfall plots.
        vmin (float): The minimum of the colormap for the INS (non-mean-subtracted)
        vmax (float): The maximum of the colormap for the INS (non-mean-subtracted)
        ms_vmin (float): The minimum of the colormap for the mean-subtracted INS
        ms_vmax (float): The maximum of the colormap for the mean-subtracted INS
        data_cmap (colormap): The colormap for the non-mean-subtracted data
        xticklabels (sequence of str): The labels for the frequency ticks
        yticklabels (sequence of str): The labels for the time ticks
        aspect (float or 'auto' or 'equal'): Set the aspect ratio of the waterfall plots.
        title (str): The title to use for the plot.
        title_x (float): x-coordinate of title center (in figure coordinates)
        title_y (float): y-coordinate of title center (in figure coordinates)
        use_extent (bool): Whether to use the INS metadata to make ticks on plots.
            Easier than manual adjustment and sufficient for most cases.
            Will put time in UTC and frequency in MHz.
        backend (str): Which matplotlib backend to use.
        extent_time_format (str): If 'jd', will use the time_array of the object.
            is 'lst', will use the lst_array of the object.
        convert_times (bool): Whether to convert times in extent. Will convert jd into
            UTC and lst into hourangles.
    """

    from matplotlib import cm, use
    if backend is not None:
        use(backend)
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates

    outdir = prefix[:prefix.rfind('/')]

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

    if use_extent:
        # Have to put times in reverse since vertical axis is inverted
        extent = [INS.freq_array[0] / 1e6, INS.freq_array[-1] / 1e6]
        if extent_time_format.lower() == 'jd':
            extent.extend([INS.time_array[-1], INS.time_array[0]])
        elif extent_time_format.lower() == 'lst':
            extent.extend([INS.lst_array[-1], INS.lst_array[0]])
        xlabel = "Frequency (MHz)"
        ylabel = "Time (UTC)"
    else:
        extent = None

    im_kwargs = {
        'xticks': xticks,
        'yticks': yticks,
        'xticklabels': xticklabels,
        'yticklabels': yticklabels,
        'extent': extent,
        'extent_time_format': extent_time_format,
        'convert_times': convert_times,
        'aspect': aspect,
        'xlabel': xlabel,
        'ylabel': ylabel
    }

    data_kwargs = [{
        'cbar_label': cbar_label,
        'mask_color': 'white',
        'vmin': vmin,
        'vmax': vmax,
        'cmap': data_cmap,
        'cbar_ticks': cbar_ticks,
        'log': log,
        'symlog': symlog,
        'linthresh': linthresh
    }, {
        'cbar_label': 'Deviation ($\hat{\sigma})$',
        'mask_color': 'black',
        'cmap': cm.coolwarm,
        'vmin': ms_vmin,
        'vmax': ms_vmax,
        'cbar_ticks': ms_cbar_ticks,
        'midpoint': True
    }]

    sig_event_kwargs = [{
        'cbar_label': 'Significance ($\hat{\sigma}$)',
        'vmin': sig_event_vmin,
        'vmax': sig_event_vmax,
        'log': sig_log,
        'cmap': sig_cmap,
        'midpoint': False
    }, {
        'cbar_label': 'Event Index',
        'cmap': cm.viridis_r,
        'mask_color': 'white',
        'midpoint': False,
        'log': False,
        'symlog': False
    }, {
        'cbar_label': 'Significance ($\hat{\sigma}$)',
        'vmin': sample_sig_vmin,
        'vmax': sample_sig_vmax,
        'midpoint': True,
        'cmap': cm.coolwarm,
        'mask_color': 'black'
    }]

    fig, ax = plt.subplots(nrows=INS.metric_array.shape[2],
                           ncols=2,
                           squeeze=False,
                           figsize=(16, 9))
    if title is not None:
        fig.suptitle(title, x=title_x, y=title_y)

    for data_ind, data in enumerate(['array', 'ms']):
        im_kwargs.update(data_kwargs[data_ind])
        for pol_ind in range(INS.metric_array.shape[2]):
            image_plot(fig,
                       ax[pol_ind, data_ind],
                       getattr(INS, 'metric_%s' % data)[:, :, pol_ind],
                       title=pol_dict[INS.polarization_array[pol_ind]],
                       **im_kwargs)
    plt.tight_layout(h_pad=1, w_pad=1)
    fig.savefig(f'{prefix}_SSINS.{file_ext}')
    plt.close(fig)

    if sig_event_plot:
        if len(INS.match_events):
            fig, ax = plt.subplots(nrows=INS.metric_array.shape[2],
                                   ncols=3,
                                   squeeze=False,
                                   figsize=(16, 9))
            event_sig_arr = np.zeros(INS.metric_array.shape)
            event_ind_arr = np.ma.zeros(INS.metric_array.shape, dtype=int)

            # iterate backwards so that the most significant events are shown at the topmost layer
            for event_ind in range(len(INS.match_events) - 1, -1, -1):
                event_sig_arr[INS.match_events[event_ind]
                              [:2]] = INS.match_events[event_ind][-1]
                event_ind_arr[INS.match_events[event_ind][:2]] = event_ind
            event_sig_arr_wh_0 = np.where(event_sig_arr == 0)
            event_sig_arr[event_sig_arr_wh_0] = INS.metric_ms[
                event_sig_arr_wh_0]
            event_ind_arr[event_sig_arr_wh_0] = np.ma.masked

            for data_ind, data in enumerate(
                [event_sig_arr, event_ind_arr, INS.sig_array]):
                im_kwargs.update(sig_event_kwargs[data_ind])
                for pol_ind in range(INS.metric_array.shape[2]):
                    image_plot(fig,
                               ax[pol_ind, data_ind],
                               data[:, :, pol_ind],
                               title=pol_dict[INS.polarization_array[pol_ind]],
                               **im_kwargs)
            plt.tight_layout(h_pad=1, w_pad=1)
            fig.savefig('%s_SSINS_sig.%s' % (prefix, file_ext))
            plt.close(fig)
Exemple #19
0
beta = 5
W_2_coeff = '/Users/mikewilensky/Repos/MJW-MWA/Useful_Information/pfb2coeff.csv'
W_1 = np.kaiser(n * NT1, beta)
W_2 = np.genfromtxt(W_2_coeff, delimiter=',')
W_2 /= W_2.max()
t = np.arange(n * M * NT1 * NT2)

w = 2 * np.pi * np.arange(n * M) / (n * M)
var = np.arange(n * M)
var[0] = var[1]
var = var**(-2.2)
covar_time = np.zeros([len(var), len(var)], dtype=complex)
print('I initialized the cov matrix')
for i in np.arange(n * M):
    F_L = np.exp(1.0j * w * i)
    if not i % 100:
        print('%i at %s' % (i, time.strftime('%H:%M:%S')))
    for k in np.arange(i + 1):
        F_R = np.exp(1.0j * w * k)
        vec = F_L * var * F_R
        covar_time[i, k] = np.mean(vec, dtype=complex)
        covar_time[k, i] = covar_time[i, k]
fig, ax = plt.subplots(figsize=(14, 8))
plot_lib.image_plot(fig,
                    ax,
                    covar_time,
                    ylabel='Time Index',
                    xlabel='Time Index',
                    cbar_label='Variance')
fig.savefig('/Users/mikewilensky/PFB/Covar_Plot.png')
Exemple #20
0
from SSINS import INS, plot_lib, util
import numpy as np
import matplotlib.pyplot as plt

inpath = '/Users/mike_e_dubs/General/1061318984'
outpath = '%s/figs' % inpath
obs = '1061318984'
read_paths = util.read_paths_construct(inpath, None, obs, 'INS')

ins = INS(read_paths=read_paths, obs=obs, outpath=outpath)

vmax = [None, 150]
fig, ax = plt.subplots(figsize=(14, 8), nrows=2)
fig.suptitle('Narrowband SSINS')

for i in range(2):

    plot_lib.image_plot(fig,
                        ax[i],
                        ins.data[:, 0, :, 0],
                        cbar_label='Amplitude (UNCALIB)',
                        freq_array=ins.freq_array[0],
                        vmax=vmax[i])
fig.savefig('%s/1061318984_None_INS_data_XX.png' % outpath)
Exemple #21
0
    UV = UVData()
    UV.read(inpath, file_type='uvfits', polarizations=-5)
    UV.select(ant_str='cross', times=np.unique(UV.time_array)[1:-3])
    UV.data_array = UV.data_array.reshape(
        [UV.Ntimes, UV.Nbls, UV.Nspws, UV.Nfreqs, UV.Npols])
    data = UV.data_array[:, i, 0, :, 0]

data_diff = np.absolute(np.diff(data, axis=0))
fig, ax = plt.subplots(figsize=(4, 4.5))
fig_diff, ax_diff = plt.subplots(figsize=(4, 4.5))
np.save('%s/Best_Baseline.npy' % outpath, data)
print(data.shape[1] / (data.shape[0] * 10))
print(data.shape)
plot_lib.image_plot(fig,
                    ax,
                    data.real,
                    cmap=cm.RdGy_r,
                    freq_array=freq_array,
                    cbar_label='Amplitude (arbs)',
                    aspect=data.shape[1] / (data.shape[0]),
                    ylabel='Time (2 s)')
plot_lib.image_plot(fig_diff,
                    ax_diff,
                    data_diff,
                    freq_array=freq_array,
                    ylabel='Time (2 s)',
                    cbar_label='Amplitude (arbs)',
                    aspect=data.shape[1] / (data.shape[0]))
fig.savefig('%s/Best_Baseline.png' % outpath)
fig_diff.savefig('%s/Best_Baseline_Diff.png' % outpath)