def tui_checkap(args): import omega as om if len(args) != 2: util.die('usage: <datfile> <antpol>') nc = NoiseCal() nc.load(args[0]) ap = util.parseAP(args[1]) apidx = nc.saps.index(ap) if apidx < 0: util.die('no antpol %s in data file!', util.fmtAP(ap)) sqbps = nc.sqbps vals = nc.bpdata[:, 1] modelvals = nc.bpdata[:, 3] * nc.svals resids = vals - modelvals runcerts = np.sqrt(1. / nc.bpdata[:, 2] + (nc.suncerts * nc.bpdata[:, 3])**2) resids /= runcerts w = np.where((sqbps[:, 0] == apidx) | (sqbps[:, 1] == apidx)) resids = resids[w] n = resids.size mn = resids.mean() s = resids.std() md = np.median(resids) smadm = 1.4826 * np.median(np.abs(resids - md)) # see comment below print ' Number of samples:', n print ' Norm. mean residal:', mn print ' Median:', md print 'Norm. residual std. dev.:', s print ' SMADM:', smadm bins = 50 rng = -5, 5 p = om.quickHist(resids, keyText='%s Residuals' % util.fmtAP(ap), bins=bins, range=rng) x = np.linspace(-5, 5, 200) area = 10. / bins * n y = area / np.sqrt(2 * np.pi) * np.exp(-0.5 * x**2) p.addXY(x, y, 'Ideal') p.rebound(False, False) p.show() return 0
def tui_checkap (args): import omega as om if len (args) != 2: util.die ('usage: <datfile> <antpol>') nc = NoiseCal () nc.load (args[0]) ap = util.parseAP (args[1]) apidx = nc.saps.index (ap) if apidx < 0: util.die ('no antpol %s in data file!', util.fmtAP (ap)) sqbps = nc.sqbps vals = nc.bpdata[:,1] modelvals = nc.bpdata[:,3] * nc.svals resids = vals - modelvals runcerts = np.sqrt (1./nc.bpdata[:,2] + (nc.suncerts * nc.bpdata[:,3])**2) resids /= runcerts w = np.where ((sqbps[:,0] == apidx) | (sqbps[:,1] == apidx)) resids = resids[w] n = resids.size mn = resids.mean () s = resids.std () md = np.median (resids) smadm = 1.4826 * np.median (np.abs (resids - md)) # see comment below print ' Number of samples:', n print ' Norm. mean residal:', mn print ' Median:', md print 'Norm. residual std. dev.:', s print ' SMADM:', smadm bins = 50 rng = -5, 5 p = om.quickHist (resids, keyText='%s Residuals' % util.fmtAP (ap), bins=bins, range=rng) x = np.linspace (-5, 5, 200) area = 10. / bins * n y = area / np.sqrt (2 * np.pi) * np.exp (-0.5 * x**2) p.addXY (x, y, 'Ideal') p.rebound (False, False) p.show () return 0
def tui_checkabs (args): import omega as om if len (args) != 1: util.die ('usage: <datfile>') nc = NoiseCal () nc.load (args[0]) saps = nc.saps sqbps = nc.sqbps vals = nc.bpdata[:,1] uncerts = nc.bpdata[:,2]**-0.5 modelvals = nc.bpdata[:,3] * nc.svals muncerts = nc.suncerts * nc.bpdata[:,3] pg = om.quickPager ([]) for idx in xrange (len (saps)): w = np.where ((sqbps[:,0] == idx) | (sqbps[:,1] == idx)) p = om.quickXYErr (vals[w], modelvals[w], muncerts[w], util.fmtAP (saps[idx]), lines=False) p.setLabels ('Measured variance (Jy²)', 'Modeled variance (Jy²)') pg.send (p) pg.done () return 0
def tui_checkabs(args): import omega as om if len(args) != 1: util.die('usage: <datfile>') nc = NoiseCal() nc.load(args[0]) saps = nc.saps sqbps = nc.sqbps vals = nc.bpdata[:, 1] uncerts = nc.bpdata[:, 2]**-0.5 modelvals = nc.bpdata[:, 3] * nc.svals muncerts = nc.suncerts * nc.bpdata[:, 3] pg = om.quickPager([]) for idx in xrange(len(saps)): w = np.where((sqbps[:, 0] == idx) | (sqbps[:, 1] == idx)) p = om.quickXYErr(vals[w], modelvals[w], muncerts[w], util.fmtAP(saps[idx]), lines=False) p.setLabels('Measured variance (Jy²)', 'Modeled variance (Jy²)') pg.send(p) pg.done() return 0
def export(self, stream): solution = self.solution saps = self.saps for i in xrange(len(saps)): print >> stream, self.instr, util.fmtAP( saps[i]), '%.5e' % solution[i]
def printsefdinfo (self): raras = self.raras solution = self.solution saps = self.saps n = len (saps) maxant = util.apAnt (saps[-1]) + 1 msefds = np.empty (n) pstds = np.empty (n) antcounts = np.zeros (maxant) antprods = np.ones (maxant) for i in xrange (n): info = raras[i] # TODO later: we're ignoring the RARA weighting # sqrt (2 * 102.4 khz * 10 s) sefd = 1431 * solution[i] * info[1] msefds[i] = sefd.mean () pstds[i] = 100. * sefd.std () / msefds[i] ant = util.apAnt (saps[i]) antcounts[ant] += 1 antprods[ant] *= msefds[i] w = np.where (antcounts == 2)[0] if w.size == 0: bestant = -1 else: bestant = w[np.argmin (antprods[w])] mmarks = [' | '] * n smarks = [' | '] * n sm = np.argsort (msefds) ss = np.argsort (pstds) for i in xrange (5): mmarks[sm[i]] = ' ' * i + '*' + ' ' * (4 - i) + '| ' mmarks[sm[-1 - i]] = ' |' + ' ' * (4 - i) + '*' + ' ' * i smarks[ss[i]] = ' ' * i + '*' + ' ' * (4 - i) + '| ' smarks[ss[-1 - i]] = ' |' + ' ' * (4 - i) + '*' + ' ' * i print 'instrument:', self.instr print print '%4s %7s %5s %13s %13s' % ('AP', 'SEFD', 'Var.', 'SEFD Rank', 'Var. Rank') for i in xrange (n): print '%4s %7.0f %4.1f%% [%s] [%s]' % \ (util.fmtAP (saps[i]), msefds[i], pstds[i], mmarks[i], smarks[i]) print print 'Median (mean SEFD):', np.median (msefds) print ' Equiv. TSys:', np.median (msefds) / 153. if bestant < 0: print 'No dual-pol antennas' else: print 'Best dual-pol antenna:', bestant
def printsefdinfo(self): raras = self.raras solution = self.solution saps = self.saps n = len(saps) maxant = util.apAnt(saps[-1]) + 1 msefds = np.empty(n) pstds = np.empty(n) antcounts = np.zeros(maxant) antprods = np.ones(maxant) for i in xrange(n): info = raras[i] # TODO later: we're ignoring the RARA weighting # sqrt (2 * 102.4 khz * 10 s) sefd = 1431 * solution[i] * info[1] msefds[i] = sefd.mean() pstds[i] = 100. * sefd.std() / msefds[i] ant = util.apAnt(saps[i]) antcounts[ant] += 1 antprods[ant] *= msefds[i] w = np.where(antcounts == 2)[0] if w.size == 0: bestant = -1 else: bestant = w[np.argmin(antprods[w])] mmarks = [' | '] * n smarks = [' | '] * n sm = np.argsort(msefds) ss = np.argsort(pstds) for i in xrange(5): mmarks[sm[i]] = ' ' * i + '*' + ' ' * (4 - i) + '| ' mmarks[sm[-1 - i]] = ' |' + ' ' * (4 - i) + '*' + ' ' * i smarks[ss[i]] = ' ' * i + '*' + ' ' * (4 - i) + '| ' smarks[ss[-1 - i]] = ' |' + ' ' * (4 - i) + '*' + ' ' * i print 'instrument:', self.instr print print '%4s %7s %5s %13s %13s' % ('AP', 'SEFD', 'Var.', 'SEFD Rank', 'Var. Rank') for i in xrange(n): print '%4s %7.0f %4.1f%% [%s] [%s]' % \ (util.fmtAP (saps[i]), msefds[i], pstds[i], mmarks[i], smarks[i]) print print 'Median (mean SEFD):', np.median(msefds) print ' Equiv. TSys:', np.median(msefds) / 153. if bestant < 0: print 'No dual-pol antennas' else: print 'Best dual-pol antenna:', bestant
def _format(aps): if isinstance(aps, int): aps = (aps, ) return '-'.join(util.fmtAP(x) for x in aps)
def tui_checkfit (args): import omega as om if len (args) != 1: util.die ('usage: <datfile>') nc = NoiseCal () nc.load (args[0]) vals = nc.bpdata[:,1] modelvals = nc.bpdata[:,3] * nc.svals resids = vals - modelvals runcerts = np.sqrt (1./nc.bpdata[:,2] + (nc.suncerts * nc.bpdata[:,3])**2) normresids = resids / runcerts n = normresids.size mn = normresids.mean () s = normresids.std () md = np.median (normresids) smadm = 1.4826 * np.median (np.abs (normresids - md)) # see comment below print ' Number of samples:', n print ' Normalized mean residal:', mn print ' Median:', md print 'Normalized std. dev. (should be 1):', s print ' SMADM:', smadm # Check for problematic antpols and basepols saps = nc.saps sqbps = nc.sqbps nap = len (saps) dumbnbp = nap**2 apcounts = np.zeros (nap, dtype=np.int) apsumsqresids = np.zeros (nap) bpcounts = np.zeros (dumbnbp, dtype=np.int) bpsumsqresids = np.zeros (dumbnbp) for i in xrange (n): idx1, idx2 = sqbps[i] apcounts[idx1] += 1 apsumsqresids[idx1] += normresids[i]**2 apcounts[idx2] += 1 apsumsqresids[idx2] += normresids[i]**2 bpidx = idx1 * nap + idx2 bpcounts[bpidx] += 1 bpsumsqresids[bpidx] += normresids[i]**2 aprmsresids = np.sqrt (apsumsqresids / apcounts) sapresids = np.argsort (aprmsresids) print print 'Extreme residual RMS by antpol:' for i in xrange (5): idx = sapresids[i] print ' %10s %8.2f' % (util.fmtAP (saps[idx]), aprmsresids[idx]) print ' ....' for i in xrange (5): idx = sapresids[i - 5] print ' %10s %8.2f' % (util.fmtAP (saps[idx]), aprmsresids[idx]) wbpgood = np.where (bpcounts)[0] wbpbad = np.where (bpcounts == 0)[0] bpcounts[wbpbad] = 1 bprmsresids = bpsumsqresids / bpcounts sbpresids = np.argsort (bprmsresids[wbpgood]) print print 'Extreme residual RMS by basepol:' for i in xrange (3): idx = wbpgood[sbpresids[i]] ap2 = saps[idx % nap] ap1 = saps[idx // nap] print ' %10s %8.2f' % (util.fmtBP ((ap1, ap2)), bprmsresids[idx]) print ' ....' for i in xrange (7): idx = wbpgood[sbpresids[i - 7]] ap2 = saps[idx % nap] ap1 = saps[idx // nap] print ' %10s %8.2f' % (util.fmtBP ((ap1, ap2)), bprmsresids[idx]) # Plot the distribution of residuals bins = 50 rng = -5, 5 p = om.quickHist (normresids, keyText='Residuals', bins=bins, range=rng) x = np.linspace (-5, 5, 200) area = 10. / bins * n y = area / np.sqrt (2 * np.pi) * np.exp (-0.5 * x**2) p.addXY (x, y, 'Ideal') p.rebound (False, False) p.show () return 0
def export (self, stream): solution = self.solution saps = self.saps for i in xrange (len (saps)): print >>stream, self.instr, util.fmtAP (saps[i]), '%.5e' % solution[i]
def _format (aps): if isinstance (aps, int): aps = (aps, ) return '-'.join (util.fmtAP (x) for x in aps)
def tui_checkfit(args): import omega as om if len(args) != 1: util.die('usage: <datfile>') nc = NoiseCal() nc.load(args[0]) vals = nc.bpdata[:, 1] modelvals = nc.bpdata[:, 3] * nc.svals resids = vals - modelvals runcerts = np.sqrt(1. / nc.bpdata[:, 2] + (nc.suncerts * nc.bpdata[:, 3])**2) normresids = resids / runcerts n = normresids.size mn = normresids.mean() s = normresids.std() md = np.median(normresids) smadm = 1.4826 * np.median(np.abs(normresids - md)) # see comment below print ' Number of samples:', n print ' Normalized mean residal:', mn print ' Median:', md print 'Normalized std. dev. (should be 1):', s print ' SMADM:', smadm # Check for problematic antpols and basepols saps = nc.saps sqbps = nc.sqbps nap = len(saps) dumbnbp = nap**2 apcounts = np.zeros(nap, dtype=np.int) apsumsqresids = np.zeros(nap) bpcounts = np.zeros(dumbnbp, dtype=np.int) bpsumsqresids = np.zeros(dumbnbp) for i in xrange(n): idx1, idx2 = sqbps[i] apcounts[idx1] += 1 apsumsqresids[idx1] += normresids[i]**2 apcounts[idx2] += 1 apsumsqresids[idx2] += normresids[i]**2 bpidx = idx1 * nap + idx2 bpcounts[bpidx] += 1 bpsumsqresids[bpidx] += normresids[i]**2 aprmsresids = np.sqrt(apsumsqresids / apcounts) sapresids = np.argsort(aprmsresids) print print 'Extreme residual RMS by antpol:' for i in xrange(5): idx = sapresids[i] print ' %10s %8.2f' % (util.fmtAP(saps[idx]), aprmsresids[idx]) print ' ....' for i in xrange(5): idx = sapresids[i - 5] print ' %10s %8.2f' % (util.fmtAP(saps[idx]), aprmsresids[idx]) wbpgood = np.where(bpcounts)[0] wbpbad = np.where(bpcounts == 0)[0] bpcounts[wbpbad] = 1 bprmsresids = bpsumsqresids / bpcounts sbpresids = np.argsort(bprmsresids[wbpgood]) print print 'Extreme residual RMS by basepol:' for i in xrange(3): idx = wbpgood[sbpresids[i]] ap2 = saps[idx % nap] ap1 = saps[idx // nap] print ' %10s %8.2f' % (util.fmtBP((ap1, ap2)), bprmsresids[idx]) print ' ....' for i in xrange(7): idx = wbpgood[sbpresids[i - 7]] ap2 = saps[idx % nap] ap1 = saps[idx // nap] print ' %10s %8.2f' % (util.fmtBP((ap1, ap2)), bprmsresids[idx]) # Plot the distribution of residuals bins = 50 rng = -5, 5 p = om.quickHist(normresids, keyText='Residuals', bins=bins, range=rng) x = np.linspace(-5, 5, 200) area = 10. / bins * n y = area / np.sqrt(2 * np.pi) * np.exp(-0.5 * x**2) p.addXY(x, y, 'Ideal') p.rebound(False, False) p.show() return 0