def make_waveform_realization_plot(ax, psr, real, sigma=0.68, *args, **kwargs): """ Make a waveform realization plot of signal vs time with uncertantiy region. :param ax: axes object instance :param psr: Pulsar object instance :param real: Nreal x ntoa array containing individual waveform realizations. :param sigma: Uncertainty level on waveform """ nt = real.shape[1] xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): rlind = np.flatnonzero(real[:, ii]) tmp, xmed[ii] = bu.confinterval(real[rlind, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(real[rlind, ii], sigma=sigma, type='minArea') idx = np.argsort(psr.toas) ax.fill_between(convert_mjd_to_greg(psr.toas[idx] / 86400), xlow[idx] * 1e6, xhigh[idx] * 1e6, **kwargs) ax.plot(convert_mjd_to_greg(psr.toas[idx] / 86400), xmed[idx] * 1e6, ls='--', lw=1.5, **kwargs)
def make_dm_waveform_realization_plot(ax, psr, qreal, incDM=True, *args, **kwargs): """ Make a waveform realization plot of DM vs time with uncertantiy region. :param ax: axes object instance :param psr: Pulsar object instance :param qreal: Nreal x npar array containing individual quadratic posteriors :param incDM: Boolean whether or not DM is in timing model or in noise model """ dmconst = 2.41e-4 #ntmpars = len(psr.ptmdescription) ntmpars = psr.Mmat_reduced.shape[1] nf = psr.Fmat.shape[1] nfdm = len(psr.Fdmfreqs) idd = np.arange(ntmpars + nf, ntmpars + nf + nfdm) idx = np.argsort(psr.toas) nt = len(idx) dmsig = np.zeros((qreal.shape[0], nt)) for ii in range(qreal.shape[0]): if incDM: id1 = list(psr.newdes).index('DM1') dmsig[ii, :] = psr.Ttmat[:, id1] * qreal[ii, id1] * dmconst * psr.freqs**2 id2 = list(psr.newdes).index('DM2') dmsig[ii, :] += psr.Ttmat[:, id2] * qreal[ ii, id2] * dmconst * psr.freqs**2 dmsig[ii, :] += np.dot(psr.Fdmmat, qreal[ii, idd]) dmsig[ii, :] -= dmsig[ii, :].mean() else: idd = np.array([ ct for ct, pp in enumerate(psr.ptmdescription) if 'DMX' in pp ]) dmsig[ii, :] = np.dot(psr.Ttmat[:, idd], qreal[ii, idd]) * dmconst * psr.freqs**2 xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): rlind = np.flatnonzero(dmsig[:, ii]) tmp, xmed[ii] = bu.confinterval(dmsig[rlind, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(dmsig[rlind, ii], sigma=0.68, type='minArea') ax.fill_between(convert_mjd_to_greg(psr.toas[idx] / 86400), xlow[idx] * 1e3, xhigh[idx] * 1e3, **kwargs) ax.plot(convert_mjd_to_greg(psr.toas[idx] / 86400), (xmed[idx] - xmed[idx].mean()) * 1e3, ls='--', lw=1.5, color='k')
def make_spectrum_realization_plot(ax, f, psd, sigma=0.68, plot_median=True, use_bars=False, *args, **kwargs): """ Make a waveform realization plot of signal vs time with uncertantiy region. :param ax: axes object instance :param model: PAL2 Model class :param real: Nreal x nf array containing individual spectrum realizations. :param sigma: Uncertainty level on waveform :param plot_median: Plot the median spectrum :param use_bars: Use error bars instead of fill_between """ nt = len(f) xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): tmp, xmed[ii] = bu.confinterval(psd[:, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(psd[:, ii], sigma=sigma, type='minArea') #print xlow, xhigh if use_bars: ymean = psd.mean(axis=0) ylow = np.log10(10**ymean - 10**xlow) yhigh = np.log10(10**xhigh - 10**ymean) yerr = np.vstack((ylow, yhigh)) ax.errorbar(f, 10**ymean, yerr=10**yerr, fmt='o', capsize=0, **kwargs) else: ax.fill_between(f, 10**xlow, 10**xhigh, **kwargs) if plot_median: ax.plot(f, 10**xmed, ls='--', lw=1.5, color='k') ax.set_xscale('log') ax.set_yscale('log') ax.set_ylim(10**xlow.min() / 2, 10**xhigh.max() * 2) df = f[1] - f[0] ax.set_xlim(f.min() - df, f.max() + df) ax.grid(which='both')
def make_dm_waveform_realization_plot(ax, psr, qreal, incDM=True, *args, **kwargs): """ Make a waveform realization plot of DM vs time with uncertantiy region. :param ax: axes object instance :param psr: Pulsar object instance :param qreal: Nreal x npar array containing individual quadratic posteriors :param incDM: Boolean whether or not DM is in timing model or in noise model """ dmconst = 2.41e-4 # ntmpars = len(psr.ptmdescription) ntmpars = psr.Mmat_reduced.shape[1] nf = psr.Fmat.shape[1] nfdm = len(psr.Fdmfreqs) idd = np.arange(ntmpars + nf, ntmpars + nf + nfdm) idx = np.argsort(psr.toas) nt = len(idx) dmsig = np.zeros((qreal.shape[0], nt)) for ii in range(qreal.shape[0]): if incDM: id1 = list(psr.newdes).index("DM1") dmsig[ii, :] = psr.Ttmat[:, id1] * qreal[ii, id1] * dmconst * psr.freqs ** 2 id2 = list(psr.newdes).index("DM2") dmsig[ii, :] += psr.Ttmat[:, id2] * qreal[ii, id2] * dmconst * psr.freqs ** 2 dmsig[ii, :] += np.dot(psr.Fdmmat, qreal[ii, idd]) dmsig[ii, :] -= dmsig[ii, :].mean() else: idd = np.array([ct for ct, pp in enumerate(psr.ptmdescription) if "DMX" in pp]) dmsig[ii, :] = np.dot(psr.Ttmat[:, idd], qreal[ii, idd]) * dmconst * psr.freqs ** 2 xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): rlind = np.flatnonzero(dmsig[:, ii]) tmp, xmed[ii] = bu.confinterval(dmsig[rlind, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(dmsig[rlind, ii], sigma=0.68, type="minArea") ax.fill_between(convert_mjd_to_greg(psr.toas[idx] / 86400), xlow[idx] * 1e3, xhigh[idx] * 1e3, **kwargs) ax.plot( convert_mjd_to_greg(psr.toas[idx] / 86400), (xmed[idx] - xmed[idx].mean()) * 1e3, ls="--", lw=1.5, color="k" )
def make_waveform_realization_plot(ax, psr, real, sigma=0.68, *args, **kwargs): """ Make a waveform realization plot of signal vs time with uncertantiy region. :param ax: axes object instance :param psr: Pulsar object instance :param real: Nreal x ntoa array containing individual waveform realizations. :param sigma: Uncertainty level on waveform """ nt = real.shape[1] xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): rlind = np.flatnonzero(real[:, ii]) tmp, xmed[ii] = bu.confinterval(real[rlind, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(real[rlind, ii], sigma=sigma, type="minArea") idx = np.argsort(psr.toas) ax.fill_between(convert_mjd_to_greg(psr.toas[idx] / 86400), xlow[idx] * 1e6, xhigh[idx] * 1e6, **kwargs) ax.plot(convert_mjd_to_greg(psr.toas[idx] / 86400), xmed[idx] * 1e6, ls="--", lw=1.5, **kwargs)
def make_spectrum_realization_plot(ax, f, psd, sigma=0.68, plot_median=True, use_bars=False, *args, **kwargs): """ Make a waveform realization plot of signal vs time with uncertantiy region. :param ax: axes object instance :param model: PAL2 Model class :param real: Nreal x nf array containing individual spectrum realizations. :param sigma: Uncertainty level on waveform :param plot_median: Plot the median spectrum :param use_bars: Use error bars instead of fill_between """ nt = len(f) xmed, xlow, xhigh = np.zeros(nt), np.zeros(nt), np.zeros(nt) for ii in range(nt): tmp, xmed[ii] = bu.confinterval(psd[:, ii], onesided=True, sigma=0.5) xlow[ii], xhigh[ii] = bu.confinterval(psd[:, ii], sigma=sigma, type="minArea") # print xlow, xhigh if use_bars: ymean = psd.mean(axis=0) ylow = np.log10(10 ** ymean - 10 ** xlow) yhigh = np.log10(10 ** xhigh - 10 ** ymean) yerr = np.vstack((ylow, yhigh)) ax.errorbar(f, 10 ** ymean, yerr=10 ** yerr, fmt="o", capsize=0, **kwargs) else: ax.fill_between(f, 10 ** xlow, 10 ** xhigh, **kwargs) if plot_median: ax.plot(f, 10 ** xmed, ls="--", lw=1.5, color="k") ax.set_xscale("log") ax.set_yscale("log") ax.set_ylim(10 ** xlow.min() / 2, 10 ** xhigh.max() * 2) df = f[1] - f[0] ax.set_xlim(f.min() - df, f.max() + df) ax.grid(which="both")