def simple_flux_from_greybody(lambdavector, Trf = None, b = None, Lrf = None, zin = None, ngal = None): ''' Return flux densities at any wavelength of interest (in the range 1-10000 micron), assuming a galaxy (at given redshift) graybody spectral energy distribution (SED), with a power law replacing the Wien part of the spectrum to account for the variability of dust temperatures within the galaxy. The two different functional forms are stitched together by imposing that the two functions and their first derivatives coincide. The code contains the nitty-gritty details explicitly. Cosmology assumed: H0=70.5, Omega_M=0.274, Omega_L=0.726 (Hinshaw et al. 2009) Inputs: alphain = spectral index of the power law replacing the Wien part of the spectrum, to account for the variability of dust temperatures within a galaxy [default = 2; see Blain 1999 and Blain et al. 2003] betain = spectral index of the emissivity law for the graybody [default = 2; see Hildebrand 1985] Trf = rest-frame temperature [in K; default = 20K] Lrf = rest-frame FIR bolometric luminosity [in L_sun; default = 10^10] zin = galaxy redshift [default = 0.001] lambdavector = array of wavelengths of interest [in microns; default = (24, 70, 160, 250, 350, 500)]; AUTHOR: Lorenzo Moncelsi [[email protected]] HISTORY: 20June2012: created in IDL November2015: converted to Python ''' nwv = len(lambdavector) nuvector = c * 1.e6 / lambdavector # Hz nsed = 1e4 lambda_mod = loggen(1e3, 8.0, nsed) # microns nu_mod = c * 1.e6/lambda_mod # Hz #Lorenzo's version had: H0=70.5, Omega_M=0.274, Omega_L=0.726 (Hinshaw et al. 2009) cosmo = FlatLambdaCDM(H0 = 70.5 * u.km / u.s / u.Mpc, Om0 = 0.273) conversion = 4.0 * np.pi *(1.0E-13 * cosmo.luminosity_distance(zin) * 3.08568025E22)**2.0 / L_sun # 4 * pi * D_L^2 units are L_sun/(Jy x Hz) Lir = Lrf / conversion # Jy x Hz Ain = np.zeros(ngal) + 1.0e-36 #good starting parameter betain = np.zeros(ngal) + b alphain= np.zeros(ngal) + 2.0 fit_params = Parameters() fit_params.add('Ain', value= Ain) #fit_params.add('Tin', value= Trf/(1.+zin), vary = False) #fit_params.add('betain', value= b, vary = False) #fit_params.add('alphain', value= alphain, vary = False) #pdb.set_trace() #THE LM FIT IS HERE #Pfin = minimize(sedint, fit_params, args=(nu_mod,Lir.value,ngal)) Pfin = minimize(sedint, fit_params, args=(nu_mod,Lir.value,ngal,Trf/(1.+zin),b,alphain)) #pdb.set_trace() flux_mJy=sed(Pfin.params,nuvector,ngal,Trf/(1.+zin),b,alphain) return flux_mJy
from VieroLibrary.loggen import loggen from astropy.cosmology import FlatLambdaCDM import astropy.units as u from lmfit import Parameters, minimize, fit_report import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D #pylab.figure() L_sun = 3.839e26 # W c = 299792458.0 # m/s lambdavector = np.array([250,350,500]) nuvector = c * 1.e6 / lambdavector # Hz nsed = 1e4 lambda_mod = loggen(1e3, 8.0, nsed) # microns nu_mod = c * 1.e6/lambda_mod # Hz cosmo = FlatLambdaCDM(H0 = 70.5 * u.km / u.s / u.Mpc, Om0 = 0.273) nz = 5.#20.0#0 nl = 5.#20.0#0 nt = 5.#20.0#0 ngal=1 z_vector = loggen(0.1,5.,nz,linear=1) l_vector = loggen(8.0,13.0,nl,linear=1) t_vector = loggen(10.0,75.0,nt,linear=1) z_l_t_matrix = np.array([z_vector,l_vector,t_vector]) betain = 2.0
import astropy.units as u from lmfit import Parameters, minimize, fit_report #Trf = 20K, b = 2.0, Lrf = 10^13, zin = 0.1, ngal = 1 zin = np.array([0.1]) Lin = np.array([1e13])#,2e12,1e13]) lambdavector = np.array([250,350,500]) nwv = len(lambdavector) L_sun = 3.839e26 # W c = 299792458.0 # m/s nuvector = c * 1.e6 / lambdavector # Hz nsed = 1e4 lambda_mod = loggen(1e3, 8.0, nsed) # microns nu_mod = c * 1.e6/lambda_mod # Hz cosmo = FlatLambdaCDM(H0 = 70.5 * u.km / u.s / u.Mpc, Om0 = 0.273) conversion = 4.0 * np.pi *(1.0E-13 * cosmo.luminosity_distance(zin) * 3.08568025E22)**2.0 / L_sun # 4 * pi * D_L^2 units are L_sun/(Jy x Hz) int_sed = Lin / conversion # Jy x Hz Ain = np.array([1.e-36])#,3.e-36,1.2e-36]) #good starting parameter Tin = np.array([20.0])#,24.0,28.0]) betain = np.array([2.0])#,2.0,2.0]) alphain =np.array([2.0])#,2.0,2.0]) #Ain = np.array([1.e-36]) #good starting parameter #Tin = np.array([23.0]) #betain = np.array([2.0]) #alphain =np.array([2.0])