def test_write(): obs = '1061313128_99bl_1pol_half_time' testfile = os.path.join(DATA_PATH, '%s.uvfits' % obs) file_type = 'uvfits' outfile = os.path.join(DATA_PATH, 'test_write.uvfits') ss = SS() ss.read(testfile) custom = np.zeros_like(ss.data_array.mask) custom[:ss.Nbls] = 1 # Flags the first time and no others ss.apply_flags(flag_choice='custom', custom=custom) # Write this out without combining flags ss.write(outfile, 'uvfits', filename_in=testfile, combine=False) # Check if the flags propagated correctly UV = UVData() UV.read(outfile) assert np.all( UV.flag_array[:2 * UV.Nbls]), "Not all expected flags were propagated" assert not np.any( UV.flag_array[2 * UV.Nbls:]), "More flags were made than expected" os.remove(outfile)
def test_write(): obs = '1061313128_99bl_1pol_half_time' testfile = os.path.join(DATA_PATH, f'{obs}.uvfits') file_type = 'uvfits' outfile = os.path.join(DATA_PATH, 'test_write.uvfits') ss = SS() ss.read(testfile, diff=True) blt_inds = np.where(ss.time_array == np.unique(ss.time_array)[10]) custom = np.zeros_like(ss.data_array.mask) custom[blt_inds, :, 64:128, :] = 1 # Flags the first time and no others ss.apply_flags(flag_choice='custom', custom=custom) # Write this out without combining flags, will issue a warning with pytest.warns( UserWarning, match= "Some nsamples are 0, which will result in failure to propagate flags. Setting nsample to default values where 0." ): ss.write(outfile, 'uvfits', filename_in=testfile, combine=False) # Check if the flags propagated correctly UV = UVData() UV.read(outfile) blt_inds = np.isin(UV.time_array, np.unique(UV.time_array)[10:12]) assert np.all( UV.flag_array[blt_inds, :, 64:128, :]), "Not all expected flags were propagated" new_blt_inds = np.logical_not( np.isin(UV.time_array, np.unique(UV.time_array)[10:12])) assert not np.any( UV.flag_array[new_blt_inds, :, 64:128, :]), "More flags were made than expected" os.remove(outfile) # Test bad read. bad_uv_filepath = os.path.join(DATA_PATH, '1061312640_mix.uvfits') bad_uv = UVData() bad_uv.read(bad_uv_filepath) with pytest.raises( ValueError, match="UVData and SS objects were found to be incompatible."): ss.write(outfile, 'uvfits', bad_uv)
time.strftime("%H:%M:%S")) sys.stdout.write("Beginning flagging at %s" % time.strftime("%H:%M:%S")) auto_bls = ss.UV.ant_1_array[:ss.UV.Nbls] == ss.UV.ant_2_array[:ss.UV.Nbls] custom = np.copy(ss.UV.flag_array) custom[:, auto_bls] = 1 custom[-4:-1] = 1 ss.apply_flags(choice='custom', custom=custom) ss.MF_prepare(sig_thresh=5, shape_dict={ 'TV6': [1.74e8, 1.81e8], 'TV7': [1.81e8, 1.88e8], 'TV8': [1.88e8, 1.95e8], 'TV7_broad': [1.79e8, 1.9e8] }) ss.MF.apply_match_test() ss.apply_flags(choice='INS', INS=ss.INS) sys.stdout.write("Done with flagging at %s" % time.strftime("%H:%M:%S")) sys.stdout.write("Beginning writing at %s" % time.strftime("%H:%M:%S")) ss.write('%s/%s.uvfits' % (args.outpath, args.obs), 'uvfits', inpath=args.inpath, nsample_default=8) sys.stdout.write("Done with writing at %s" % time.strftime("%H:%M:%S"))
vmin=0, vmax=0.03, aspect=ss.UV.Nfreqs / ss.UV.Ntimes) ss.INS.data[:, 0, :82] = np.ma.masked ss.INS.data[:, 0, -21:] = np.ma.masked ss.INS.data_ms = ss.INS.mean_subtract(order=1) ss.MF_prepare(sig_thresh=5, N_thresh=20, shape_dict=shape_dict) ss.MF.apply_match_test(apply_N_thresh=True, order=1) ss.INS.data[ss.INS.data > 0.03] = np.ma.masked ss.INS.data_ms = ss.INS.mean_subtract(order=0) ss.INS.save() cp.MF_plot(ss.MF, ms_vmin=-5, ms_vmax=5, vmin=0, vmax=0.03, aspect=ss.UV.Nfreqs / ss.UV.Ntimes) ss.apply_flags(choice='INS', INS=ss.INS) ss.UV.data_array.mask[:, auto_bls] = True ss.write('%s/%s.HH.uvfits' % (args.outdir, args.obs), 'uvfits', UV=UV1 + UV2, write_kwargs={ 'force_phase': True, 'spoof_nonessential': True })
UV.read(args.inpath, file_type='uvfits') JD = np.unique(UV.time_array)[-2] where = np.where(UV.time_array == JD) UV.flag_array[where] = 1 auto_bl = np.where(UV.ant_1_array == UV.ant_2_array) UV.flag_array[auto_bl] = 1 return (UV) UV = UV_construct(args) shape_dict = { 'TV6': [1.74e8, 1.81e8], 'TV7': [1.81e8, 1.88e8], 'TV8': [1.88e8, 1.95e8], 'broad6': [1.72e8, 1.83e8], 'broad7': [1.79e8, 1.9e8], 'broad8': [1.86e8, 1.97e8] } sky_sub = SS(obs=args.obs, UV=UV, outpath=args.outpath, flag_choice='original') sky_sub.INS_prepare() sky_sub.MF_prepare(sig_thresh=5, shape_dict=shape_dict, N_thresh=15) sky_sub.MF.apply_match_test(apply_N_thresh=True) sky_sub.apply_flags(choice='INS', INS=sky_sub.INS) sky_sub.write('%s/%s.uvfits' % (args.outpath, args.obs), 'uvfits', UV=UV_construct(args))
indir = args.infile[:args.infile.rfind('/')] if indir == args.outdir: raise ValueError("indir and outdir are the same") ss = SS() ss.read(args.infile, flag_choice='original') ins = INS(ss) ins.metric_array[-5:] = np.ma.masked ins.metric_ms = ins.mean_subtract() shape_dict = { 'TV4': [1.74e8, 1.81e8], 'TV5': [1.81e8, 1.88e8], 'TV6': [1.88e8, 1.95e8], 'broad6': [1.72e8, 1.83e8], 'broad7': [1.79e8, 1.9e8], 'broad8': [1.86e8, 1.98e8] } mf = MF(ins.freq_array, 5, shape_dict=shape_dict, N_samp_thresh=25) mf.apply_match_test(ins, apply_samp_thresh=True) cp.INS_plot(ins, '%s/%s' % (args.outdir, args.obsid)) ss.apply_flags(flag_choice='INS', INS=ins) ss.write('%s/%s.uvfits' % (args.outdir, args.obsid), 'uvfits', nsample_default=16)