def process_ms(msname, outfn): station_map = utils.get_station_map(msname) station_names = sorted(station_map.keys()) stations2 = sorted(map(station_map.get, station_names)) ref_station_name = '1' # ANTENNA table has ID, Name and 'Station' fields'; here we want the last of these ref_station2 = station_map[ref_station_name] ref_s_ind2 = stations2.index(ref_station2) swid, pol_id, polind, = (0, 0, 0) for timeq in timeqs: delays, phases, rates, sigs = [], [], [], [] for pol_id in [0,3]: dels, phs, rs, sig = fringer.fit_fringe_lm(msname, stations2, ref_s_ind2, swid, polind, pol_id, timeq, solint=300) delays.append(dels) phases.append(phs) rates.append(rs) sigs.append(sig) outf = file(outfn, 'w') print >>outf, "#\n#{}\n#".format(timeq) utils.print_res(station_map, stations2, phases, delays, rates, sigs=sigs, outf=outf)
import glob, lsqrs, ffd, fringer, utils msname = 'N08C1_4C39.25.MS' ms.open(msname) ms.summary() # Better: listobs(msname) date = '2008-03-10' times = [('17:06:01.0', '17:09:00.0')] mysolint = 300 # seconds myrefant = '1' # string for 1-based refant number, 1 = EF timeqs = ffd.mktimeqs(date, times) station_map = utils.get_station_map(msname) station_names = sorted(station_map.keys()) # stations2 = sorted(map(station_map.get, station_names)) # station 8 missing; 3 misses a bunch of stuff. stations2 = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10] ref_station_name = myrefant # '1' is Effelsberg ref_station2 = station_map[ref_station_name] ref_s_ind2 = stations2.index(ref_station2) swid, polind, = (0, 0) #stations2 = [0,1,2,3,4,5,6,7,9,10] stations2 = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10] for timeq, swid in itertools.product(timeqs, range(4)): timeq2 = ffd.actual_timerangeq(msname, timeq)
import numpy as np, scipy, itertools import glob, lsqrs, ffd, fringer, utils msname='N14C3.MS' msname = '/scratch/small/N14C3/NME_challenge/N14C3_scan2_2.MS' timeqs = ['SCAN_NUMBER=2'] station_map = utils.get_station_map(msname) station_names = [t[1] for t in sorted([(i,n) for (n, i) in station_map.items()])] # stations2 = sorted(map(station_map.get, station_names)) stations2 = [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11] n_stations = len(stations2) # ref_station_name = '1' # Effelsberg ref_station_name = 'EF' ref_station = station_map[ref_station_name] polind = 0 solint = 600 threshold = 0.0 all_delays = [] all_phases = [] all_rates = [] for timeq, swid in itertools.product(timeqs, range(8)): timeq2 = ffd.actual_timerangeq(msname, timeq) delays, phases, rates, sigs = [], [], [], [] for pol_id in [0,3]: anffd = ffd.FFData.make_FFD(msname, stations2, swid, polind, pol_id, timeq2,
def fit_multiband_fringe(msname, scan_number, ctname): ms.open(msname) timeqs = ["SCAN_NUMBER={}".format(scan_number)] station_map = utils.get_station_map(msname) stations2 = sorted(ffd.actual_stations(msname, timeqs[0]).keys()) ism = utils.invert_map(station_map) station_names = [ism[s] for s in stations2] ref_station_name = 'EF' ref_station2 = station_map[ref_station_name] ref_s_ind2 = stations2.index(ref_station2) polind = 0 swids = range(8) reffreqs = utils.get_min_freqs(msname) minfreq = utils.get_min_freqs(msname)[0] make_table.make_table(msname, ctname) shape = (2, len(stations2)) delays = np.zeros(shape, np.float) phases = np.zeros(shape, np.float) rates = np.zeros(shape, np.float) sigs = [] rowcount = 0 for timeq in timeqs[:1]: timeq2 = ffd.actual_timerangeq(msname, timeq) for pol_id in [0,1]: casalog.post("Getting data") anffd = ffd.FFData.make_FFD_multiband(msname, stations2, polind, pol_id, timeq2, datacol="CORRECTED_DATA", solint=500) casalog.post("Fitting fringes") dels, phs, rs, sig = fringer.fit_fringe_ffd(anffd, ref_station2, stations2) delays[pol_id, :] = dels phases[pol_id, :] = phs rates[pol_id, :] = rs sigs.append(sig) obsid, field, scan = [ffd.distinct_thing(msname, timeq, col) for col in ['OBSERVATION_ID', 'FIELD_ID', 'SCAN_NUMBER']] darr = -delays*1e9 pharr = -phases # radians! rarr = -rates for i,s in enumerate(stations2): antenna = s assert (anffd.get_station_index(s) == i) time = anffd.get_ref_time() # time = anffd.times[0] interval = anffd.get_interval() midfreqs = utils.get_mid_freqs(msname) for swid in swids: # Df = (reffreqs[swid]-minfreq) Df = (midfreqs[swid]-minfreq) phase_offsets = utils.turns_to_radians(Df * darr/1e9 + interval/2 * rarr) ph = pharr + phase_offsets param = np.zeros(shape=(6,1), dtype='float32') param[:, 0] = [ph[0, i], darr[0, i], rates[0,i], ph[1, i], darr[1, i], rates[1,i] ] make_table.add_row(ctname, rowcount, time, interval, antenna, field, scan, obsid, swid, param) rowcount += 1