Skip to content

Commit 0443a87

Browse files
committed
attempt to use plot directive
1 parent 0bee09c commit 0443a87

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

docs/cdms/cdms.rst

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ shown below:
152152
>>> plt.title('Parititon Fn vs Temp')
153153
>>> plt.show()
154154

155+
.. plot::
155156

156157
.. figure:: images/docplot_cdms_q.png
157158
:scale: 50%
@@ -194,11 +195,33 @@ other temperatures using curve fitting models:
194195
>>> plt.show()
195196

196197

197-
.. figure:: images/docplot_cdms_fitted.png
198-
:scale: 50%
199-
:alt: Plot of Partition Function vs Temperature and resulting Curve Fit
200-
201-
The resulting plot from the example above
198+
.. plot::
199+
import matplotlib.pyplot as plt
200+
from astroquery.linelists.cdms import CDMS
201+
from scipy.optimize import curve_fit
202+
203+
result = CDMS.get_species_table()
204+
mol = result[result['TAG'] == 30501] #do not include signs of TAG for this
205+
from scipy.optimize import curve_fit
206+
def f(T, a):
207+
return np.log10(a*T**(1.5))
208+
keys = [k for k in mol.keys() if 'lg' in k]
209+
def tryfloat(x):
210+
try:
211+
return float(x)
212+
except:
213+
return np.nan
214+
temp = np.array([float(k.split('(')[-1].split(')')[0]) for k in keys])
215+
part = np.array([tryfloat(x) for x in mol[keys][0]])
216+
param, cov = curve_fit(f, temp[np.isfinite(part)], part[np.isfinite(part)])
217+
x = np.linspace(2.7,500)
218+
y = f(x,param[0])
219+
plt.scatter(temp,part,c='r')
220+
plt.plot(x,y,'k')
221+
plt.title('Partition Function vs Temperature')
222+
plt.xlabel('Temperature')
223+
plt.ylabel('Log10 of Partition Function')
224+
plt.show()
202225

203226

204227
We can then compare linear interpolation to the fitted interpolation above:
@@ -210,12 +233,32 @@ We can then compare linear interpolation to the fitted interpolation above:
210233
>>> pl.plot(x, (10**y-interp_Q)/10**y)
211234
>>> pl.xlabel("Temperature")
212235
>>> pl.ylabel("Fractional difference between linear and fitted")
213-
214-
.. figure:: images/docplot_cdms_fitted_vs_linear.png
215-
:scale: 50%
216-
:alt: Plot of the fractional difference between fitted & linear interpolation
217236

218-
The resulting plot from the example above
237+
.. plot::
238+
239+
import matplotlib.pyplot as plt
240+
from astroquery.linelists.cdms import CDMS
241+
from scipy.optimize import curve_fit
242+
243+
result = CDMS.get_species_table()
244+
mol = result[result['TAG'] == 30501] #do not include signs of TAG for this
245+
def f(T, a):
246+
return np.log10(a*T**(1.5))
247+
keys = [k for k in mol.keys() if 'lg' in k]
248+
def tryfloat(x):
249+
try:
250+
return float(x)
251+
except:
252+
return np.nan
253+
x = np.linspace(2.7,500)
254+
y = f(x,param[0])
255+
temp = np.array([float(k.split('(')[-1].split(')')[0]) for k in keys])
256+
part = np.array([tryfloat(x) for x in mol[keys][0]])
257+
param, cov = curve_fit(f, temp[np.isfinite(part)], part[np.isfinite(part)])
258+
interp_Q = np.interp(x, temp, 10**part)
259+
pl.plot(x, (10**y-interp_Q)/10**y)
260+
pl.xlabel("Temperature")
261+
pl.ylabel("Fractional difference between linear and fitted")
219262

220263

221264
Linear interpolation is a good approximation, in this case, for any moderately

0 commit comments

Comments
 (0)