def make_FFD(self, timeq, swid, polind, solint=300): timeq2 = ffd.actual_timerangeq(self.msname, timeq) casalog.post("Processing spectral window {} for data selection {}" "".format(swid, timeq), "DEBUG") anffd = ffd.FFData.make_FFD(self.msname, self.antennas2, swid, self.pol_id, polind, timeq2, datacol="CORRECTED_DATA", solint=solint) return anffd
def run(self): shape = (2, len(self.antennas2)) flags = np.zeros(shape, np.bool) delays = np.zeros(shape, np.float) phases = np.zeros(shape, np.float) rates = np.zeros(shape, np.float) sigs = [] ref_freqs = utils.get_reference_freqs(self.msname) ref_freq_diffs = ref_freqs - ref_freqs[0] for scan in self.scans: if self.solint is None: solint = utils.get_scan_length(self.msname, scan) else: solint = self.solint scanq = self.make_time_q_from_scan(scan) solintqs = ffd.divide_up_timerange(self.msname, scanq, solint, self.solmin, self.solsub, self.dofloat) for timeq in solintqs: timeq2 = ffd.actual_timerangeq(self.msname, timeq) for pi, polind in enumerate(self.polinds): casalog.post("Getting data") anffd = ffd.FFData.make_FFD_multiband(self.msname, self.antennas2, self.pol_id, polind, timeq2, datacol="CORRECTED_DATA", solint=self.solint) self.anffd = anffd # so developers can poke it offline. casalog.post("Fitting fringes") self.t = fringer.fit_fringe_ffd(anffd, self.ref_antenna, self.antennas2, pad=self.pad) fs, dels, phs, rs, sig = self.t flags[pi, :] = fs delays[pi, :] = dels phases[pi, :] = phs rates[pi, :] = rs sigs.append(sig) for swid in self.spectral_windows: diffs = 2*np.pi*((ref_freq_diffs[swid]*delays) % 1.0) ph = phases + diffs # casalog.post("phases {} diffs {}".format(phases, diffs)) self.write_table(anffd, timeq2, flags, swid, delays, ph, rates, sigs)
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) delays, phases, rates, sigs = [], [], [], [] for pol_id in [0, 3]: print "# Doing a thing", swid, pol_id dels, phs, rs, sig = fringer.fit_fringe_lm(msname, stations2, ref_s_ind2, swid, polind, pol_id, timeq2, solint=mysolint, threshold=1000) delays.append(dels) phases.append(phs) rates.append(rs)
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