示例#1
0
 def addRadioData(self):
     
     '''
     Add radio data to Transition() objects in all Star() objects.
     
     Only done if RADIO_PATH is given and if a file named radio_data.db is 
     present in the given folder.
     
     If the radio_autosearch flag is on, transitions are automatically 
     generated based on the available data. Note that in this case, N_QUAD
     from Star() is taken. 
     
     '''
     
     if self.radio:
         #-- Get the transition definitions (are in the correct format 
         #   automatically, due to the methods in Radio.py) and make sure 
         #   they are all unique.
         radio_trans = sorted(['%s 100'%tr.replace('TRANSITION=','',1) 
                               for tr in self.radio.keys()])
         radio_trans = DataIO.checkEntryInfo(radio_trans,12,'TRANSITION')
         for star in self.star_grid:
             molecules = [m.molecule for m in star['GAS_LIST']]
             if self.radio_autosearch:
                 n_quad = star['N_QUAD']
                 add_trans = [tr[:-1] + [n_quad] 
                              for tr in radio_trans
                              if tr[0] in molecules]
                 if star.has_key('TRANSITION'):
                     star['TRANSITION'] = list(star['TRANSITION'])
                     star['TRANSITION'].extend(add_trans)
                 else:
                     star['TRANSITION'] = add_trans
             for trans in star['GAS_LINES']:
                 if trans:
                     trstr = trans.getInputString(include_nquad=0)
                     if trstr in self.radio.keys():
                         trans.addDatafile(self.radio[trstr])
示例#2
0
 def readInput(self):
     
     '''
     Read input for ComboCode and return list.
     
     The MOLECULE, TRANSITION and R_POINTS_MASS_LOSS parameter formats are
     checked for errors in this method. If erroneous, an IOError is raised.
     
     '''
     
     multi_keys = ['MOLECULE','TRANSITION','R_POINTS_MASS_LOSS']
     input_dict = DataIO.readDict(self.inputfilename,convert_floats=1,\
                                  convert_ints=1,multi_keys=multi_keys)
     #-- keywords in multi_keys require different method
     self.processed_input = dict()
     self.multiplicative_grid = dict()
     self.additive_grid = dict()
     molecules = input_dict.pop('MOLECULE',[])
     transitions = input_dict.pop('TRANSITION',[])
     r_points_mass_loss = input_dict.pop('R_POINTS_MASS_LOSS',[])      
     for k,v in input_dict.items():
         #-- Fortran input is not case sensitive. Note: use the dict
         #   value v, not input_dict[k] because of this transformation.
         k = k.upper()
         #-- Determine delimiter        
         try:
             if v.find('&') != -1: delimiter = '&'                         
             elif v.find(';') != -1: delimiter = ';'
             elif v.find(',') != -1: delimiter = ','
             elif v.find(':') != -1: delimiter = ':'
             #-- * while no ; or , or : means multiple values for ONE model
             #   Only * star for multiplicative grid makes no sense (just 
             #   give the value without delimiter)
             elif v.find('*') != -1: delimiter = '&'
             else: delimiter = ' '                                                        
         except AttributeError: 
             #-- v is already a float, so can't use .find on it => no grids
             #-- no need to check the rest, continue on with the next k/v pair
             self.processed_input[k] = v
             continue
         #-- Expanding '*' entries: Assumes the value is first, the count 
         #   second. Can't be made flexible, because in some cases the value
         #   cannot be discerned from the count (because both are low-value
         #   integers)
         newv = delimiter.join(\
                     [len(value.split('*')) > 1 
                               and delimiter.join([value.split('*')[0]]*\
                                                   int(value.split('*')[1])) 
                               or value 
                      for value in v.split(delimiter)])
         #-- Add entries to processed_input, the multiplicative grid or the
         #-- additive grid, depending on the type of delimiter.
         if delimiter == ' ':
             self.processed_input[k] = v 
         elif delimiter == ',':
             newv = [float(value) 
                     for value in newv.split(',')]
             newv = Gridding.makeGrid(*newv)
             self.multiplicative_grid[k] = newv
         else:
             try:
                 if delimiter == '&':
                     newv = tuple([float(value.rstrip()) 
                                   for value in newv.split('&')])
                     self.processed_input[k] = newv
                 elif delimiter == ';':
                     newv = [value.rstrip() == '%' and '%' or float(value.rstrip()) 
                             for value in newv.split(';')]
                     self.multiplicative_grid[k] = newv
                 elif delimiter == ':':
                     newv = [value.rstrip() == '%' and '%' or float(value.rstrip()) 
                             for value in newv.split(':')]
                     self.additive_grid[k] = newv
             except ValueError:
                 if delimiter == '&':
                     newv = tuple([value.rstrip() 
                                   for value in newv.split('&')])
                     self.processed_input[k] = newv
                 elif delimiter == ';':
                     newv = [value.rstrip() 
                             for value in newv.split(';')]
                     self.multiplicative_grid[k] = newv
                 elif delimiter == ':':
                     newv = [value.rstrip() 
                             for value in newv.split(':')]
                     self.additive_grid[k] = newv
     #-- Make sure R_POINTS_MASS_LOSS, Molecule and Transition input makes 
     #-- sense and is correct
     if molecules: 
         molecules = DataIO.checkEntryInfo(molecules,20,'MOLECULE')
         if type(molecules) is types.ListType:
             self.additive_grid['MOLECULE'] = molecules
         else:
             self.processed_input['MOLECULE'] = molecules
     if r_points_mass_loss: 
         r_points_mass_loss = DataIO.checkEntryInfo(r_points_mass_loss,4,\
                                                    'R_POINTS_MASS_LOSS')
         if type(r_points_mass_loss) is types.ListType:
             self.additive_grid['R_POINTS_MASS_LOSS'] = r_points_mass_loss
         else:
             self.processed_input['R_POINTS_MASS_LOSS'] = r_points_mass_loss
     if transitions: 
         transitions = DataIO.checkEntryInfo(transitions,12,'TRANSITION')
         if type(transitions) is types.ListType:
             self.additive_grid['TRANSITION'] = transitions
         else:
             self.processed_input['TRANSITION'] = transitions