1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
2
import numpy as np
3
+ import requests
3
4
import os
4
5
5
6
from bs4 import BeautifulSoup
@@ -277,7 +278,8 @@ def _parse_result(self, response, *, verbose=False):
277
278
278
279
return result
279
280
280
- def get_species_table (self , * , catfile = 'catdir.cat' ):
281
+ def get_species_table (self , * , catfile = 'catdir.cat' , use_cached = True ,
282
+ catfile_url = conf .catfile_url ):
281
283
"""
282
284
A directory of the catalog is found in a file called 'catdir.cat.'
283
285
@@ -299,8 +301,10 @@ def get_species_table(self, *, catfile='catdir.cat'):
299
301
300
302
"""
301
303
302
- result = ascii .read (data_path ('catdir.cat' ), format = 'csv' ,
303
- delimiter = '|' )
304
+ if use_cached :
305
+ result = ascii .read (data_path (catfile ), format = 'fixed_width' , delimiter = '|' )
306
+ else :
307
+ result = retrieve_catfile (catfile_url )
304
308
305
309
meta = {'lg(Q(1000))' : 1000.0 ,
306
310
'lg(Q(500))' : 500.0 ,
@@ -364,7 +368,7 @@ def find(self, st, flags):
364
368
Can be entered non-specific for broader results
365
369
('H2O' yields 'H2O' but will also yield 'HCCCH2OD')
366
370
or as the specific desired regular expression for
367
- catered results, for example: ('H20 $' yields only 'H2O')
371
+ catered results, for example: ('H2O $' yields only 'H2O')
368
372
369
373
flags : int
370
374
Regular expression flags.
@@ -390,9 +394,24 @@ def find(self, st, flags):
390
394
def build_lookup ():
391
395
392
396
result = CDMS .get_species_table ()
393
- keys = list (result [1 ][:]) # convert NAME column to list
394
- values = list (result [0 ][:]) # convert TAG column to list
397
+ keys = list (result ['molecule' ][:]) # convert NAME column to list
398
+ values = list (result ['tag' ][:]) # convert TAG column to list
395
399
dictionary = dict (zip (keys , values )) # make k,v dictionary
396
400
lookuptable = Lookuptable (dictionary ) # apply the class above
397
401
398
402
return lookuptable
403
+
404
+
405
+ def retrieve_catfile (url = 'https://cdms.astro.uni-koeln.de/classic/entries/partition_function.html' ):
406
+ """
407
+ Simple retrieve index function
408
+ """
409
+ response = requests .get (url )
410
+ response .raise_for_status ()
411
+ tbl = ascii .read (response .text , header_start = None , data_start = 15 , data_end = - 5 ,
412
+ names = ['tag' , 'molecule' , '#lines' , 'lg(Q(1000))' , 'lg(Q(500))' , 'lg(Q(300))' , 'lg(Q(225))' ,
413
+ 'lg(Q(150))' , 'lg(Q(75))' , 'lg(Q(37.5))' , 'lg(Q(18.75))' , 'lg(Q(9.375))' , 'lg(Q(5.000))' ,
414
+ 'lg(Q(2.725))' ],
415
+ col_starts = (0 , 7 , 34 , 41 , 53 , 66 , 79 , 92 , 106 , 117 , 131 , 145 , 159 , 173 ),
416
+ format = 'fixed_width' , delimiter = ' ' )
417
+ return tbl
0 commit comments