def least_sq(p, fjac): T = p[0] w = p[1] if is_Fj: wbb = w * rf.planck(self.Freq, T, inp="Hz", out="freq") else: wbb = np.pi * w * rf.planck(self.Freq, T, inp="Hz", out="freq") # model interpolation res = np.abs(self.Flux - wbb) return 0, res
def test_fit_bb(self): def func(nu, T): return np.pi * rf.planck(nu, T, inp="Hz", out="freq") self.sp.cut_flux(max(self.sp.Flux) * 1e-5) freq = self.sp.Freq flux = self.sp.Flux Tinit = 1.e4 popt, pcov = curve_fit(func, freq, flux, p0=Tinit) Tbest = popt # bestT, pcov = curve_fit(rf.fit_planck(nu, inp='Hz'), nu, flux, p0=Tinit, sigma=sigma) sigmaT = np.sqrt(np.diag(pcov)) print 'True model values' print ' Tbb = %.2f K' % self.sp.T print 'Parameters of best-fitting model:' print ' T = %.2f +/- %.2f K' % (Tbest, sigmaT) # Tcol = self.sp.temp_color ybest = np.pi * rf.planck(freq, Tbest, inp="Hz", out="freq") # plot the solution plt.plot(freq, flux, 'b*', label='Spectral T: %f' % self.sp.T) plt.plot(freq, ybest, 'r-', label='Best Tcol: %f' % Tbest) plt.xscale('log') plt.yscale('log') plt.legend(loc=3) plt.show() self.assertAlmostEqual(Tbest, self.sp.T, msg="For planck Tcolor [%f] should be equal sp.T [%f]." % (Tbest, self.sp.T), delta=Tbest*0.01)
def test_flux_wl_with_ReddeningLaw(self): import matplotlib.pyplot as plt from pystella.rf.reddening import ReddeningLaw import pystella.rf.rad_func as rf from pystella.util.phys_var import phys wl = np.logspace(3.0, np.log10(5e4), num=100) freq = phys.c / (wl * phys.angs_to_cm) T = 15500. flux = rf.planck(freq, temperature=T) flux_wl = rf.Fnu2Fwl(freq, flux) # flux_wl = flux * freq**2 / phys.c ebv = 0.074 plt.plot(wl, flux_wl, color='black', label='Origin planck T={}'.format(T)) for mode in ReddeningLaw.Modes: x = wl y = flux_reddening_wl(wl, flux_wl, ebv, mode=mode) plt.plot(x, y, label=ReddeningLaw.Names[mode]) plt.legend() plt.xscale("log", nonposx='clip') plt.yscale("log", nonposy='clip') plt.xlabel(r'$\lambda\; [A]$') plt.ylabel(r'$F_\lambda\; [ergs s^{-1} cm^{-2} A^{-1}]$') plt.grid(linestyle=':', linewidth=1) plt.show()
def plot(self): # plot the input model and synthetic data nu = self.sp._freq flux = self.sp.flux_q Tcol = self.sp.T_color ybest = rf.planck(nu, Tcol) # plot the solution plt.plot(nu, flux, 'b*', nu, ybest, 'r-', label='Tinit=%f, Tcol=%f'%(self.sp.Tbb, Tcol)) plt.xscale('log') plt.yscale('log') plt.show()
def plot(self): # plot the input model and synthetic data nu = self.sp.Freq flux = self.sp.Flux Tcol = self.sp.T_color ybest = rf.planck(nu, Tcol) # plot the solution plt.plot(nu, flux, 'b*', nu, ybest, 'r-', label='Tinit=%f, Tcol=%f' % (self.sp.T, Tcol)) plt.xscale('log') plt.yscale('log') plt.show()
def test_fit_bb(self): def func(nu, T): return np.pi * rf.planck(nu, T, inp="Hz", out="freq") self.sp.cut_flux(max(self.sp.Flux) * 1e-5) freq = self.sp.Freq flux = self.sp.Flux Tinit = 1.e4 popt, pcov = curve_fit(func, freq, flux, p0=Tinit) Tbest = float(popt) # bestT, pcov = curve_fit(rf.fit_planck(nu, inp='Hz'), nu, flux, p0=Tinit, sigma=sigma) sigmaT = np.sqrt(np.diag(pcov)) print('True model values') print(' Tbb = %.2f K' % self.sp.T) print('Parameters of best-fitting model:') print(" T = {} +/- {} K".format(Tbest, sigmaT)) # Tcol = self.sp.temp_color ybest = np.pi * rf.planck(freq, Tbest, inp="Hz", out="freq") # plot the solution plt.plot(freq, flux, 'b*', label='Spectral T: %f' % self.sp.T) plt.plot(freq, ybest, 'r-', label='Best Tcol: %f' % Tbest) plt.xscale('log') plt.yscale('log') plt.legend(loc=3) plt.show() self.assertAlmostEqual( Tbest, self.sp.T, msg="For planck Tcolor [{:,f}] should be equal sp.T [{:,f}].". format(Tbest, self.sp.T), delta=Tbest * 0.01)
def func(nu, T): return np.pi * rf.planck(nu, T, inp="Hz", out="freq")
def __init__(self, freq, temperature, W, name='wbb'): freq = np.array(freq) flux = math.pi * W * rf.planck(freq, temperature=temperature) Spectrum.__init__(self, name, freq=freq, flux=flux) self._W = W self._T = temperature
def __init__(self, freq, temperature, name='bb'): flux = math.pi * rf.planck(freq, temperature=temperature) Spectrum.__init__(self, name, freq=freq, flux=flux) self._T = temperature
def __init__(self, freq, temperature, W, name='wbb'): flux = math.pi * W * rf.planck(freq, temperature=temperature) Spectrum.__init__(self, name, freq=freq, flux=flux) self._W = W self._T = temperature