def makeXiePlot(filename): data = loadXieData(filename) fig, axes = plt.subplots(3, 3, figsize=(10, 10)) for i in range(len(data)): ax = axes.flat[i] name, nud, td, Fnud, Y = data[i] t = np.geomspace(td.min(), td.max(), 300) nu = np.empty(t.shape) nu[:] = nud Fnu = grb.fluxDensity(t * grb.day2sec, nu, 5, 0, *Y, spread=False) YG = Y.copy() YG[2] /= np.sqrt(2) FnuG = grb.fluxDensity(t * grb.day2sec, nu, 0, 0, *YG, spread=False) YG[2] /= np.sqrt(2) Fnu2 = grb.fluxDensity(t * grb.day2sec, nu, 0, 0, *YG, spread=False) YG[2] /= np.sqrt(2) Fnu3 = grb.fluxDensity(t * grb.day2sec, nu, 0, 0, *YG, spread=False) ax.plot(td, Fnud) ax.plot(t, Fnu) ax.plot(t, FnuG) ax.plot(t, Fnu2) ax.plot(t, Fnu3) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlabel(r'$t$ (d)') ax.set_ylabel(r'$F_\nu$ (mJy)') ax.set_title(name) th = np.linspace(0.0, 0.5 * np.pi) E1 = np.exp(-np.power(th / 0.15, 1.93)) E2 = np.exp(-0.5 * th * th / (0.106**2)) axes[2, 2].plot(th, E1, color='C1') axes[2, 2].plot(th, E2, color='C2') axes[2, 2].set_yscale('log') axes[2, 2].set_xlabel(r'$\theta$ (rad)') axes[2, 2].set_ylabel(r'$E_{\mathrm{iso}}$ (erg)') fig.tight_layout() print("Saving xie_comp.pdf") fig.savefig('xie_comp.pdf')
def makeLazzatiPlot(filename, structFile, figname): data = loadLazzatiData(filename) theta, E = loadLazzatiEtheta(structFile) fig, axes = plt.subplots(2, 3, figsize=(10, 7)) for i in range(len(data)): ax = axes.flat[i] name, nud, td, Fnud, Y = data[i] t = np.geomspace(td.min(), td.max(), 300) nu = np.empty(t.shape) nu[:] = nud Fnu = grb.fluxDensity(t * grb.day2sec, nu, 4, 0, *Y, spread=False) """ YG = Y.copy() YG[2] /= np.sqrt(2) FnuG = grb.fluxDensity(t*grb.day2sec, nu, 0, 0, *YG, spread=False) YG[2] /= np.sqrt(2) Fnu2 = grb.fluxDensity(t*grb.day2sec, nu, 0, 0, *YG, spread=False) YG[2] /= np.sqrt(2) Fnu3 = grb.fluxDensity(t*grb.day2sec, nu, 0, 0, *YG, spread=False) """ ax.plot(td, Fnud) ax.plot(t, Fnu) # ax.plot(t, FnuG) # ax.plot(t, Fnu2) # ax.plot(t, Fnu3) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlabel(r'$t$ (d)') ax.set_ylabel(r'$F_\nu$ (mJy)') ax.set_title(name) th = np.linspace(0.0, 0.5 * np.pi) Epl = Y[1] * np.power(1.0 + th * th / (Y[2] * Y[2]), -0.5 * Y[4]) Epl[th > Y[3]] = 0.0 axes[1, 2].plot(theta, E, color='C0') axes[1, 2].plot(th, Epl, color='C1') axes[1, 2].set_yscale('log') axes[1, 2].set_xlabel(r'$\theta$ (rad)') axes[1, 2].set_ylabel(r'$E_{\mathrm{iso}}$ (erg)') fig.tight_layout() print("Saving " + figname) fig.savefig(figname)
def compareAll(): NC = 3 NV = 6 NN = 3 colors = ['C0', 'C1', 'C2', 'C3', 'C4'] for i in range(NC): for j in range(NV): fig, ax = plt.subplots(1, 1, figsize=(8, 6)) thV = 0.0 thC = 0.0 for k in range(NN): filename = dataDir + "boxfit{0:d}{1:d}{2:d}".format(i, j, k) out = processBoxfitFile(filename) t, nu, FnuBF, jT, sT, Y, z = out thV = Y[0] thC = Y[2] Fnu = grb.fluxDensity(t, nu, jT, sT, *Y, z=z) ax.plot(t, FnuBF, ls='--', color=colors[k], label=r'BoxFit $\nu=${0:.1e}Hz'.format(nu[0])) ax.plot(t, Fnu, ls='-', color=colors[k], label=r'grbpy $\nu=${0:.1e}Hz'.format(nu[0])) ax.set_xscale('log') ax.set_yscale('log') ax.set_xlabel(r'$t$ (s)') ax.set_ylabel(r'$F_\nu$ (mJy)') # ax.legend(labelspacing=0, fontsize=6) ax.legend() ax.set_title(r"$\theta_C=${0:.2f} $\theta_V=${1:.2f}".format( thC, thV)) fig.tight_layout() figname = dataDir + "boxfit_comp_{0:d}{1:d}.png".format(i, j) print("Saving " + figname) fig.savefig(figname) plt.close(fig)
def makeNiceFigure(): curves = [] curves += ['100', '130', '102', '132'] # curves += ['000', '002', '030', '032'] # curves += ['200', '202', '230', '232'] colors = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'] fig = plt.figure(figsize=(8, 6)) gs = fig.add_gridspec(4, 1, hspace=0) axF = fig.add_subplot(gs[0:-1, 0]) axE = fig.add_subplot(gs[-1, 0]) bfLines = [] apLines = [] solid_line = mpl.lines.Line2D([], [], ls='-', color='grey') dashed_line = mpl.lines.Line2D([], [], ls='--', color='grey') handles = [solid_line, dashed_line] labels = [r'\tt{afterglowypy}', r'\tt{BoxFit}'] for i, code in enumerate(curves): filename = dataDir + "boxfit{0:s}".format(code) out = processBoxfitFile(filename) t, nu, FnuBF, jT, sT, Y, z = out thV = Y[0] # thC = Y[2] Fnu = grb.fluxDensity(t, nu, jT, sT, *Y, z=z) if code[2] == '0': log10nu = 9 elif code[2] == '0': log10nu = 14 else: log10nu = 18 lineBF, = axF.plot(t, FnuBF, ls='--', color=colors[i]) lineAP, = axF.plot(t, Fnu, ls='-', color=colors[i]) label = (r'$\theta_{{\mathrm{{obs}}}}={0:.2f}$ rad' r' $\nu=10^{{{1:d}}}$Hz').format(thV, log10nu) apLines.append(lineAP) bfLines.append(lineBF) handles.append(lineAP) labels.append(label) err = (Fnu - FnuBF)[FnuBF > 0] / FnuBF[FnuBF > 0] # err = Fnu[FnuBF > 0]/FnuBF[FnuBF > 0] axE.plot(t[FnuBF > 0], err, ls='-', color=colors[i]) axF.set_xscale('log') axF.set_yscale('log') axF.set_ylabel(r'$F_\nu$ (mJy)') axE.set_ylim(-1.0, 1.0) # axE.set_ylim(0.25, 4.0) axE.set_xscale('log') # axE.set_yscale('log') axE.set_ylabel(r'Fractional Difference') axE.set_xlabel(r'$t$ (s)') # ax.legend(labelspacing=0, fontsize=6) axF.legend(handles, labels) # axF.legend(handles, labels, labelspacing=0) fig.tight_layout() figname = dataDir + "boxfit_comp.pdf" print("Saving " + figname) fig.savefig(figname) plt.close(fig)
def fluxDensity(t, nu, jetType, specType, *Y): mJy = grbpy.fluxDensity(t, nu, jetType, specType, *Y) return mJy
def plotPanel(fig, gs0, t, nu, thV, Y, Z, thVLegend=False): gs = gs0.subgridspec(3, 1, hspace=0.0) axF = fig.add_subplot(gs[0:-1, 0]) axa = fig.add_subplot(gs[-1, 0]) tfac = 0.3 tb = t * (1.0 + tfac) ta = t / (1.0 - tfac) c = ['C0', 'C2', 'C1', 'C3'] ls = ['--', '-', '-.', ':'] thC = Y[2] Y[0] = thV FnuTH = grb.fluxDensity(t, nu, -1, 0, *Y, **Z) FnuTHa = grb.fluxDensity(ta, nu, -1, 0, *Y, **Z) FnuTHb = grb.fluxDensity(tb, nu, -1, 0, *Y, **Z) FnuG = grb.fluxDensity(t, nu, 0, 0, *Y, **Z) FnuGa = grb.fluxDensity(ta, nu, 0, 0, *Y, **Z) FnuGb = grb.fluxDensity(tb, nu, 0, 0, *Y, **Z) Y[4] = 2 FnuPL1 = grb.fluxDensity(t, nu, 4, 0, *Y, **Z) FnuPL1a = grb.fluxDensity(ta, nu, 4, 0, *Y, **Z) FnuPL1b = grb.fluxDensity(tb, nu, 4, 0, *Y, **Z) Y[4] = 6 # Y[2] = np.sqrt(3)*thC FnuPL2 = grb.fluxDensity(t, nu, 4, 0, *Y, **Z) FnuPL2a = grb.fluxDensity(ta, nu, 4, 0, *Y, **Z) FnuPL2b = grb.fluxDensity(tb, nu, 4, 0, *Y, **Z) Y[2] = thC alTH = np.log(FnuTHb / FnuTHa) / np.log(tb / ta) alG = np.log(FnuGb / FnuGa) / np.log(tb / ta) alPL1 = np.log(FnuPL1b / FnuPL1a) / np.log(tb / ta) alPL2 = np.log(FnuPL2b / FnuPL2a) / np.log(tb / ta) axF.plot(t, FnuTH, label='Top-Hat', color=c[0], ls=ls[0]) axF.plot(t, FnuG, label='Gaussian Jet', color=c[1], ls=ls[1]) axF.plot(t, FnuPL1, label='Power Law Jet $b=2$', color=c[2], ls=ls[2]) axF.plot(t, FnuPL2, label='Power Law Jet $b=6$', color=c[3], ls=ls[3]) axa.plot(t, alTH, color=c[0], ls=ls[0]) axa.plot(t, alG, color=c[1], ls=ls[1]) axa.plot(t, alPL1, color=c[2], ls=ls[2]) axa.plot(t, alPL2, color=c[3], ls=ls[3]) axa.set_xscale('log') axa.set_yscale('linear') axF.set_xscale('log') axF.set_yscale('log') axF.get_xaxis().set_visible(False) axa.set_yticks([-2, 0, 2, 4]) axF.set_ylabel(r'$F_{\nu}$ (1 keV)') axa.set_xlabel(r'$t$ (s)') axa.set_ylabel(r'$\alpha$') axF.set_xlim(t[0], t[-1]) axF.set_ylim(1.0e-10, 1.0e-3) axa.set_xlim(t[0], t[-1]) axa.set_ylim(-3, 5) if modelLegend: axF.legend(loc='lower left') axF.text(0.95, 0.95, r'$\theta_{{\mathrm{{obs}}}} = $ {0:.2f} rad'.format(thV), transform=axF.transAxes, horizontalalignment='right', verticalalignment='top')
def analyzeBreakTimes(regime, jetModel): NU, tN, Y, betaE = pp.getRegimePars(regime) tfac = 1.1 nufac = 1.1 if jetModel is 4: bs = np.array([2.0, 3, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]) else: bs = np.array([1.0]) thCs = np.array([0.04, 0.06, 0.08, 0.10, 0.12, 0.14, 0.16]) thW = 0.4 Nb = len(bs) Nc = len(thCs) panelWidth = 6.0 panelHeight = 6.0 fig = plt.figure(figsize=(panelWidth * Nb, panelHeight * Nc)) gs0 = fig.add_gridspec(Nc, Nb) # minTb = math.pow(min(thCs), 8.0/3.0) t = np.geomspace(1.0e-6 * tN, 0.03 * tN, 100) nu = np.empty(t.shape) nu[:] = NU print("Calculating") tb = np.empty((Nc, Nb)) for i, thC in enumerate(thCs): for j, b in enumerate(bs): Y[0] = 0.0 Y[2] = thC Y[3] = thW Y[4] = b Fnu = grb.fluxDensity(t, nu, jetModel, 0, *Y, latRes=10) Fnutr = grb.fluxDensity(t * tfac, nu, jetModel, 0, *Y, latRes=10) Fnutl = grb.fluxDensity(t / tfac, nu, jetModel, 0, *Y, latRes=10) Fnunr = grb.fluxDensity(t, nu * nufac, jetModel, 0, *Y, latRes=10) Fnunl = grb.fluxDensity(t, nu / nufac, jetModel, 0, *Y, latRes=10) alpha = np.log(Fnutr / Fnutl) / np.log(tfac * tfac) beta = np.log(Fnunr / Fnunl) / np.log(nufac * nufac) alPre = pp.calcSlopePre(jetModel, Y, regime) alPost = pp.calcSlopePost(jetModel, Y, regime) # ib = np.searchsorted(alpha, 0.5*(alPre+alPost)) ib = np.argwhere(alpha < 0.5 * (alPre + alPost))[0] tb[i, j] = t[ib] gs = gs0[i, j].subgridspec(4, 1, hspace=0) axF = fig.add_subplot(gs[0:-2, 0]) axa = fig.add_subplot(gs[-2, 0]) axb = fig.add_subplot(gs[-1, 0]) axF.plot(t, Fnu) axa.plot(t, alpha) axb.plot(t, beta) axa.axhline(alPre, color='grey', ls='--') axa.axhline(alPost, color='grey', ls='-') axF.set_xscale('log') axa.set_xscale('log') axb.set_xscale('log') axF.set_yscale('log') plotname = "jb_lc_jet_{0:d}_regime_{1:s}.png".format(jetModel, regime) print("Saving " + plotname) fig.savefig(plotname) p = Y[9] betaE2, al1, D, s1, s2, p = pp.get_powers(regime, p) numfac = math.pow( math.pow(2.0, 8 + 3 * betaE) / math.sqrt(4 * D), -1.0 / (2 * D)) tbTH = 0.5 * np.power(thCs * numfac, 8.0 / 3.0) * tN fig, ax = plt.subplots(1, 1) ax.plot(thCs, tbTH, ls='--', lw=3, color='grey') for j, b in enumerate(bs): ax.plot(thCs, tb[:, j], marker='.') ax.set_xscale('log') ax.set_yscale('log') plotname = "jb_tb_jet_{0:d}_regime_{1:s}.png".format(jetModel, regime) print("Saving " + plotname) fig.savefig(plotname) if len(bs) > 1.0: fig, ax = plt.subplots(1, 1) ax.plot(bs, np.power(bs / 2, -1.5), ls='--', lw=3, color='grey') ax.plot(bs, np.power(bs / 2, -1.65), ls='--', lw=3, color='grey') ax.plot(bs, np.power(bs / 2, -2), ls='--', lw=3, color='grey') for i, thC in enumerate(thCs): ax.plot(bs, tb[i, :] / tbTH[i], marker='.') ax.set_xscale('log') ax.set_yscale('log') plotname = "jb_corr_jet_{0:d}_regime_{1:s}.png".format( jetModel, regime) print("Saving " + plotname) fig.savefig(plotname) res = np.polyfit(np.log(bs)[1:], np.log(tb[:, :] / tbTH[:, None]).mean(axis=0)[1:], deg=1) print(res)
def plotPanel(fig, gs0, t, nu, jetType, Y, Z, thVLegend=False): gs = gs0.subgridspec(3, 1, hspace=0.0) axF = fig.add_subplot(gs[0:-1, 0]) axa = fig.add_subplot(gs[-1, 0]) # axs = fig.add_subplot(gs[-1, 0]) tfac = 0.3 tb = t * (1.0 + tfac) ta = t / (1.0 - tfac) b = Y[4] if jetType == -1: c = 'C0' ls = '--' name = 'top hat' elif jetType == 0: c = 'C2' ls = '-' name = 'Gaussian' elif jetType == 4 and b < 4: c = 'C1' ls = '-.' name = 'power law b={0:d}'.format(int(b)) elif jetType == 4 and b >= 4: c = 'C3' ls = ':' name = 'power law b={0:d}'.format(int(b)) else: c = 'C4' ls = '-' name = 'unknown' thC = Y[2] thVs = np.array( [0.0, 0.5 * thC, 0.9 * thC, 2 * thC, 4 * thC, 6 * thC, 8 * thC]) alpha = np.linspace(0.2, 1.0, len(thVs)) th = np.linspace(0.0, Y[3], 300) # phi = np.zeros(th.shape) # t_th = np.empty(th.shape) nu_th = np.empty(th.shape) nu_th[:] = nu[0] for i, thV in enumerate(thVs): Y[0] = thV Fnu = grb.fluxDensity(t, nu, jetType, 0, *Y, **Z) Fnua = grb.fluxDensity(ta, nu, jetType, 0, *Y, **Z) Fnub = grb.fluxDensity(tb, nu, jetType, 0, *Y, **Z) al = np.log(Fnub / Fnua) / np.log(tb / ta) """ dOma = np.empty(Fnu.shape) dOmb = np.empty(Fnu.shape) dOm = np.empty(Fnu.shape) thsa = np.empty(Fnu.shape) thsb = np.empty(Fnu.shape) ths = np.empty(Fnu.shape) for j in range(len(t)): t_th[:] = ta[j] Inu = grb.intensity(th, phi, t_th, nu_th, jetType, 0, *Y, **Z) dOma[j] = Fnua[j] / Inu.max() thsa[j] = th[Inu.argmax()] t_th[:] = tb[j] Inu = grb.intensity(th, phi, t_th, nu_th, jetType, 0, *Y, **Z) dOmb[j] = Fnub[j] / Inu.max() thsb[j] = th[Inu.argmax()] t_th[:] = t[j] Inu = grb.intensity(th, phi, t_th, nu_th, jetType, 0, *Y, **Z) dOm[j] = Fnu[j] / Inu.max() ths[j] = th[Inu.argmax()] _, _, us, _ = grb.jet.shockVals(ths, np.zeros(t.shape), t, jetType, *Y) _, _, usa, _ = grb.jet.shockVals(thsa, np.zeros(t.shape), ta, jetType, *Y) _, _, usb, _ = grb.jet.shockVals(thsb, np.zeros(t.shape), tb, jetType, *Y) som = np.log(dOmb/dOma) / np.log(usb/usa) """ axF.plot( t, Fnu, label=r'$\theta_{{\mathrm{{obs}}}} = $ {0:.2f} rad'.format(thV), color=c, ls=ls, alpha=alpha[i]) axa.plot(t, al, color=c, ls=ls, alpha=alpha[i]) # axs.plot(t, som, color=c, ls=ls, alpha=alpha[i]) axa.set_xscale('log') axa.set_yscale('linear') axF.set_xscale('log') axF.set_yscale('log') # axs.set_xscale('log') # axs.set_yscale('linear') axF.get_xaxis().set_visible(False) axa.set_yticks([-4, -2, 0, 2, 4]) axF.set_ylabel(r'$F_{\nu}$ (1 keV)') axa.set_xlabel(r'$t$ (s)') axa.set_ylabel(r'$\alpha$') axF.set_xlim(t[0], t[-1]) axF.set_ylim(1.0e-10, 1.0e-3) axa.set_xlim(t[0], t[-1]) axa.set_ylim(-4, 5) # axs.set_ylim(-3.1, 0.1) if thVLegend: axF.legend(loc='lower left') axF.text(0.95, 0.95, name, transform=axF.transAxes, horizontalalignment='right', verticalalignment='top')
def makeSlopesPlot(): thV = 0.75 * 0.02 E0 = 1.0e52 thC = 0.02 thW = 0.4 b = 5.0 n0 = 1.0e-3 p = 2.2 epse = 0.1 epsB = 1.0e-4 xiN = 1.0 dL = 3.0e26 Y = np.array( [thV, E0, thC, thW, b, 0.0, 0.0, 0.0, n0, p, epse, epsB, xiN, dL]) tN = math.pow(9 * E0 / (16.0 * np.pi * n0 * grb.mp * grb.c**5), 1.0 / 3.0) NU = 1.0e17 regime = 'G' jetModel = -1 tRes = 4000 spread = False tfac = 0.25 vfac = 0.25 t = np.geomspace(1.0, 0.03 * tN, 1000) nu = np.empty(t.shape) nu[:] = NU findBreaks(regime, NU, jetModel, Y, plot=True) Fnu = grb.fluxDensity(t, nu, -1, 0, *Y, tRes=tRes, spread=spread) Fnuta = grb.fluxDensity(t / (1.0 + tfac), nu, -1, 0, *Y, tRes=tRes, spread=spread) Fnutb = grb.fluxDensity(t * (1.0 + tfac), nu, -1, 0, *Y, tRes=tRes, spread=spread) Fnuva = grb.fluxDensity(t, nu / (1.0 + vfac), -1, 0, *Y, tRes=tRes, spread=spread) Fnuvb = grb.fluxDensity(t, nu * (1.0 + vfac), -1, 0, *Y, tRes=tRes, spread=spread) al = np.log(Fnutb / Fnuta) / np.log((1 + tfac) * (1 + tfac)) daldt = np.log(Fnutb * Fnuta / (Fnu * Fnu)) / np.log(1.0 + tfac)**2 d2aldt2 = np.zeros(al.shape) d2aldt2[1:-1] = (daldt[2:] - daldt[:-2]) / np.log((1 + tfac) * (1 + tfac)) be = np.log(Fnuvb / Fnuva) / np.log((1 + vfac) * (1 + vfac)) alPre = slopePre(p, 'G') alPost = slopePost(p, 'G') beSpec = slopeSpec(p, 'G') fig, ax = plt.subplots(5, 1, figsize=(4, 7)) ax[0].plot(t, Fnu) ax[1].plot(t, al) ax[1].axhline(alPre, color='grey') ax[1].axhline(alPost, color='grey') ax[2].plot(t, daldt) ax[3].plot(t, d2aldt2) ax[4].plot(t, be) ax[4].axhline(beSpec, color='grey') ax[0].set_xscale('log') ax[0].set_yscale('log') ax[1].set_xscale('log') ax[2].set_xscale('log') ax[3].set_xscale('log') ax[4].set_xscale('log') ax[2].set_ylim(-1, 1) ax[3].set_ylim(-1, 1)
def findBreaks(regime, NU, jetModel, Y, n=None, spread=False, plot=False, ax=None, fig=None, printMode=None): thV = Y[0] E0 = Y[1] thC = Y[2] thW = Y[3] n0 = Y[8] p = Y[9] tN = math.pow(9 * E0 / (16.0 * np.pi * n0 * grb.mp * grb.c**5), 1.0 / 3.0) chim = 2 * np.sin(0.5 * np.fabs(thC - thV)) chip = 2 * np.sin(0.5 * (thC + thV)) EW = Etheta(jetModel, thW, Y) tNW = math.pow(9 * EW / (16.0 * np.pi * n0 * grb.mp * grb.c**5), 1.0 / 3.0) chiW = 2 * np.sin(0.5 * np.fabs(thV - thW)) t0_OnA = tN * math.pow(chim, 8.0 / 3.0) t0_OfA = tNW * math.pow(chiW, 8.0 / 3.0) """ t0 = t0_OnA if thV > thW: t0 = min(t0_OnA, t0_OfA) """ t0 = min(t0_OnA, t0_OfA) # if t0 < 1.0: # t0 = 1.0 t = np.geomspace(1.0e-1 * t0, min(0.8 * tN, 3 * tN * math.pow(chip, 8.0 / 3.0)), 300) # t = np.geomspace(0.1 * tN * math.pow(chim, 8.0/3.0), # min(0.8*tN, 3*tN*math.pow(chip, 8.0/3.0)), 300) nu = np.empty(t.shape) nu[:] = NU tRes = 1000 vfac = 0.25 Fnu = grb.fluxDensity(t, nu, jetModel, 0, *Y, tRes=tRes, spread=spread) Fnuva = grb.fluxDensity(t, nu / (1.0 + vfac), jetModel, 0, *Y, tRes=tRes, spread=spread) Fnuvb = grb.fluxDensity(t, nu * (1.0 + vfac), jetModel, 0, *Y, tRes=tRes, spread=spread) be = np.log(Fnuvb / Fnuva) / np.log((1 + vfac) * (1 + vfac)) beSpec = slopeSpec(p, 'G') be_err = np.fabs((be - beSpec) / beSpec) good = be_err < 0.01 agood = [] reading = False i1 = -1 i2 = -1 for i in range(len(good)): if good[i] and not reading: i1 = i reading = True if not good[i] and reading: i2 = i reading = False agood.append([i1, i2]) if reading: agood.append([i1, len(good)]) agood = np.array(agood) ngood = agood[:, 1] - agood[:, 0] j = np.argmax(ngood) i1 = agood[j, 0] i2 = agood[j, 1] if printMode is 'all': print(i2 - i1) if plot: if ax is None: fig = plt.figure(figsize=(6, 4)) gs = fig.add_gridspec(4, 1, hspace=0) ax0 = fig.add_subplot(gs[:-1]) ax0.get_xaxis().set_visible(False) ax1 = fig.add_subplot(gs[-1]) ax = [ax0, ax1] ax[0].plot(t, Fnu, lw=4) ax[0].plot(t[i1:i2], Fnu[i1:i2]) al = np.log(Fnu[2:] / Fnu[:-2]) / np.log(t[2:] / t[:-2]) N = len(t) ax[1].plot(t[1:-1], al, lw=4) ax[1].plot(t[max(1, i1):min(i2, N - 1)], al[max(i1 - 1, 0):min(i2 - 1, N - 2)]) ax[0].set_xscale('log') ax[0].set_yscale('log') ax[1].set_xscale('log') t = np.geomspace(t[i1], t[i2 - 1], 100) nu = np.empty(t.shape) nu[:] = NU Fnu = grb.fluxDensity(t, nu, jetModel, 0, *Y, tRes=tRes, spread=spread) if n is 1: y, chi2, n = fit_pl(t, Fnu, plot, printMode) if plot: ax[0].plot(t, f_pl(t, *y)) ax[1].plot(t, al_pl(t, *y)) return 1, y[1] elif n is 2: y, chi2, n = fit_pl2(t, Fnu, tN, thV, thC, printMode) if plot: ax[0].plot(t, f_pl2(t, *y)) ax[1].plot(t, al_pl2(t, *y)) ax[0].axvline(y[1], color='grey', ls='--', alpha=0.5) ax[1].axvline(y[1], color='grey', ls='--', alpha=0.5) return 2, y[1], y[2], y[3] elif n is 3: y, chi2, n = fit_pl3(t, Fnu, tN, thV, thC, printMode) if plot: ax[0].plot(t, f_pl3(t, *y)) ax[1].plot(t, al_pl3(t, *y)) ax[0].axvline(y[1], color='grey', ls='--', alpha=0.5) ax[0].axvline(y[2], color='grey', ls='--', alpha=0.5) ax[1].axvline(y[1], color='grey', ls='--', alpha=0.5) ax[1].axvline(y[2], color='grey', ls='--', alpha=0.5) return 3, y[1], y[2], y[3], y[4], y[5] else: y1, chi21, n1 = fit_pl(t, Fnu, printMode) y2, chi22, n2 = fit_pl2(t, Fnu, tN, thV, thC, printMode) y3, chi23, n3 = fit_pl3(t, Fnu, tN, thV, thC, printMode) rc1 = chi21 / (n1 - 1) rc2 = chi22 / (n2 - 1) rc3 = chi23 / (n3 - 1) if plot: ax[0].plot(t, f_pl(t, *y1), color='C2') ax[0].plot(t, f_pl2(t, *y2), color='C3') ax[0].plot(t, f_pl3(t, *y3), color='C4') ax[1].plot(t, al_pl(t, *y1), color='C2') ax[1].plot(t, al_pl2(t, *y2), color='C3') ax[1].plot(t, al_pl3(t, *y3), color='C4') ax[0].axvline(y2[1], color='C3', ls='--', alpha=0.5) ax[0].axvline(y3[1], color='C4', ls='--', alpha=0.5) ax[0].axvline(y3[2], color='C4', ls='--', alpha=0.5) ax[1].axvline(y2[1], color='C3', ls='--', alpha=0.5) ax[1].axvline(y3[1], color='C4', ls='--', alpha=0.5) ax[1].axvline(y3[2], color='C4', ls='--', alpha=0.5) print(rc1, rc2, rc3) print(y1[-1]) print(y2[-2], y2[-1]) print(y3[-3], y3[-2], y3[-1]) if rc3 < rc2 and rc3 < rc1: return 3, y3[1], y3[2], y3[3], y3[4], y3[5] elif rc2 < rc3 and rc2 < rc1: return 2, y2[1], y2[2], y2[3] else: return 1, y1[1]