Created
June 1, 2015 10:46
-
-
Save keflavich/fdfd584195cd70b91ab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from astroquery.lamda import Lamda, utils | |
| from astropy.utils.console import ProgressBar | |
| import pylab as pl | |
| import itertools | |
| import mpld3 | |
| from mpld3 import plugins as d3p | |
| from brush import LinkedBrush | |
| tem = 20 | |
| maxfreq = 500 | |
| markers = itertools.cycle('*12348HDopsx+') | |
| colors = itertools.cycle('rgbcmyk') | |
| pl.close(1) | |
| pl.figure(1, figsize=(20,10)) | |
| pl.clf() | |
| figure = pl.gcf() | |
| if 'cache' not in locals(): | |
| cache = {} | |
| scatters = [] | |
| labels = [] | |
| for molecule in ProgressBar(Lamda.molecule_dict): | |
| if 'rovib' in molecule: | |
| continue | |
| if molecule in cache: | |
| ncrits, tables = cache[molecule] | |
| else: | |
| try: | |
| tables = Lamda.query(molecule, timeout=30) | |
| except Exception as ex: | |
| print(ex) | |
| continue | |
| try: | |
| ncrits = [utils.ncrit(tables, row['Upper'], row['Lower'], tem) | |
| for row in tables[1] | |
| if row['Frequency'] < maxfreq] | |
| except Exception as ex: | |
| print(ex) | |
| continue | |
| cache[molecule] = (ncrits, tables) | |
| OK = tables[1]['Frequency']<maxfreq | |
| if not any(OK): | |
| continue | |
| scat = pl.scatter(tables[1]['Frequency'][OK], | |
| [np.log10(x.value) for x in ncrits], label=molecule, | |
| marker=markers.next(), color=colors.next(), | |
| edgecolor='none', alpha=0.75) | |
| scatters.append(scat) | |
| labels.append(molecule) | |
| trans_labels = ['{0}_{1}-{2}'.format(molecule, row['Upper'], row['Lower']) | |
| for row in tables[1] | |
| if row['Frequency'] < maxfreq] | |
| tooltip = d3p.PointHTMLTooltip(scat, trans_labels, voffset=10, hoffset=10) | |
| d3p.connect(figure, tooltip) | |
| #pl.yscale('log') | |
| pl.xlabel("Frequency (GHz)") | |
| pl.ylabel("log($n_{crit}$)") | |
| pl.xlim(0,500) | |
| pl.ylim(np.log10(0.1),np.log10(4e7)) | |
| ax = pl.gca() | |
| box = ax.get_position() | |
| ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) | |
| d3p.connect(figure, d3p.InteractiveLegendPlugin(scatters, #ax.collections, | |
| labels, #[L.get_label() for L in ax.collections], | |
| alpha_unsel=0, | |
| alpha_sel=0.5)) | |
| html = mpld3.fig_to_html(figure) | |
| with open('ncrit_vs_frequency_allmols.html', 'w') as f: | |
| f.write(html) | |
| ax.legend(bbox_to_anchor=(1.4, 1.1)) | |
| pl.draw(); pl.show() | |
| pl.savefig("ncrit_vs_frequency_allmols.png", bbox_inches='tight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment