@@ -152,6 +152,7 @@ shown below:
152
152
>>> plt.title(' Parititon Fn vs Temp' )
153
153
>>> plt.show()
154
154
155
+ .. plot ::
155
156
156
157
.. figure :: images/docplot_cdms_q.png
157
158
:scale: 50%
@@ -194,11 +195,33 @@ other temperatures using curve fitting models:
194
195
>>> plt.show()
195
196
196
197
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()
202
225
203
226
204
227
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:
210
233
>>> pl.plot(x, (10 ** y- interp_Q)/ 10 ** y)
211
234
>>> pl.xlabel(" Temperature" )
212
235
>>> 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
217
236
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")
219
262
220
263
221
264
Linear interpolation is a good approximation, in this case, for any moderately
0 commit comments