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


Python DataIO.readCols方法代码示例

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


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

示例1: mergeOpacity

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
def mergeOpacity(species,lowres='nom_res',highres='high_res'):
    
    '''
    Merge high-res opacities into a grid of low-res opacities.
    
    The wavelength range of the inserted high res opacities is taken from the 
    given high res grid. 
        
    @param species: The dust species for which this is done. This is also the 
                    name of the folder in ~/MCMax/DustOpacities/ that contains
                    the data files.
    @type species: string
    @keyword lowres: The subfolder in ~/MCMax/DustOpacities/species containing
                     the low resolution datafiles.
                   
                     (default: low_res)
    @type lowres: string
    @keyword highres: The subfolder in ~/MCMax/DustOpacities/species containing
                      the high resolution datafiles.
                      
                      (default: high_res)
    @type highres: string
    
    '''
    
    path = os.path.join(cc.path.mopac,species)
    lowres_files = [f 
                    for f in glob(os.path.join(path,lowres,'*')) 
                    if f[-5:] == '.opac']
    highres_files = [f 
                     for f in glob(os.path.join(path,highres,'*')) 
                     if f[-5:] == '.opac']
    files = set([os.path.split(f)[1] for f in lowres_files] + \
                [os.path.split(f)[1] for f in highres_files])
    
    for f in files:
        hdfile = os.path.join(path,highres,f)
        ldfile = os.path.join(path,lowres,f)
        if os.path.isfile(ldfile) and os.path.isfile(hdfile):
            hd = DataIO.readCols(hdfile)
            ld = DataIO.readCols(ldfile)
            hdw = hd[0]
            ldw = ld[0]
            wmin = hdw[0]
            wmax = hdw[-1]
            ld_low = [list(col[ldw<wmin]) for col in ld]
            ld_high = [list(col[ldw>wmax]) for col in ld]
            hd = [list(col) for col in hd]
            merged = [ld_low[i] + hd[i] + ld_high[i] 
                      for i in range(len(hd))]
            DataIO.writeCols(filename=os.path.join(path,f),cols=merged)
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:53,代码来源:DustOpacity.py

示例2: readData

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def readData(self):
     
     '''
     Read the raw SED data. 
     
     '''
     
     for dt,fn in zip(self.data_types,self.data_filenames):
         data = DataIO.readCols(fn,nans=0)
         #-- Currently, error bars only available for these types of data.
         if 'Photometric' in dt or 'MIDI' in dt or 'Sacha' in dt: 
             #-- Sort MIDI data
             if 'MIDI' in dt: 
                 cdat = [dd[(data[0]<=13.)*(data[0]>=8.)] for dd in data]
                 i = argsort(cdat[0])
                 self.data[(dt,fn)] = (cdat[0][i],cdat[1][i],cdat[2][i])
             else:
                 self.data[(dt,fn)] = (data[0],data[1],data[2])
             if  dt == 'Photometric_IvS':
                 self.photbands = data[3]
                 self.photwave = data[0]
         else:
             #-- Still sorting for PACS. Obsolete when separate bands for 
             #   PACS are available. 
             i = argsort(data[0])
             self.data[(dt,fn)] = (data[0][i],data[1][i])
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:28,代码来源:Sed.py

示例3: readData

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def readData(self):
     
     '''
     Read in data, taking special care of NaNs. 
     
     Four colums are taken as input! wave - contsub - original - continuum
     
     Two columns still works, but may result in errors in other places in 
     the code. 
     
     Data are always read in Jy versus micron, for both SPIRE and PACS.
     
     '''
     
     self.data_wave_list = [] 
     self.data_flux_list = []
     self.data_original_list = [] 
     self.data_continuum_list = [] 
     for filename in self.data_filenames:
         data = DataIO.readCols(filename=filename,nans=1)
         self.data_wave_list.append(data[0])
         self.data_flux_list.append(data[1])
         if len(data) == 2: 
             continue
         self.data_original_list.append(data[2])
         self.data_continuum_list.append(data[3])
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:28,代码来源:Instrument.py

示例4: updateDustMCMaxDatabase

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
def updateDustMCMaxDatabase(filename):

    """
    Update dust filenames in MCMax database with the new OPAC_PATH system. 
    
    @param filename: The file and path to the MCMax database. 
    @type filename: str
    
    """

    i = 0
    new_filename = "%s_new" % (filename)

    db_old = Database(filename)
    db_new = Database(new_filename)

    path = os.path.join(cc.path.usr, "Dust_updatefile.dat")
    dustfiles = DataIO.readCols(path)
    pfn_old = list(dustfiles[0])
    pfn_new = list(dustfiles[1])

    for k, v in db_old.items():
        dd = v["dust_species"]
        dd_new = dict()
        for pfn, cont in dd.items():
            try:
                new_key = pfn_new[pfn_old.index(pfn)]
                dd_new[new_key] = cont
            except ValueError:
                dd_new[pfn] = cont
        v["dust_species"] = dd_new
        db_new[k] = v
    db_new.sync()
开发者ID:FungKu01,项目名称:ComboCode,代码行数:35,代码来源:Database.py

示例5: readDustInfo

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
    def readDustInfo(self):

        """
        Read all column densities, min/max temperatures and min/max radii for 
        the species involved in the MCMax model.
        
        Note that the self.coldens dictionary does not give real column 
        densities! This dict merely gives column densities in a prescribed 
        shell with given min and max radius, in order to compare with the H2 
        col density. 
        
        """

        dens = self.star.getDustDensity()
        temp = self.star.getDustTemperature()
        compf = os.path.join(
            cc.path.mcmax, self.star.path_mcmax, "models", self.star["LAST_MCMAX_MODEL"], "composition.dat"
        )
        comp = DataIO.readCols(compf)
        self.rad = comp.pop(0) * self.au
        self.r_outer = self.rad[-1]

        for species in self.star.getDustList():
            # - Save the actual density profile for this dust species, as well
            # - as calculating the full column density of a dust species.
            self.dustfractions[species] = comp.pop(0)
            self.compd[species] = self.dustfractions[species] * dens
            self.fullcoldens[species] = trapz(x=self.rad, y=self.compd[species])
            # - Determine the column density from 90% of the dust species formed
            # - onward, based on the mass fractions!
            # - Not before, because the comparison with H2 must be made,
            # - and this will skew the result if not solely looking at where the
            # - dust has (almost) all been formed.
            # - We also save min amd max radii, for use with the H2 calculation
            a_species = self.star["A_%s" % species]
            maxdens = max(self.compd[species])
            mindens = maxdens * 10 ** (-10)
            radsel = self.rad[(self.dustfractions[species] > 0.9 * a_species) * (self.compd[species] > mindens)]
            denssel = self.compd[species][
                (self.dustfractions[species] > 0.9 * a_species) * (self.compd[species] > mindens)
            ]
            self.coldens[species] = trapz(x=radsel, y=denssel)
            if radsel.size:
                self.r_min_cd[species] = radsel[0]
                self.r_max_cd[species] = radsel[-1]
            else:
                print "Threshold dust mass fraction not reached for %s." % species
                self.r_min_cd[species] = 0
                self.r_max_cd[species] = 0
            # - Determine the actual destruction radius and temperature.
            # - Taken where the density reaches 1% of the maximum density
            # - (not mass fraction).
            self.r_des[species] = self.rad[self.compd[species] > (maxdens * 0.01)][0]
            self.t_des[species] = temp[self.compd[species] > (maxdens * 0.01)][0]

            # - e-10 as limit for minimum is ok, because if shell is 100000 R*
            # - the mass conservation dictates ~ (10^5)^2 = 10^10 (r^2 law)
            # - decrease in density. Shells this big dont occur anyway.
            self.r_max[species] = self.rad[self.compd[species] > mindens][-1]
            self.t_min[species] = temp[self.compd[species] > mindens][-1]
开发者ID:robinlombaert,项目名称:ComboCode,代码行数:62,代码来源:ColumnDensity.py

示例6: getSphinxConvolution

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def getSphinxConvolution(self,star,fn):
     
     '''
     Read the sphinx convolution and return if it has already been done. 
     
     Returns None if the convolution is not available. 
     
     @param star: The Star() object
     @type star: Star()
     @param fn: The filename of the dataset (band) for which the convolution
                is to be returned.
     @type fn: str
     
     @return: The sphinx convolution result. (wavelength, flux)
     @rtype: array
     
     '''
     
     this_id = star['LAST_PACS_MODEL']
     if not this_id:
         return ([],[])
     fn = os.path.split(fn)[1]
     sphinx_file = os.path.join(cc.path.gout,'stars',self.star_name,\
                               'PACS_results',this_id,'%s_%s'%('sphinx',fn))
     return DataIO.readCols(sphinx_file)
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:27,代码来源:Pacs.py

示例7: plotExtinction

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def plotExtinction(self,star_grid=[],models=[],plot_default=1,cfg=''):
     
     """ 
     Plotting wavelength dependent extinction efficiencies wrt grain size.
     
     This always depends on a star_grid or one created from a list of MCMax 
     model ids.
     
     Plotted are the total efficiencies, including relative weights between 
     the included dust species. This is the input for GASTRoNOoM!
     
     @keyword star_grid: List of Star() instances. If default, model ids 
                         have to be given.
                               
                         (default: [])
     @type star_grid: list[Star()]
     @keyword models: The model ids, only required if star_grid is []
     
                      (default: [])
     @type models: list[string]
     @keyword cfg: path to the Plotting2.plotCols config file. If default, 
                   the hard-coded default plotting options are used.
                       
                   (default: '')
     @type cfg: string
     
     """
     
     print '***********************************'
     print '** Plotting Q_ext/a.'
     if not star_grid and not models:
         print 'Input is undefined. Aborting.'
         return      
     elif not star_grid and models:
         star_grid = self.makeMCMaxStars(models=models)
     x = []
     y = []
     keys = []
     for star in star_grid:        
         try:
             inputfile = os.path.join(cc.path.gdata,star['TEMDUST_FILENAME'])
             opacities = DataIO.readCols(filename=inputfile)
             x.append(opacities[0])
             y.append(opacities[1])
             keys.append('$Q_\mathrm{ext}/a$ for MCMax %s'\
                         %star['LAST_MCMAX_MODEL'].replace('_','\_'))
         except IOError: 
             pass
     filename = os.path.join(self.pplot,'gastronoom_opacities_%s'\
                             %star['LAST_MCMAX_MODEL'])
     title = 'GASTRoNOoM Extinction Efficiencies in %s'\
              %(self.star_name_plots)
     filename = Plotting2.plotCols(x=x,y=y,cfg=cfg,filename=filename,\
                                   xaxis='$\lambda$ ($\mu$m)',keytags=keys,\
                                   yaxis='$Q_{ext}/a$ (cm$^{-1}$)',\
                                   plot_title=title,key_location=(0.7,0.6),\
                                   xlogscale=1,ylogscale=1,fontsize_key=20)
     print '** The extinction efficiency plot can be found at:'
     print filename
     print '***********************************'  
开发者ID:FungKu01,项目名称:ComboCode,代码行数:62,代码来源:PlotDust.py

示例8: readModelSpectrum

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
def readModelSpectrum(dpath,rt_sed=1,fn_spec='spectrum45.0.dat'):
     
    '''
    Read the model output spectrum.
     
    If no ray-tracing is requested or no ray-tracing output is found, the 
    average of the MC spectra is taken.
     
    @param dpath: folder that contains the MCMax outputfiles
    @type dpath: string
    
    @keyword rt_sed: If a ray-traced spectrum is requested
     
                     (default: 1)
    @type rt_sed: bool
    @keyword fn_spec: The filename of the ray-traced spectrum. Typically this 
                      is the default name, but can be different depending on 
                      the ray-tracing angle that is used. 
                      Not used if MCSpec are used.
                      
                      (default: spectrum45.0.dat)
    @type fn_spec: str
    
    @return: The wavelength and flux grids (micron,Jy)
    @rtype: (array,array)
     
    '''
     
    rt_sed = int(rt_sed)
    try:    
        if rt_sed:  
            dfile = os.path.join(dpath,fn_spec)
            this_data = DataIO.readCols(dfile)
            #- if the lists are not empty
            if list(this_data[0]) and list(this_data[1]):    
                w = this_data[0]
                f = this_data[1]
            else: raise IOError
        else: raise IOError                                
    except IOError:
        print 'No spectrum was found or ray-tracing is off for ' + \
              'this model. Taking average of theta-grid MCSpectra.'
        dfiles = glob(os.path.join(dpath,'MCSpec*.dat'))
        w = DataIO.readCols(filename=dfiles[0])[0]
        mcy_list = [DataIO.readCols(f)[1] for f in dfiles]
        f = sum(mcy_list)/len(mcy_list)
    return (w,f)
开发者ID:FungKu01,项目名称:ComboCode,代码行数:49,代码来源:MCMax.py

示例9: coolingDbRetrieval

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
def coolingDbRetrieval(path_gastronoom, r_outer=None):

    """    
    Reconstruct a cooling database based on the mline database and the
    GASTRoNOoM inputfiles.
    
    Only works if the water MOLECULE convenience keywords, the MOLECULE R_OUTER
    and/or the MOLECULE ENHANCE_ABUNDANCE_FACTOR keywords were not adapted!
    
    @param path_gastronoom: The path_gastronoom to the output folder
    @type path_gastronoom: string
    
    @keyword r_outer: The outer radius used for the cooling model, regardless
                      of the outer_r_mode parameter.
                      
                      (default: None)
    @type r_outer: float
    
    """

    # -- Convenience path
    cc.path.gout = os.path.join(cc.path.gastronoom, path_gastronoom)

    coolkeys_path = os.path.join(cc.path.aux, "Input_Keywords_Cooling.dat")
    coolkeys = DataIO.readCols(coolkeys_path, make_float=0, make_array=0)[0]
    extra_keys = [
        "ENHANCE_ABUNDANCE_FACTOR",
        "MOLECULE_TABLE",
        "ISOTOPE_TABLE",
        "ABUNDANCE_FILENAME",
        "NUMBER_INPUT_ABUNDANCE_VALUES",
        "KEYWORD_TABLE",
    ]
    coolkeys = [k for k in coolkeys if k not in extra_keys]
    cool_db_path = os.path.join(cc.path.gout, "GASTRoNOoM_cooling_models.db")
    ml_db_path = os.path.join(cc.path.gout, "GASTRoNOoM_mline_models.db")
    subprocess.call(["mv %s %s_backupCoolDbRetrieval" % (cool_db_path, cool_db_path)], shell=True)
    cool_db = Database(db_path=cool_db_path)
    ml_db = Database(db_path=ml_db_path)
    for ml_id in ml_db.keys():
        file_path = os.path.join(cc.path.gout, "models", "gastronoom_%s.inp" % ml_id)
        input_dict = DataIO.readDict(file_path)
        input_dict = dict([(k, v) for k, v in input_dict.items() if k in coolkeys])
        cool_db[ml_id] = input_dict
        if r_outer <> None:
            cool_db[ml_id]["R_OUTER"] = r_outer
    cool_db.sync()
开发者ID:FungKu01,项目名称:ComboCode,代码行数:49,代码来源:Database.py

示例10: parseImpact

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
    def parseImpact(self):

        """ 
        Parse sphinx file 1, which includes all the impact parameter info. 
        
        The output is stored in dict self.sph1.
        
        """

        self.sph1 = dict()
        self.contents["sph1"] = self.sph1
        data = DataIO.readCols(self.filename.replace("*", "1"), start_row=1)
        self.sph1["impact"] = data[0]
        self.sph1["norm_intens"] = data[1]
        self.sph1["weighted_intens"] = data[2]
        self.sph1["sum_intens_p"] = data[3]
        self.sph1["sum_intens"] = data[4]
开发者ID:FungKu01,项目名称:ComboCode,代码行数:19,代码来源:SphinxReader.py

示例11: readVisibilities

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
def readVisibilities(dpath,fn_vis='visibility01.0.dat'):
    
    '''
    Read the model output visibilities, either as function of wavelength or
    baseline. 
     
    @param dpath: folder that contains the MCMax outputfiles
    @type dpath: string
    
    @keyword fn_spec: The filename of the ray-traced visibilities. Typically 
                      this is the default name, but can be different depending 
                      on the inclination (or baseline) that is used. 
                      
                      (default: visibility01.0.dat)
    @type fn_spec: str
    
    @return: A dictionary containing either wavelength or baseline, the flux, 
             and the visibilities for either given baselines or wavelengths
    @rtype: dict
     
    '''
    
    #-- Read file and 
    dfile = os.path.join(dpath,fn_vis)
    if not os.path.isfile(dfile):
        return dict()
    cols, comments = DataIO.readCols(dfile,return_comments=1)
    comments = [comment for comment in comments if comment]
    
    if 'visibility' in fn_vis: 
        xtype = 'wavelength'
        seltype = 'baseline'
    elif 'basevis' in fn_vis: 
        xtype = 'baseline'
        seltype = 'wavelength'
    model = dict()
    model[xtype] = cols[0]
    model['flux'] = cols[1]
    model[seltype] = dict()
    for i,comment in enumerate(comments[2:]):
        val = float(comment.partition(seltype)[2].partition(',')[0])
        model[seltype][val] = cols[2+i]
    return model
开发者ID:FungKu01,项目名称:ComboCode,代码行数:45,代码来源:MCMax.py

示例12: readTxt

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def readTxt(self):
     
     ''' 
     Read the txt file. 
     
     Assumes Tmb flux values in K, with respect to velocity. 
             
     '''
     
     data = DataIO.readCols(filename=self.filename,start_row=0,nans=1)
     if self.filename[-6:] == '.ISPEC':
         del data[0]
         data[0] = data[0]/1000.
     self.contents['velocity'] = data[0]
     self.contents['flux'] = data[1]
     if self.contents['velocity'][0] > self.contents['velocity'][-1]: 
         self.contents['velocity'] = self.contents['velocity'][::-1]
         self.contents['flux'] = self.contents['flux'][::-1]
     self.contents['date_obs'] = 'N.A.'
     self.contents['vlsr'] = None
开发者ID:FungKu01,项目名称:ComboCode,代码行数:22,代码来源:TxtReader.py

示例13: readKappas

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
    def readKappas(self, species):

        """
        Read kappas (cm2/g) and Q_ext/a (cm-1) for a dust species from the 
        MCMax INPUT files. 
        
        This also reads the absorption and scattering kappas separately. 
        
        @param species: The dust species (from Dust.dat)
        @type species: string
                        
        """

        if self.waves.has_key(species):
            return
        try:
            ispecies = self.lspecies.index(species)
        except ValueError:
            print "Species not found in Dust.dat."
            return
        fn = os.path.join(cc.path.mopac, self.lfilenames[ispecies])
        sd = self.lspec_dens[ispecies]
        if fn[-9:] == ".particle":
            part_file = DataIO.readFile(filename=fn, delimiter=" ")
            wav = array([float(q[0]) for q in part_file if len(q) == 4])
            kappa = [
                array([float(q[1]) for q in part_file if len(q) == 4]),
                array([float(q[2]) for q in part_file if len(q) == 4]),
                array([float(q[3]) for q in part_file if len(q) == 4]),
            ]
        else:
            part_file = DataIO.readCols(filename=fn)
            wav = part_file[0]
            kappa = part_file[1:]
        self.spec_dens[species] = sd
        self.fns[species] = fn
        self.waves[species] = wav
        self.kappas[species] = kappa
        self.qext_a[species] = array(kappa) * 4 / 3.0 * sd
开发者ID:robinlombaert,项目名称:ComboCode,代码行数:41,代码来源:KappaReader.py

示例14: parseImpact

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def parseImpact(self):
     
     ''' 
     Parse sphinx file 1, line intensities at line center (!) as a function 
     of impact parameter. 
     
     The output is stored in dict self['sph1'].
     
     Note that the headers of the sph1 file state the last two columns are
     summed intensities. This is not true! It is the intensity at line 
     center.
     
     '''
     
     
     self['sph1'] = dict()
     data = DataIO.readCols(self.fn.replace('*','1'),start_row=1)
     self['sph1']['p'] = data[0]
     self['sph1']['norm_intens'] = data[1] 
     self['sph1']['weighted_intens'] = data[2] 
     self['sph1']['weighted_intens_p^-2'] = data[3]
     self['sph1']['intens'] = data[4]
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:24,代码来源:SphinxReader.py

示例15: readLineFit

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readCols [as 别名]
 def readLineFit(self,**kwargs):
     
     '''
     Read the data from the line fit procedure.
     
     @keyword kwargs: Extra keywords for the readCols method.
                     
                      (default: dict())
     @type kwargs: dict
     
     @return: The line fit columns are returned.
     @rtype: list[array]
     
     '''
     
     fn = os.path.join(self.path_instrument,self.star_name,\
                       self.path_linefit,'lineFitResults')
     if not self.path_linefit or not os.path.isfile(fn):
         self.linefit = None
         return
     dd = DataIO.readCols(fn,make_array=0,**kwargs)
     return dd
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:24,代码来源:Instrument.py


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