示例#1
0
 def parseProfile(self):
     
     '''
     Parse the sphinx file 2, which includes all line profile info.
     
     The output is stored in dict self['sph2'].
     
     '''
     
     self['sph2'] = dict()
     self['sph2']['nobeam'] = dict()
     self['sph2']['beam'] = dict()
     self['sph2']['nobeam_cont'] = dict()
     self['sph2']['beam_cont'] = dict()
     data = self.getFile(wildcard='2',delimiter=' ')
     data_col_1 = [d[0] for d in data]
     data_i = 6
     data_j = DataIO.findString(data_i,data_col_1)
     self['sph2']['nobeam']['velocity'] = array([float(line[0]) 
                                           for line in data[data_i:data_j]])
     
     #-- Reverse this flux grid. Sphinx output files give the mirrored
     #   flux grid for the associated velocity grid.
     self['sph2']['nobeam']['flux'] = array([DataIO.convertFloat(line[-1],\
                                                                  nans=1) 
                                           for line in data[data_i:data_j]])
     self['sph2']['nobeam']['flux'] = self['sph2']['nobeam']['flux'][::-1]
     data_k = data_j + 4
     data_l = DataIO.findString(data_k,data_col_1)
     self['sph2']['beam']['velocity'] =  array([float(line[0]) 
                                           for line in data[data_k:data_l]])
     self['sph2']['beam']['flux'] =      array([float(line[-1]) 
                                           for line in data[data_k:data_l]])  
     self['sph2']['beam']['norm_flux'] = array([float(line[1]) 
                                           for line in data[data_k:data_l]])
     self['sph2']['beam']['tmb'] =       array([float(line[2]) 
                                           for line in data[data_k:data_l]])
     
     #-- Set the continuum value for the different profiles
     self.setContinuum('nobeam','flux')
     for lp in ['flux','norm_flux','tmb']:
         self.setContinuum('beam',lp)
         
     #-- Check if the velocity is correctly monotonously increasing
     if self['sph2']['beam']['velocity'][0] > self['sph2']['beam']['velocity'][-1]:
         self['sph2']['beam']['velocity'] = self['sph2']['beam']['velocity'][::-1]
         self['sph2']['beam']['flux'] = self['sph2']['beam']['flux'][::-1]
         self['sph2']['beam']['norm_flux'] = self['sph2']['beam']['norm_flux'][::-1]
         self['sph2']['beam']['tmb'] = self['sph2']['beam']['tmb'][::-1]
     if self['sph2']['nobeam']['velocity'][0] > self['sph2']['nobeam']['velocity'][-1]:
         self['sph2']['nobeam']['velocity'] = self['sph2']['nobeam']['velocity'][::-1]
         self['sph2']['nobeam']['flux'] = self['sph2']['nobeam']['flux'][::-1]
     
     #-- Check for NaNs in the profile.
     if True in list(isnan(self['sph2']['nobeam']['flux'])):
         self.nans_present = True
         print "WARNING! There are NaN's in the intrinsic line profile " + \
               "with model id %s:"\
               %(os.path.split(os.path.split(self.fn)[0])[1])
         print os.path.split(self.fn.replace('sph*','sph2'))[1]
示例#2
0
    def parseProfile(self):
        '''
        Parse the sphinx file 2, which includes all line profile info.
        
        The output is stored in dict self.sph2.
        
        '''

        self.sph2 = dict()
        self.contents['sph2'] = self.sph2
        self.sph2['nobeam'] = dict()
        self.sph2['beam'] = dict()
        self.sph2['nobeam_cont'] = dict()
        self.sph2['beam_cont'] = dict()
        data = self.getFile(self.filename.replace('*', '2'))
        data_col_1 = [d[0] for d in data]
        data_i = 6
        data_j = DataIO.findString(data_i, data_col_1)
        self.sph2['nobeam']['velocity'] = array(
            [float(line[0]) for line in data[data_i:data_j]])
        #-- Reverse this flux grid. Sphinx output files give the mirrored
        #   flux grid for the associated velocity grid.
        self.sph2['nobeam']['flux'] =     array([DataIO.convertFloat(line[-1],\
                                                                     nans=1)
                                              for line in data[data_i:data_j]])
        self.sph2['nobeam']['flux'] = self.sph2['nobeam']['flux'][::-1]
        data_k = data_j + 4
        data_l = DataIO.findString(data_k, data_col_1)
        self.sph2['beam']['velocity'] = array(
            [float(line[0]) for line in data[data_k:data_l]])
        self.sph2['beam']['flux'] = array(
            [float(line[-1]) for line in data[data_k:data_l]])
        self.sph2['beam']['norm_flux'] = array(
            [float(line[1]) for line in data[data_k:data_l]])
        self.sph2['beam']['tmb'] = array(
            [float(line[2]) for line in data[data_k:data_l]])

        self.setContinuum('nobeam', 'flux')
        for lp in ['flux', 'norm_flux', 'tmb']:
            self.setContinuum('beam', lp)
        if self.sph2['beam']['velocity'][0] > self.sph2['beam']['velocity'][-1]:
            self.sph2['beam']['velocity'] = self.sph2['beam']['velocity'][::-1]
            self.sph2['beam']['flux'] = self.sph2['beam']['flux'][::-1]
            self.sph2['beam']['norm_flux'] = self.sph2['beam'][
                'norm_flux'][::-1]
            self.sph2['beam']['tmb'] = self.sph2['beam']['tmb'][::-1]
        if self.sph2['nobeam']['velocity'][0] > self.sph2['nobeam'][
                'velocity'][-1]:
            self.sph2['nobeam']['velocity'] = self.sph2['nobeam'][
                'velocity'][::-1]
            self.sph2['nobeam']['flux'] = self.sph2['nobeam']['flux'][::-1]
        if True in list(isnan(self.sph2['nobeam']['flux'])):
            self.nans_present = True
            print "WARNING! There are NaN's in the intrinsic line profile " + \
                  "with model id %s:"\
                  %(os.path.split(os.path.split(self.filename)[0])[1])
            print os.path.split(self.filename.replace('sph*', 'sph2'))[1]
示例#3
0
    def parseProfile(self):

        """
        Parse the sphinx file 2, which includes all line profile info.
        
        The output is stored in dict self.sph2.
        
        """

        self.sph2 = dict()
        self.contents["sph2"] = self.sph2
        self.sph2["nobeam"] = dict()
        self.sph2["beam"] = dict()
        self.sph2["nobeam_cont"] = dict()
        self.sph2["beam_cont"] = dict()
        data = self.getFile(self.filename.replace("*", "2"))
        data_col_1 = [d[0] for d in data]
        data_i = 6
        data_j = DataIO.findString(data_i, data_col_1)
        self.sph2["nobeam"]["velocity"] = array([float(line[0]) for line in data[data_i:data_j]])
        # -- Reverse this flux grid. Sphinx output files give the mirrored
        #   flux grid for the associated velocity grid.
        self.sph2["nobeam"]["flux"] = array([DataIO.convertFloat(line[-1], nans=1) for line in data[data_i:data_j]])
        self.sph2["nobeam"]["flux"] = self.sph2["nobeam"]["flux"][::-1]
        data_k = data_j + 4
        data_l = DataIO.findString(data_k, data_col_1)
        self.sph2["beam"]["velocity"] = array([float(line[0]) for line in data[data_k:data_l]])
        self.sph2["beam"]["flux"] = array([float(line[-1]) for line in data[data_k:data_l]])
        self.sph2["beam"]["norm_flux"] = array([float(line[1]) for line in data[data_k:data_l]])
        self.sph2["beam"]["tmb"] = array([float(line[2]) for line in data[data_k:data_l]])

        self.setContinuum("nobeam", "flux")
        for lp in ["flux", "norm_flux", "tmb"]:
            self.setContinuum("beam", lp)
        if self.sph2["beam"]["velocity"][0] > self.sph2["beam"]["velocity"][-1]:
            self.sph2["beam"]["velocity"] = self.sph2["beam"]["velocity"][::-1]
            self.sph2["beam"]["flux"] = self.sph2["beam"]["flux"][::-1]
            self.sph2["beam"]["norm_flux"] = self.sph2["beam"]["norm_flux"][::-1]
            self.sph2["beam"]["tmb"] = self.sph2["beam"]["tmb"][::-1]
        if self.sph2["nobeam"]["velocity"][0] > self.sph2["nobeam"]["velocity"][-1]:
            self.sph2["nobeam"]["velocity"] = self.sph2["nobeam"]["velocity"][::-1]
            self.sph2["nobeam"]["flux"] = self.sph2["nobeam"]["flux"][::-1]
        if True in list(isnan(self.sph2["nobeam"]["flux"])):
            self.nans_present = True
            print "WARNING! There are NaN's in the intrinsic line profile " + "with model id %s:" % (
                os.path.split(os.path.split(self.filename)[0])[1]
            )
            print os.path.split(self.filename.replace("sph*", "sph2"))[1]
示例#4
0
def convertMCMaxDatabase(path_mcmax):

    """
    Convert MCMax database to the dict format.
    
    This change was made to speed up the use of the database and makes use of 
    the Database() class.
    
    @param path_mcmax: the name of the MCMac subfolder.
    @type path_mcmax: string

    """

    print "** Converting MCMax database to dictionary format..."
    # -- Convenience path
    cc.path.mout = os.path.join(cc.path.mcmax, path_mcmax)
    db_path = os.path.join(cc.path.mout, "MCMax_models.db")
    i = 0
    backup_file = "%s_backup%i" % (db_path, i)
    while os.path.isfile(backup_file):
        i += 1
        backup_file = "%s_backup%i" % (db_path, i)
    subprocess.call(["mv %s %s" % (db_path, backup_file)], shell=True, stdout=subprocess.PIPE)
    mcmax_db = open(backup_file, "r")
    old_db = []
    try:
        while True:
            model = cPickle.load(mcmax_db)
            old_db.append(model)
    except EOFError:
        print "** End of old database reached."
    finally:
        mcmax_db.close()
    db = Database(db_path)
    print "** Inserting entries into the new database."
    for commands, model_id in old_db:
        photon_count = DataIO.convertFloat(commands.pop(0), convert_int=1)
        commands = [c.split("=") for c in commands]
        commanddict = dict(
            [
                (k, DataIO.convertFloat(v, convert_int=1))
                for k, v in commands
                if k[0:4] not in ["opac", "part", "abun", "Tdes", "minr", "maxr"]
            ]
        )
        # - Correcting erroneous input entries in the old version
        if commanddict.has_key("densfile"):
            commanddict["densfile"] = "'%s'" % commanddict["densfile"]
        if not commanddict.has_key("FLD"):
            commanddict["FLD"] = ".false."
        if not commanddict.has_key("randomwalk"):
            commanddict["randomwalk"] = ".true."

        commanddict["photon_count"] = photon_count
        speciespars = [
            (k, DataIO.convertFloat(v, convert_int=1))
            for k, v in commands
            if k[0:4] in ["opac", "part", "abun", "Tdes", "minr", "maxr"]
        ]
        commanddict["dust_species"] = dict()
        i = 0
        while speciespars:
            i += 1
            this_species = dict()
            for k, v in speciespars:
                if int(k[-2:]) == i:
                    if k[:4] == "part" or k[:4] == "opac":
                        speciesfile = v.strip("'")
                    else:
                        this_species[k.strip("%.2i" % i)] = v
            commanddict["dust_species"][os.path.split(speciesfile)[1]] = this_species
            speciespars = [(k, v) for k, v in speciespars if int(k[-2:]) != i]
        db[model_id] = commanddict
    db.sync()
    print "** Done!"
示例#5
0
def convertMCMaxDatabase(path_mcmax):
    
    '''
    Convert MCMax database to the dict format.
    
    This change was made to speed up the use of the database and makes use of 
    the Database() class.
    
    @param path_mcmax: the name of the MCMac subfolder.
    @type path_mcmax: string

    '''
    
    print '** Converting MCMax database to dictionary format...'
    #-- Convenience path
    cc.path.mout = os.path.join(cc.path.mcmax,path_mcmax)
    db_path = os.path.join(cc.path.mout,'MCMax_models.db')
    i = 0
    backup_file = '%s_backup%i'%(db_path,i)
    while os.path.isfile(backup_file):
        i += 1
        backup_file = '%s_backup%i'%(db_path,i)
    subprocess.call(['mv %s %s'%(db_path,backup_file)],\
                    shell=True,stdout=subprocess.PIPE)
    mcmax_db = open(backup_file,'r')
    old_db = []
    try:
        while True:
            model = cPickle.load(mcmax_db)
            old_db.append(model)
    except EOFError:
        print '** End of old database reached.'
    finally:
        mcmax_db.close()
    db = Database(db_path)
    print '** Inserting entries into the new database.'
    for commands,model_id in old_db:
        photon_count = DataIO.convertFloat(commands.pop(0),convert_int=1)
        commands = [c.split('=') for c in commands]
        commanddict = dict([(k,DataIO.convertFloat(v,convert_int=1)) 
                            for k,v in commands 
                            if k[0:4] not in ['opac','part','abun',\
                                              'Tdes','minr','maxr']])
        #- Correcting erroneous input entries in the old version
        if commanddict.has_key('densfile'):
            commanddict['densfile'] = "'%s'"%commanddict['densfile']
        if not commanddict.has_key('FLD'):
            commanddict['FLD'] = '.false.'
        if not commanddict.has_key('randomwalk'):
            commanddict['randomwalk'] = '.true.'
        
        commanddict['photon_count'] = photon_count
        speciespars = [(k,DataIO.convertFloat(v,convert_int=1)) 
                       for k,v in commands 
                       if k[0:4] in ['opac','part','abun',\
                                     'Tdes','minr','maxr']]       
        commanddict['dust_species'] = dict()
        i = 0 
        while speciespars:
            i += 1
            this_species = dict()
            for k,v in speciespars:
                if int(k[-2:]) == i:
                    if k[:4] == 'part' or k[:4] == 'opac':
                        speciesfile = v.strip("'")
                    else:
                        this_species[k.strip('%.2i'%i)] = v
            commanddict['dust_species'][os.path.split(speciesfile)[1]] \
                = this_species
            speciespars = [(k,v) for k,v in speciespars 
                           if int(k[-2:]) != i]
        db[model_id] = commanddict
    db.sync()   
    print '** Done!'