def sio_model(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 if background is not None: tbg = background # assume equal-width channels kwargs = dict(rest=ref_freq) equiv = u.doppler_radio(**kwargs) channelwidth = np.abs(xarr[1].to(u.Hz, equiv) - xarr[0].to(u.Hz, equiv)).value velo = xarr.to(u.km / u.s, equiv).value mol_model = np.zeros_like(xarr).value freqs_ = freqs.to(u.Hz).value Q = m.calculate_partitionfunction(result.data['States'], temperature=tex)[sio.Id] jnu_bg = lte_molecule.Jnu_cgs(xarr.to(u.Hz).value, tbg) bg_model = np.ones_like(xarr).value * jnu_bg for voff, A, g, nu, eu in zip(vdiff, aij, deg, freqs_, EU): tau_per_dnu = lte_molecule.line_tau_cgs(tex, column, Q, g, nu, eu, 10**A) s = np.exp(-(velo - vcen - voff)**2 / (2 * width**2)) * tau_per_dnu / channelwidth jnu_mol = lte_molecule.Jnu_cgs(nu, tex) # the "emission" model is generally zero everywhere, so we can just # add to it as we move along mol_model = mol_model + jnu_mol * (1 - np.exp(-s)) # background is assumed to start as a uniform value, then each # absorption line multiplies to reduce it. s is zero for most velocities, # so this is mostly bg_model *= 1 bg_model *= np.exp(-s) if background: # subtract jnu_bg because we *must* rezero for the case of # having multiple components, otherwise the backgrounds add, # which is nonsense model = bg_model + mol_model - jnu_bg else: model = mol_model return model
def hnco_model(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 # assume equal-width channels #kwargs = dict(rest=ref_freq) #equiv = u.doppler_radio(**kwargs) channelwidth = np.abs(xarr[1].to(u.Hz, ) - xarr[0].to(u.Hz, )).value #velo = xarr.to(u.km/u.s, equiv).value freq = xarr.to(u.Hz).value # same unit as nu below model = np.zeros_like(xarr).value freqs_ = freqs.to(u.Hz).value Q = specmodel.calculate_partitionfunction(result.data['States'], temperature=tex)[hnco.Id] for A, g, nu, eu in zip(aij, deg, freqs_, EU): tau_per_dnu = lte_molecule.line_tau_cgs(tex, column, Q, g, nu, eu, 10**A) width_dnu = width / ckms * nu s = np.exp(-(freq-(1-vcen/ckms)*nu)**2/(2*width_dnu**2))*tau_per_dnu/channelwidth jnu = (lte_molecule.Jnu_cgs(nu, tex)-lte_molecule.Jnu_cgs(nu, tbg)) model = model + jnu*(1-np.exp(-s)) if background is not None: return background-model return model
def ch3cn_model(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 # assume equal-width channels kwargs = dict(rest=ref_freq) equiv = u.doppler_radio(**kwargs) channelwidth = np.abs(xarr[1].to(u.Hz, equiv) - xarr[0].to(u.Hz, equiv)).value velo = xarr.to(u.km/u.s, equiv).value model = np.zeros_like(xarr).value freqs_ = freqs.to(u.Hz).value Q = m.calculate_partitionfunction(result.data['States'], temperature=tex)[ch3cn.Id] for voff, A, g, nu, eu in zip(vdiff, aij, deg, freqs_, EU): tau_per_dnu = lte_molecule.line_tau_cgs(tex, column, Q, g, nu, eu, 10**A) s = np.exp(-(velo-vcen-voff)**2/(2*width**2))*tau_per_dnu/channelwidth jnu = (lte_molecule.Jnu_cgs(nu, tex)-lte_molecule.Jnu_cgs(nu, tbg)) model = model + jnu*(1-np.exp(-s)) 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