An incomplete example showing attempts to fit the RADEX parameter space with low-order polynomials
In [1]:
%matplotlib inline
import pylab as pl
In [2]:
import os
if not os.path.exists('oh2co-h2.dat'):
import urllib
urllib.urlretrieve('http://home.strw.leidenuniv.nl/~moldata/datafiles/oh2co-h2.dat')
In [3]:
import pyradex
import numpy as np
tau = np.empty([20,4])
In [4]:
abundance = 10**-8.5
R = pyradex.Radex(species='oh2co-h2', abundance=abundance, column=1e14, temperature=20)
R.run_radex()
Out[4]:
In [5]:
fortho = 1e-3
densities = np.logspace(0,8,20)
for jj,dd in enumerate(densities):
R.density = {'oH2':dd*fortho,'pH2':dd*(1-fortho)}
R.abundance = abundance # reset column to the appropriate value
R.run_radex(reuse_last=False, reload_molfile=True)
tau[jj,:] = R.tau[:4]
In [6]:
pl.loglog(densities,tau,'o')
Out[6]:
In [7]:
fits_7 = [np.polyfit(np.log10(densities),np.log10(t),7) for t in tau.T]
fits_11 = [np.polyfit(np.log10(densities),np.log10(t),11) for t in tau.T]
fits_7
Out[7]:
In [8]:
pl.loglog(densities,tau[:,0],'o')
pl.loglog(densities,10**np.polyval(fits_7[0],np.log10(densities)))
pl.loglog(densities,10**np.polyval(fits_11[0],np.log10(densities)))
Out[8]:
In [9]:
pl.semilogx(densities,abs(tau[:,0]-10**np.polyval(fits_7[0],np.log10(densities)))/tau[:,0])
pl.semilogx(densities,abs(tau[:,0]-10**np.polyval(fits_11[0],np.log10(densities)))/tau[:,0])
Out[9]:
In [22]:
def buildgrid(densities=np.logspace(0,8,20), abundance=10**-8.5, fortho=1e-3, **kwargs):
tau = np.zeros_like(densities)
R = pyradex.Radex(species='co', abundance=abundance, collider_densities={'oH2':10,'pH2':10},
temperature=20)
for jj,dd in enumerate(densities):
R.density = {'oH2':dd*fortho,'pH2':dd*(1-fortho)}
R.abundance = abundance # reset column to the appropriate value
R.run_radex(**kwargs)
tau[jj] = R.tau[0]
return tau
In [23]:
tau1 = buildgrid()
In [24]:
pl.loglog(np.logspace(0,8,20), tau1)
Out[24]:
In [ ]: