def add_meas_record(self, bl1, pol1, conj1, bl2, pol2, conj2): #amp_line = n.zeros((self.nprms,), dtype=n.double) phs_line = n.zeros((self.nprms,), dtype=n.double) i1,j1 = bl2ij(bl1) i2,j2 = bl2ij(bl2) if conj1: i1,j1 = j1,i1 if conj2: i2,j2 = j2,i2 i1,j1 = self.antpol_index(i1,pol1), self.antpol_index(j1,pol1) i2,j2 = self.antpol_index(i2,pol2), self.antpol_index(j2,pol2) #amp_line[j2], amp_line[i2], amp_line[j1], amp_line[i1] = 1, 1, -1, -1 #self.M_amp.append(amp_line) #phs_line[j2], phs_line[i2], phs_line[j1], phs_line[i1] = 1, -1, -1, 1 phs_line[j2] += 1; phs_line[i2] += -1; phs_line[j1] += -1; phs_line[i1] += 1 self.M_phs.append(phs_line) self.meas_order.append((bl1,pol1,conj1,bl2,pol2,conj2))
def estimate_xtalk(ant_sol, vis, meas_order): dsum,dwgt = {},{} for (bl,pol,sep,cnj),d in zip(meas_order,vis): i,j = bl2ij(bl) gi,gj = ant_sol[i][pol], ant_sol[j][pol] if cnj: gij = gi * n.conj(gj) else: gij = gj * n.conj(gi) d /= gij dsum[sep] = dsum.get(sep,0) + d dwgt[sep] = dwgt.get(sep,0) + 1 xtalk = [] for (bl,pol,sep,cnj),d in zip(meas_order,vis): i,j = bl2ij(bl) gi,gj = ant_sol[i][pol], ant_sol[j][pol] if cnj: gij = gi * n.conj(gj) else: gij = gj * n.conj(gi) davg = dsum[sep] / dwgt[sep] davg *= gij xtalk.append(d - davg) return n.array(xtalk)
def add_meas_record(self, bl, pol, sep, conj): amp_line = n.zeros((self.nprms,), dtype=n.double) phs_line = n.zeros((self.nprms,), dtype=n.double) i,j = bl2ij(bl) if conj: i,j = j,i s = self.sep_index(sep) i,j = self.antpol_index(i,pol), self.antpol_index(j,pol) amp_line[i], amp_line[j], amp_line[s] = 1, 1, 1 self.M_amp.append(amp_line) phs_line[i], phs_line[j], phs_line[s] = -1, 1, 1 self.M_phs.append(phs_line) self.meas_order.append((bl,pol,sep,conj))
def apply_gains(data, gains): rms = data['rms_array'] a1 = np.ndarray(rms.shape) a2 = np.ndarray(rms.shape) for bl in trange(rms.shape[0]): for freq in range(rms.shape[3]): for pol in range(rms.shape[4]): (i1, i2) = bl2ij(bl) i1 = np.argmin(gains['HERA_list'] - i1) i2 = np.argmin(gains['HERA_list'] - i2) g1 = np.mean(gains['hera_gains'][pol, i1, np.argmin(np.abs( gains['freqs'] - data['freq_array'][freq] / 1e6)), np.logical_and(gains['lsts'] < 11, gains['lsts'] > 6)]) g2 = np.mean(gains['hera_gains'][pol, i2, np.argmin(np.abs( gains['freqs'] - data['freq_array'][freq] / 1e6)), np.logical_and(gains['lsts'] < 11, gains['lsts'] > 6)]) a1[bl, :, 0, freq, pol] = np.tile(g1, (rms.shape[1],)) a2[bl, :, 0, freq, pol] = np.tile(g2, (rms.shape[1],)) tsys = np.divide(rms, np.sqrt(np.multiply(a1, a2))) tsys[tsys <= 0] = 0 return tsys
def find_peaks(d): p = n.zeros(d.size) np = n.argsort(d)[-NDLY:] while n.any(p != np): p = np np = n.unique(n.where(d[p-1] > d[p], p-1, p)) np = n.unique(n.where(d[(np+1)%d.size] > d[np], (np+1)%d.size, np)) return np bl01 = ij2bl(0,1) bins = find_peaks(data[bl01]) ok_bls = {bl01: n.where(bins > NCHAN/2, bins-NCHAN, bins)} NDLY = len(ok_bls[bl01]) if True: print bl2ij(bl01), bins, dlys_noshift[bins] p.plot(dlys_noshift, data[bl01]) p.plot(dlys_noshift[bins], data[bl01][bins], '^') p.show() # inds = n.argsort(ans,axis=None)[-NDLY**2:] # best_inds = {} # for ind in inds: # x = ind / ans.shape[0] # y = ind % ans.shape[0] # _x = None # for cnt in range(100): # _y = n.argmax(ans[x]) # _x = n.argmax(ans[:,_y]) # if _x == x: break
def blp2ijp(blp): bl,pol = int(blp) / 16, (blp % 16) - 9 i,j = miriad.bl2ij(bl) return i,j,pol
def blp2ijp(blp): bl, pol = int(blp) / 16, (blp % 16) - 9 i, j = miriad.bl2ij(bl) return i, j, pol
p = n.zeros(d.size) np = n.argsort(d)[-NDLY:] while n.any(p != np): p = np np = n.unique(n.where(d[p - 1] > d[p], p - 1, p)) np = n.unique( n.where(d[(np + 1) % d.size] > d[np], (np + 1) % d.size, np)) return np bl01 = ij2bl(0, 1) bins = find_peaks(data[bl01]) ok_bls = {bl01: n.where(bins > NCHAN / 2, bins - NCHAN, bins)} NDLY = len(ok_bls[bl01]) if True: print bl2ij(bl01), bins, dlys_noshift[bins] p.plot(dlys_noshift, data[bl01]) p.plot(dlys_noshift[bins], data[bl01][bins], '^') p.show() # inds = n.argsort(ans,axis=None)[-NDLY**2:] # best_inds = {} # for ind in inds: # x = ind / ans.shape[0] # y = ind % ans.shape[0] # _x = None # for cnt in range(100): # _y = n.argmax(ans[x]) # _x = n.argmax(ans[:,_y]) # if _x == x: break # else: x = _x