def get_raw_tables(query): """(Down)load LAMDA data as astropy tables.""" # lazy import of astropy-related things from astroquery.lamda import Lamda from astroquery.lamda import parse_lamda_datafile # case 1: try to get by URL if query.startswith("http"): name = Path(urlparse(query).path).stem Lamda.molecule_dict[name] = query return Lamda.query(name) # case 2: try to get by local path path = Path(query).expanduser().resolve() if path.exists(): return parse_lamda_datafile(path) # case 3: try to get by astroquery try: return Lamda.query(Path(query).stem) except Exception: raise ValueError(query)
def test_einstein(): transition_freq_list = [(1611.7935180 * u.GHz).to('MHz'), (177.26111120 * u.GHz).to('MHz')] mol_tag_list = [28001, 27001] temp_estimate = 300. * u.K result = [] catalog_result = [] cat = JPLSpec.get_species_table() for i in range(2): transition_freq = transition_freq_list[i] mol_tag = mol_tag_list[i] mol_data = Phys.from_jplspec(temp_estimate, transition_freq, mol_tag) intl = intensity_conversion(mol_data) mol_data.apply([intl.value] * intl.unit, name='intl') au = einstein_coeff(mol_data) result.append(au.value) mol = cat[cat['TAG'] == mol_tag] mol_name = mol['NAME'].data[0] lam_search = Lamda.query(mol=mol_name.lower()) lam_result = lam_search[1] tran = transition_freq.to('GHz').value lam_found = lam_result[lam_result['Frequency'] == tran] au_cat = lam_found['EinsteinA'] au_cat = au_cat.data[0] catalog_result.append(au_cat) err = (abs((np.array(catalog_result) - np.array(result)) / np.array(catalog_result) * 100)) assert np.all(err < 23.5)
def get_datafile(species, savedir='./'): """ Load a molecular data file and save it into the specified directory """ from astroquery.lamda import Lamda datapath = os.path.join(savedir,species) species,suffix = os.path.splitext(species) if suffix == "": datapath += ".dat" elif suffix != ".dat": raise ValueError("Molecular data file must either be a species name or species.dat") if not os.path.isdir(savedir): mkdir_p(savedir) if not os.path.isfile(datapath): data = Lamda.query(species, return_datafile=True) with open(datapath,'w') as out: out.writelines([d+"\n" for d in data]) return os.path.split(datapath)
import pylab as pl from astropy import units as u from astroquery.lamda import Lamda, utils as lamutils from astropy.utils.console import ProgressBar ech3oh = Lamda.query('e-ch3oh') lamutils.ncrit(ech3oh, 256, 253, 100) crates, transitions, levels = ech3oh upperenergy = [ transitions['E_u(K)'][transitions['Upper'] == upper][0] for upper in crates['H2']['Upper'] ] ncrits = [ lamutils.ncrit(ech3oh, upper, lower, 100) for upper, lower in ProgressBar( list(zip(transitions['Upper'], transitions['Lower']))) ] Jvals = { level: int(levels[levels['Level'] == level]['J'][0].split("_")[0]) for level in levels['Level'] } pl.figure(4).clf() pl.semilogy(upperenergy, crates['H2']['C_ij(T=200)'], '.') pl.xlabel("$E_U$ (K)") pl.ylabel("$C_{ij}$ at $T=200$ K") pl.figure(1).clf() pl.semilogy(transitions['Upper'], u.Quantity(ncrits), '.')
import pylab as pl from astropy import units as u from astroquery.lamda import Lamda, utils as lamutils from astropy.utils.console import ProgressBar ech3oh = Lamda.query("e-ch3oh") lamutils.ncrit(ech3oh, 256, 253, 100) crates, transitions, levels = ech3oh upperenergy = [transitions["E_u(K)"][transitions["Upper"] == upper][0] for upper in crates["H2"]["Upper"]] ncrits = [ lamutils.ncrit(ech3oh, upper, lower, 100) for upper, lower in ProgressBar(list(zip(transitions["Upper"], transitions["Lower"]))) ] Jvals = {level: int(levels[levels["Level"] == level]["J"][0].split("_")[0]) for level in levels["Level"]} pl.figure(4).clf() pl.semilogy(upperenergy, crates["H2"]["C_ij(T=200)"], ".") pl.xlabel("$E_U$ (K)") pl.ylabel("$C_{ij}$ at $T=200$ K") pl.figure(1).clf() pl.semilogy(transitions["Upper"], u.Quantity(ncrits), ".") pl.xlabel("Level ID") pl.ylabel("$n_{crit}$ [cm$^{-3}$]") pl.figure(3).clf() pl.semilogy([Jvals[lid] for lid in transitions["Upper"]], u.Quantity(ncrits), ".")