예제 #1
0
def test_combine_ins():
    obs = "1061313128_99bl_1pol_half_time"
    testfile = os.path.join(DATA_PATH, f"{obs}.uvfits")

    ss = SS()
    ss.read(testfile, diff=True)

    whole_ins = INS(ss)

    all_bls = ss.get_antpairs()
    first_50 = all_bls[:50]
    remaining = all_bls[50:]

    ss_first_50 = ss.select(bls=first_50, inplace=False)
    ss_remaining = ss.select(bls=remaining, inplace=False)

    ins_first_50 = INS(ss_first_50)
    ins_remaining = INS(ss_remaining)

    test_ins = util.combine_ins(ins_first_50, ins_remaining)

    # Metric arrays are off by 10^-14 (1 part in 10^16)
    for attr in whole_ins._data_params:
        assert np.all(
            np.isclose(getattr(whole_ins, attr), getattr(
                test_ins, attr))), f"{attr} is not equal between the two INS"

    util.combine_ins(ins_first_50, ins_remaining, inplace=True)

    # Check inplace
    for attr in whole_ins._data_params:
        assert np.all(
            np.isclose(getattr(whole_ins, attr), getattr(
                ins_first_50,
                attr))), f"{attr} is not equal between the two INS"
예제 #2
0
def test_combine_ins_errors():
    obs = "1061313128_99bl_1pol_half_time"
    testfile = os.path.join(DATA_PATH, f"{obs}.uvfits")
    autofile = os.path.join(DATA_PATH, "1061312640_autos.uvfits")
    mixfile = os.path.join(DATA_PATH, "1061312640_mix.uvfits")

    ss = SS()
    ss.read(testfile, diff=True)

    all_bls = ss.get_antpairs()
    first_50 = all_bls[:50]
    remaining = all_bls[50:]

    ss_first_50 = ss.select(bls=first_50, inplace=False)
    ss_remaining = ss.select(bls=remaining, inplace=False)

    ins_first_50 = INS(ss_first_50, use_integration_weights=True)
    ins_remaining = INS(ss_remaining, use_integration_weights=True)

    ins_sig_arr = np.ma.copy(ins_first_50.sig_array)

    ins_first_50.sig_array = ins_first_50.sig_array + 1
    with pytest.warns(UserWarning, match="sig_array attribute"):
        new_ins = util.combine_ins(ins_first_50, ins_remaining)

    ss_autos = SS()
    ss_autos.read(autofile, diff=True)
    ss_cross = SS()
    ss_cross.read(mixfile, diff=True)

    auto_ins = INS(ss_autos, spectrum_type="auto")
    cross_ins = INS(ss_cross, spectrum_type="cross")

    with pytest.raises(ValueError, match="ins1 is of type"):
        new_ins = util.combine_ins(auto_ins, cross_ins)

    ins_remaining.polarization_array = np.array([-6])
    with pytest.raises(ValueError,
                       match="The spectra do not have the same pols"):
        new_ins = util.combine_ins(ins_first_50, ins_remaining)

    ins_remaining.freq_array = ins_remaining.freq_array + 1
    with pytest.raises(ValueError,
                       match="The spectra do not have the same frequencies"):
        new_ins = util.combine_ins(ins_first_50, ins_remaining)

    ins_remaining.time_array = ins_remaining.time_array + 1
    with pytest.raises(ValueError,
                       match="The spectra do not have matching time"):
        new_ins = util.combine_ins(ins_first_50, ins_remaining)
예제 #3
0
uvf = UVFlag(uvd, waterfall=True, mode='flag')
del uvd

# Make the SS object
ss = SS()
if args.num_baselines > 0:
    ss.read(args.filename, bls=bls[:args.num_baselines], diff=args.no_diff)
    ins = INS(ss)
    Nbls = len(bls)
    for slice_ind in range(args.num_baselines, Nbls, args.num_baselines):
        ss = SS()
        ss.read(args.filename,
                bls=bls[slice_ind:slice_ind + args.num_baselines],
                diff=args.no_diff)
        new_ins = INS(ss)
        ins = util.combine_ins(ins, new_ins)
else:
    ss.read(args.filename, antenna_nums=use_ants, diff=args.no_diff)
    ss.select(ant_str='cross')
    ins = INS(ss)

# Clear some memory??
del ss

# Write the raw data and z-scores to h5 format
ins.write(args.prefix, sep='.', clobber=args.clobber)
ins.write(args.prefix, output_type='z_score', sep='.', clobber=args.clobber)

# Flag FM radio
where_FM = np.where(
    np.logical_and(ins.freq_array > 87.5e6, ins.freq_array < 108e6))