Example use of the grid wrapper and then interactive plot creation
In [1]:
# requires pyradex: grab it from
# https://github.com/keflavich/pyradex/
# Both RADEX and pyradex require a fortran compiler!
# However, if you're on a mac, you can try using pip install with the precompiled binary I provide:
# (this is a source distribution, but it includes the radex.so file)
!pip install https://github.com/keflavich/pyradex/releases/download/0.2/pyradex-0.2.macosx-10.9-intel.tar.gz
In [58]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from matplotlib import pyplot as plt
from IPython.display import clear_output, display, HTML
In [16]:
from pyradex import grid_wrapper
In [69]:
reload(grid_wrapper)
Out[69]:
In [70]:
temperatures = [20,50,100]
densities = np.logspace(2,6,20)
abundances = np.logspace(-8,-10,5)
h2columns = [1e22,1e23]
transition_indices = [0,2,5] #[1,3,6]
orthopararatios = [1e-3,0.5,1,3]
grid = grid_wrapper.grid_wrapper('oh2co-h2',
temperatures=temperatures,
densities=densities,
abundances=abundances,
h2columns=h2columns,
transition_indices=transition_indices,
orthopararatios=orthopararatios,
)
In [72]:
temperatures = [20,50,100]
densities = np.logspace(2,6,20)
abundances = np.logspace(-8,-10,5)
h2columns = [1e22,1e23]
transition_indices = [0,2,5] # [1,3,6]
orthopararatios = [1e-3,0.5,1,3]
grid[0]['source_line_surfbrightness'].shape
Out[72]:
In [89]:
styleargs = {'linewidth': 2, 'alpha': 0.5, 'color':'#5A228B'}
def setup(tem=1,dens=10,opr=0,col=1,abund=0,lineid=0):
fig, ((ax1,ax2),(ax3,ax4)) = plt.subplots(2,2, sharex='col', sharey='row', squeeze=True, figsize=(10,7))
plt.subplots_adjust(hspace=0,wspace=0)
lines1, = ax1.plot(temperatures, grid[lineid]['tau'][opr,col,abund,:,dens], **styleargs)
ax1.set_ylim(-0.2,0.2)
p1, = ax1.plot(temperatures[tem],grid[lineid]['tau'][opr,col,abund,tem,dens], 'o',alpha=0.5, markeredgecolor='none')
lines2, = ax3.plot(temperatures, grid[lineid]['tex'][opr,col,abund,:,dens], **styleargs)
ax3.set_ylim(0,temperatures[tem])
ax3.hlines(2.73,min(temperatures),max(temperatures), linestyle='--')
p3, =ax3.plot(temperatures[tem],grid[lineid]['tex'][opr,col,abund,tem,dens], 'o',alpha=0.5, markeredgecolor='none')
lines3, = ax2.semilogx(densities, grid[lineid]['tau'][opr,col,abund,tem,:], **styleargs)
ax2.set_ylim(-0.2,0.2)
p2, = ax2.plot(densities[dens],grid[lineid]['tau'][opr,col,abund,tem,dens], 'o',alpha=0.5, markeredgecolor='none')
lines4, = ax4.semilogx(densities, grid[lineid]['tex'][opr,col,abund,tem,:], **styleargs)
p4, = ax4.plot(densities[dens],grid[lineid]['tex'][opr,col,abund,tem,dens], 'o',alpha=0.5, markeredgecolor='none')
ax4.set_ylim(0,temperatures[tem])
ax4.hlines(2.73,min(densities),max(densities), linestyle='--')
title = plt.suptitle("$T=%i$ K, $n=10^{%0.1f}$ cm$^{-3}$" % (temperatures[tem],np.log10(densities[dens])),
fontsize=20)
ax4.set_xlabel('$n(H_2)$',fontsize=20)
ax3.set_xlabel("T",fontsize=20)
ax1.set_ylabel(r"$\tau$",fontsize=20)
ax3.set_ylabel("$T_{ex}$",fontsize=20)
plt.show()
return fig,lines1,lines2,lines3,lines4,p1,p2,p3,p4,title
def run_plot_temden():
fig,lines1,lines2,lines3,lines4,p1,p2,p3,p4,title = setup()
@interact(tem=(0,len(temperatures)-1),
dens=(0,len(densities)-1),
opr=(0,len(orthopararatios)-1),
col=(0,len(h2columns)-1),
abund=(0,len(abundances)-1),
lineid=widgets.RadioButtonsWidget(values=transition_indices),
texmax=(0,max(temperatures)))
def plot_temden(tem,dens,opr,col,abund,lineid, texmax):
lines1.set_data(temperatures, grid[lineid]['tau'][opr,col,abund,:,dens])
lines2.set_data(temperatures, grid[lineid]['tex'][opr,col,abund,:,dens])
lines3.set_data(densities, grid[lineid]['tau'][opr,col,abund,tem,:])
lines4.set_data(densities, grid[lineid]['tex'][opr,col,abund,tem,:])
p1.set_data(temperatures[tem],grid[lineid]['tau'][opr,col,abund,tem,dens])
p2.set_data(densities[dens],grid[lineid]['tau'][opr,col,abund,tem,dens])
p3.set_data(temperatures[tem],grid[lineid]['tex'][opr,col,abund,tem,dens])
p4.set_data(densities[dens],grid[lineid]['tex'][opr,col,abund,tem,dens])
title.set_text("$T=%i$ K, $n=10^{%0.1f}$ cm$^{-3}$" % (temperatures[tem],np.log10(densities[dens])))
for p in (p3,p4):
p.axes.set_ylim(0,texmax)
display(fig)
In [90]:
run_plot_temden()
In [ ]: