当前位置: 首页>>代码示例>>Python>>正文


Python DataIO.convertFloat方法代码示例

本文整理汇总了Python中cc.tools.io.DataIO.convertFloat方法的典型用法代码示例。如果您正苦于以下问题:Python DataIO.convertFloat方法的具体用法?Python DataIO.convertFloat怎么用?Python DataIO.convertFloat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.tools.io.DataIO的用法示例。


在下文中一共展示了DataIO.convertFloat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parseProfile

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import convertFloat [as 别名]
 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]
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:62,代码来源:SphinxReader.py

示例2: parseProfile

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import convertFloat [as 别名]
    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]
开发者ID:FungKu01,项目名称:ComboCode,代码行数:50,代码来源:SphinxReader.py

示例3: convertMCMaxDatabase

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import convertFloat [as 别名]
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!"
开发者ID:FungKu01,项目名称:ComboCode,代码行数:77,代码来源:Database.py


注:本文中的cc.tools.io.DataIO.convertFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。