Ejemplo n.º 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)
Ejemplo n.º 2
0
def test_make_ticks():

    # Make up a frequency array and some frequencies to tick
    freq_array = np.arange(1e8, 1.1e8, 1e6)
    freqs = np.arange(1e8, 1.1e8, 2e6)

    ticks, labels = util.make_ticks_labels(freqs, freq_array, sig_fig=2)

    test_ticks = (np.arange(len(freq_array))[::2]).tolist()
    test_labels = ['100.00', '102.00', '104.00', '106.00', '108.00']

    assert np.all(ticks == test_ticks), "The ticks are not equal"
    assert np.all(labels == test_labels), "The labels are not equal"
Ejemplo n.º 3
0
    raise ValueError("indir and outdir are the same")

if args.rfi_flag:
    if args.insfile is not None:
        ins = INS(args.insfile, mask_file=args.maskfile)
    else:
        ss = SS()
        ss.read(args.uvd, phase_to_pointing_center=True, correct_cable_len=True,
                flag_choice='original', diff=True)

        ins = INS(ss)

        prefix = '%s/%s' % (args.outdir, args.obsid)
        ins.write(prefix)
        freqs = np.arange(1.7e8, 2e8, 5e6)
        xticks, xticklabels = util.make_ticks_labels(freqs, ins.freq_array, sig_fig=0)
        yticks = [0, 20, 40]
        yticklabels = []
        for tick in yticks:
            yticklabels.append(Time(ins.time_array[tick], format='jd').iso[:-4])
        Catalog_Plot.INS_plot(ins, prefix,
                              xticks=xticks, yticks=yticks, xticklabels=xticklabels,
                              yticklabels=yticklabels, data_cmap=cm.plasma,
                              ms_vmin=-5, ms_vmax=5, title=args.obsid,
                              xlabel='Frequency (Mhz)', ylabel='Time (UTC)')
        # Try to save memory - hope for garbage collector
        del ss
        # Set up MF flagging for routine shapes
        shape_dict = {'TV6': [1.74e8, 1.81e8], 'TV7': [1.81e8, 1.88e8],
                      'TV8': [1.88e8, 1.95e8], 'TV9': [1.95e8, 2.02e8]}
        sig_thresh = {shape: 5 for shape in shape_dict}
Ejemplo n.º 4
0
def execbody(ins_filepath):
    slash_ind = ins_filepath.rfind('/')
    obsid = ins_filepath[slash_ind + 1:slash_ind + 11]

    ins = INS(ins_filepath)
    ins.select(times=ins.time_array[3:-3])
    ins.metric_ms = ins.mean_subtract()
    shape_dict = {
        'TV6': [1.74e8, 1.81e8],
        'TV7': [1.81e8, 1.88e8],
        'TV8': [1.88e8, 1.95e8],
        'TV9': [1.95e8, 2.02e8]
    }
    sig_thresh = {shape: 5 for shape in shape_dict}
    sig_thresh['narrow'] = 5
    sig_thresh['streak'] = 8
    mf = MF(ins.freq_array,
            sig_thresh,
            shape_dict=shape_dict,
            N_samp_thresh=len(ins.time_array) // 2)

    ins.metric_array[ins.metric_array == 0] = np.ma.masked
    ins.metric_ms = ins.mean_subtract()
    ins.sig_array = np.ma.copy(ins.metric_ms)

    #write plots if command flagged to do so
    if args.plots:
        prefix = '%s/%s_trimmed_zeromask' % (args.outdir, obsid)
        freqs = np.arange(1.7e8, 2e8, 5e6)
        xticks, xticklabels = util.make_ticks_labels(freqs,
                                                     ins.freq_array,
                                                     sig_fig=0)
        yticks = [0, 20, 40]
        yticklabels = []
        for tick in yticks:
            yticklabels.append(
                Time(ins.time_array[tick], format='jd').iso[:-4])

        Catalog_Plot.INS_plot(ins,
                              prefix,
                              xticks=xticks,
                              yticks=yticks,
                              xticklabels=xticklabels,
                              yticklabels=yticklabels,
                              data_cmap=cm.plasma,
                              ms_vmin=-5,
                              ms_vmax=5,
                              title=obsid,
                              xlabel='Frequency (Mhz)',
                              ylabel='Time (UTC)')
        if args.verbose:
            print("wrote trimmed zeromask plot for " + obsid)

    mf.apply_match_test(ins, apply_samp_thresh=False)
    mf.apply_samp_thresh_test(ins, event_record=True)

    flagged_prefix = '%s/%s_trimmed_zeromask_MF_s8' % (args.outdir, obsid)

    #write data/mask/match/ if command flagged to do so
    if args.write:
        ins.write(flagged_prefix, output_type='data', clobber=True)
        ins.write(flagged_prefix, output_type='mask', clobber=True)
        ins.write(flagged_prefix, output_type='match_events')
        if args.verbose:
            print("wrote data/mask/match files for " + obsid)

    #write plots if command flagged to do so
    if args.plots:
        Catalog_Plot.INS_plot(ins,
                              flagged_prefix,
                              xticks=xticks,
                              yticks=yticks,
                              xticklabels=xticklabels,
                              yticklabels=yticklabels,
                              data_cmap=cm.plasma,
                              ms_vmin=-5,
                              ms_vmax=5,
                              title=obsid,
                              xlabel='Frequency (Mhz)',
                              ylabel='Time (UTC)')

        if args.verbose:
            print("wrote trimmed zeromask (w/ match filter) for " + obsid)

    #a hardcoded csv generator for occ_csv
    if args.gencsv is not None:
        csv = "" + obsid + "," + flagged_prefix + "_SSINS_data.h5," + flagged_prefix + "_SSINS_mask.h5," + flagged_prefix + "_SSINS_match_events.yml\n"
        with open(args.gencsv, "a") as csvfile:
            csvfile.write(csv)
        print("wrote entry for " + obsid)