def read(filename): """ pyuvdata changed the conjugate convention for uvfits, flip things back here. """ uv = uvd.UVData() uv.read_uvfits(filename) uv.data_array = np.conj(uv.data_array) uv.uvw_array = -uv.uvw_array return uv
if not len(args) == 1: raise IOError('Do not support multiple files.') obsid = args[0] #start processing #create an out put filename if opts.outtype == 'uvfits': if opts.intype == 'fhd': suffix = 'FO' else: suffix = 'O' if opts.ave: suffix = suffix + 'A' if opts.tave: suffix = suffix + 'T' newfile = opts.outpath + obsid.split('/')[-1] + '_' + suffix + '.uvfits' if os.path.exists(newfile): raise IOError(' %s exists. Skipping...' % newfile) #read in the file print ' Reading', obsid uvi = uvd.UVData() if opts.intype == 'fhd': uvi.read_fhd(glob.glob(opts.fhdpath+'/vis_data/'+obsid+'*')+glob.glob(opts.fhdpath+'/metadata/'+obsid+'*'),use_model=False,run_check=False,run_check_acceptability=False) elif opts.intype == 'uvfits': uvi.read_uvfits(obsid+'.uvfits',run_check=False,run_check_acceptability=False) Nblts = uvi.Nblts Nfreqs = uvi.Nfreqs Nbls = uvi.Nbls pollist = uvi.polarization_array freqs = uvi.freq_array[0] #find npz for each pol, then apply for ip,p in enumerate(pols): pid = np.where(pollist == aipy.miriad.str2pol[p])[0][0] if opts.ave: omnifile = 'omni_sol/' + obsid.split('/')[-1]+'.'+p+'.omni.npz'
import numpy as np, sys import pyuvdata.uvdata as uvd obs = sys.argv[1] uv = uvd.UVData() print 'loading...' uv.read_uvfits(obs + '.uvfits', run_check=False, run_check_acceptability=False) print 'averaging..' data = (uv.data_array * np.logical_not(uv.flag_array)).reshape( uv.Nblts, uv.Nspws, uv.Nfreqs / 2, 2, uv.Npols) wgts = np.logical_not( uv.flag_array.reshape(uv.Nblts, uv.Nspws, uv.Nfreqs / 2, 2, uv.Npols)) data = np.sum(data, axis=3) wgts = np.sum(wgts, axis=3) uv.flag_array = (wgts <= 0) uv.nsample_array = np.float32(wgts * 8) ind = np.where(wgts == 0) wgts[ind] = -1 uv.data_array = data / wgts fq = uv.freq_array.reshape(uv.Nspws, uv.Nfreqs / 2, 2) uv.freq_array = np.mean(fq, axis=2) uv.Nfreqs /= 2 uv.channel_width *= 2 del data, wgts print 'writing...' uv.write_uvfits('./uvfitsdata/' + obs + '.uvfits', spoof_nonessential=True)