'einstein_A': 10**-3.80235 / u.s, } ph2co_321.update(ph2co) ph2co_321['dnu'] = (1 * u.km / u.s / constants.c * ph2co_321['frequency']) ph2co_322 = { 'frequency': 218.47563 * u.GHz, 'energy_upper': kb_cgs * 68.0937 * u.K, 'einstein_A': 10**-3.80373 / u.s, } ph2co_322.update(ph2co) ph2co_322['dnu'] = (1 * u.km / u.s / constants.c * ph2co_322['frequency']) print("T=18.75 N=1e10") print("taudnu303 = {0}".format( line_tau(**{k: v for k, v in ph2co_303.items() if k != 'dnu'}))) print("taudnu321 = {0}".format( line_tau(**{k: v for k, v in ph2co_321.items() if k != 'dnu'}))) print("taudnu322 = {0}".format( line_tau(**{k: v for k, v in ph2co_322.items() if k != 'dnu'}))) print("r321/r303 = {0}".format( line_brightness(**ph2co_321) / line_brightness(**ph2co_303))) print("r322/r303 = {0}".format( line_brightness(**ph2co_322) / line_brightness(**ph2co_303))) # CDMS Q import requests import bs4
def lte_model(self, xarr, vcen, width, tex, column, background=None, tbg=2.73): if hasattr(tex, 'unit'): tex = tex.value if hasattr(tbg, 'unit'): tbg = tbg.value if hasattr(column, 'unit'): column = column.value if column < 25: column = 10**column if hasattr(vcen, 'unit'): vcen = vcen.value if hasattr(width, 'unit'): width = width.value ckms = constants.c.to(u.km / u.s).value freq = xarr.to(u.Hz) # same unit as nu below model = np.zeros_like(xarr).value freqs_ = self.freqs.to(u.Hz) #Q = specmodel.calculate_partitionfunction(result.data['States'], # temperature=tex)[ch3ocho.Id] # use a very approximate Q_rot instead of a well-determined one self.Q = Q = (self.all_deg * np.exp(-self.all_EU * u.erg / (constants.k_B * tex * u.K))).sum() for A, g, nu, eu, sijmu2 in zip(self.aij, self.deg, freqs_, self.EU, self.SijMu2): # skip lines that don't have an entry in the appropriate frequency # column (THIS IS BAD - it means we're not necessarily # self-consistently treating freqs above...) if nu == 0: continue width_dnu = width / ckms * nu effective_linewidth_dnu = (2 * np.pi)**0.5 * width_dnu fcen = (1 - vcen / ckms) * nu if np.isfinite(A) and A != 0 and g > 0: taudnu = lte_molecule.line_tau( tex=tex * u.K, total_column=column * u.cm**-2, partition_function=Q, degeneracy=g, frequency=u.Quantity(nu, u.Hz), energy_upper=u.Quantity(eu, u.erg), einstein_A=(10**A) * u.s**-1, ) #log.info("Line: {0} aij: {1}".format(nu, A)) tauspec = (np.exp(-(freq - fcen)**2 / (2 * (width_dnu**2))) * taudnu / effective_linewidth_dnu) else: #log.info("Line: {0} SijMu2: {1} tex: {2} degen: {3}".format(nu, # sijmu2, # tex, # g)) tau = lte_molecule.line_tau_nonquantum( tex=tex * u.K, total_column=column * u.cm**-2, partition_function=Q, degeneracy=g, frequency=u.Quantity(nu, u.Hz), energy_upper=u.Quantity(eu, u.erg), SijMu2=sijmu2 * u.debye**2, molwt=self.molwt * u.Da, ) tauspec = (np.exp(-(freq - fcen)**2 / (2 * (width_dnu**2))) * tau) if np.any(np.isnan(tauspec)): raise ValueError("NaN encountered") jnu = (lte_molecule.Jnu_cgs(nu.to(u.Hz).value, tex) - lte_molecule.Jnu_cgs(nu.to(u.Hz).value, tbg)) model = model + jnu * (1 - np.exp(-tauspec)) if background is not None: return background - model return model
def lte_model(self, xarr, vcen, width, tex, column, background=None, tbg=2.73): if hasattr(tex,'unit'): tex = tex.value if hasattr(tbg,'unit'): tbg = tbg.value if hasattr(column, 'unit'): column = column.value if column < 25: column = 10**column if hasattr(vcen, 'unit'): vcen = vcen.value if hasattr(width, 'unit'): width = width.value ckms = constants.c.to(u.km/u.s).value freq = xarr.to(u.Hz) # same unit as nu below model = np.zeros_like(xarr).value freqs_ = self.freqs.to(u.Hz) #Q = specmodel.calculate_partitionfunction(result.data['States'], # temperature=tex)[ch3ocho.Id] # use a very approximate Q_rot instead of a well-determined one self.Q = Q = (self.all_deg * np.exp(-self.all_EU*u.erg / (constants.k_B * tex*u.K))).sum() for A, g, nu, eu, sijmu2 in zip(self.aij, self.deg, freqs_, self.EU, self.SijMu2): # skip lines that don't have an entry in the appropriate frequency # column (THIS IS BAD - it means we're not necessarily # self-consistently treating freqs above...) if nu == 0: continue width_dnu = width / ckms * nu effective_linewidth_dnu = (2 * np.pi)**0.5 * width_dnu fcen = (1 - vcen/ckms) * nu if np.isfinite(A) and A!=0 and g>0: taudnu = lte_molecule.line_tau(tex=tex*u.K, total_column=column*u.cm**-2, partition_function=Q, degeneracy=g, frequency=u.Quantity(nu, u.Hz), energy_upper=u.Quantity(eu,u.erg), einstein_A=(10**A)*u.s**-1, ) #log.info("Line: {0} aij: {1}".format(nu, A)) tauspec = (np.exp(-(freq - fcen)**2 / (2 * (width_dnu**2))) * taudnu/effective_linewidth_dnu) else: #log.info("Line: {0} SijMu2: {1} tex: {2} degen: {3}".format(nu, # sijmu2, # tex, # g)) tau = lte_molecule.line_tau_nonquantum(tex=tex*u.K, total_column=column*u.cm**-2, partition_function=Q, degeneracy=g, frequency=u.Quantity(nu, u.Hz), energy_upper=u.Quantity(eu, u.erg), SijMu2=sijmu2*u.debye**2, molwt=self.molwt*u.Da,) tauspec = (np.exp(-(freq - fcen)**2 / (2 * (width_dnu**2))) * tau) if np.any(np.isnan(tauspec)): raise ValueError("NaN encountered") jnu = (lte_molecule.Jnu_cgs(nu.to(u.Hz).value, tex) - lte_molecule.Jnu_cgs(nu.to(u.Hz).value, tbg)) model = model + jnu*(1-np.exp(-tauspec)) if background is not None: return background-model return model