本文整理汇总了Python中cc.tools.io.DataIO.readDict方法的典型用法代码示例。如果您正苦于以下问题:Python DataIO.readDict方法的具体用法?Python DataIO.readDict怎么用?Python DataIO.readDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.tools.io.DataIO
的用法示例。
在下文中一共展示了DataIO.readDict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
def __init__(self,path_chemistry='runTest',replace_db_entry=0,db=None,\
single_session=0):
"""
Initializing an instance of ModelingSession.
@keyword db: the Chemistry database
(default: None)
@type db: Database()
@keyword replace_db_entry: replace an entry in the Chemistry database with
a newly calculated model with a new model id
(for instance if some general data not
included in the inputfiles is changed)
(default: 0)
@type replace_db_entry: bool
@keyword path_chemistry: modeling folder in Chemistry home
(default: 'runTest')
@type path_chemistry: string
@keyword new_entries: The new model_ids when replace_db_entry is 1
of other models in the grid. These are not
replaced!
(default: [])
@type new_entries: list[str]
@keyword single_session: If this is the only CC session. Speeds up db
check.
(default: 0)
@type single_session: bool
"""
super(Chemistry, self).__init__(code='Chemistry',path=path_chemistry,\
replace_db_entry=replace_db_entry,\
single_session=single_session)
#-- Convenience path
cc.path.cout = os.path.join(cc.path.chemistry,self.path)
#DataIO.testFolderExistence(os.path.join(cc.path.mout,\
#'data_for_gastronoom'))
self.db = db
#-- If an chemistry model is in progress, the model manager will hold until
# the other cc session is finished.
self.in_progress = False
#- Read standard input file with all parameters that should be included
#- as well as some dust specific information
self.inputfilename = os.path.join(cc.path.aux,'inputChemistry.dat')
self.standard_inputfile = DataIO.readDict(self.inputfilename,\
convert_floats=1,\
convert_ints=1,\
comment_chars=['#','*'])
chemistry_keys = os.path.join(cc.path.aux,'Input_Keywords_Chemistry.dat')
self.chemistry_keywords = [line.strip()
for line in DataIO.readFile(chemistry_keys)
if line]
示例2: coolingDbRetrieval
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [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()
示例3: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
def __init__(self,path_mcmax='runTest',replace_db_entry=0,db=None,\
new_entries=[]):
"""
Initializing an instance of ModelingSession.
@keyword db: the MCMax database
(default: None)
@type db: Database()
@keyword replace_db_entry: replace an entry in the MCMax database with
a newly calculated model with a new model id
(for instance if some general data not
included in the inputfiles is changed)
(default: 0)
@type replace_db_entry: bool
@keyword path_mcmax: modeling folder in MCMax home
(default: 'runTest')
@type path_mcmax: string
@keyword new_entries: The new model_ids when replace_db_entry is 1
of other models in the grid. These are not
replaced!
(default: [])
@type new_entries: list[str]
"""
super(MCMax, self).__init__(code='MCMax',path=path_mcmax,\
replace_db_entry=replace_db_entry,\
new_entries=new_entries)
#-- Convenience path
cc.path.mout = os.path.join(cc.path.mcmax,self.path)
DataIO.testFolderExistence(os.path.join(cc.path.mout,\
'data_for_gastronoom'))
self.db = db
self.mcmax_done = False
#- Read standard input file with all parameters that should be included
#- as well as some dust specific information
inputfilename = os.path.join(cc.path.aux,'inputMCMax.dat')
self.standard_inputfile = DataIO.readDict(inputfilename,\
convert_floats=1,\
convert_ints=1,\
comment_chars=['#','*'])
示例4: readInput
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
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:
#.........这里部分代码省略.........
示例5: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
def __init__(self,star_grid=[],spec=[],franges=[2.6,2.85,3.3,3.7],plot=0,\
func='power',cfg=''):
'''
Initializing a ContinuumDivision instance.
@keyword star_grid: The parameter sets for which the fitting is done
(default: [])
@type star_grid: list[Star()]
@keyword spec: information concerning dust data available for star
(default: [])
@type spec: list[Sed()]
@keyword franges: The fitting ranges for this instance. 4 values in mic,
delimiting 2 parts of the spectrum blueward and
redward of the dust feature. Default is for 3.1
micron ice feature.
Can also give a list of lists, in which case the
franges are defined for every Star() and Sed()
included, such that
len(franges) == len(spec)+len(star_grid). The model
franges are listed first, then the sed franges.
Can also be given through the cfg file, and takes
priority in that case.
(default: [2.6,2.85,3.3,3.7])
@type franges: list[float] or list[list[float]]
@keyword plot: Show the continuum division and fitting plots.
(default: 0)
@type plot: bool
@keyword func: The function used for fitting the continuum. Can be a
list of functions as well, of len == len(star_grid) +
len(spec)
Can also be given through the cfg file, and takes
priority in that case.
(default: power)
@type func: string or list[string]
@keyword cfg: a configuration file for Plotting2.py.
@type cfg: string
'''
self.star_grid = star_grid
self.spec = spec
self.cont_division = dict()
self.eq_width = dict()
self.plot = plot
self.cfg = cfg
if cfg:
cfg_dict = DataIO.readDict(cfg,convert_lists=1,convert_floats=1)
else:
cfg_dict = dict()
if cfg_dict.has_key('franges'):
franges = cfg_dict['franges']
if type(franges[0]) is types.TupleType:
franges = [list(f) for f in franges]
if cfg_dict.has_key('func'):
func = cfg_dict['func']
if type(franges[0]) is types.ListType:
if not len(franges) == (len(spec) + len(star_grid)):
print 'Not enough sets of franges defined for all Star() and'+\
' Sed() objects. Taking first set for all.'
self.franges = [sorted(franges[0])
for i in range(len(spec)+len(star_grid))]
else:
self.franges = [sorted(fr) for fr in franges]
else:
self.franges = [sorted(franges)
for i in range(len(spec)+len(star_grid))]
self.frmin = min([min(fr) for fr in self.franges])
self.frmax = max([max(fr) for fr in self.franges])
if type(func) is types.ListType:
if not len(func) == (len(spec) + len(star_grid)):
print 'Not enough functions defined for all Star() and'+\
' Sed() objects. Taking first func for all.'
self.func = [func[0] for i in range(len(spec)+len(star_grid))]
else:
self.func = func
else:
self.func = [func
for i in range(len(spec)+len(star_grid))]
示例6: __readML1
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
def __readML1(self):
'''
Read molecule spectroscopic properties and basic circumstellar radial
profiles from the ml1 file.
This is the information that is returned by MolReader methods.
Note that the level indexing is J + 1 for simple molecules like CO. For
any molecule, the 0-energy level has index 1!
Note also that the vel in the ml1 file is the velocity profile divided
by the stochastic velocity. (see source_common/vel.f) The velocity
profile saved here is the real velocity profile, corrected for this.
'''
#-- Molecule settings are in ml1
fn = self.fn.replace('ml*','ml1')
#-- First block contains keywords, so use readDict
d1 = DataIO.readDict(filename=fn,start_row=8,end_row=38,\
convert_floats=1,convert_ints=1,\
key_modifier='lower')
self['pars'] = d1
#-- Number of header lines: number of pars, 9 lines in first header, 1
# line with column names.
nhdr = len(d1) + 9 + 1
#-- Second block contains transitions
d2 = np.genfromtxt(fn,usecols=[0,1,2,3,4],skip_header=nhdr,\
dtype='i8,i8,i8,f8,f8',max_rows=d1['nline'],\
names=['index','lup','llow','frequency','einsteinA'])
#-- Add 1 to the lup and llow columns so they match up with the indices
# of the levels (for some reason j = 0 level is given as index 0 for
# llow in the transition definition, while the level index is actually
# 1). While for J-numbers this works, this approach breaks down for eg
# H2O.
d2['lup'] += 1
d2['llow'] += 1
self['trans'] = d2
#-- Third block contains levels (note hdr contains line with col names)
nhdr += d1['nline'] + 1
d3 = np.genfromtxt(fn,skip_header=nhdr,max_rows=d1['ny'],\
dtype='i8,f8,f8',names=['index','weight','energy'])
self['level'] = d3
#-- Fourth block contains circumstellar properties as a function of
# impact parameter (note that P1 = R_outer, Pmax = R_star, so reverse)
nhdr += d1['ny']
colnames = ['p_rstar','vel','nmol','nh2','amol','Tg','Td']
d4 = np.genfromtxt(fn,names=colnames,\
skip_header=nhdr,max_rows=d1['n_impact'])[::-1]
d4['vel'] *= d1['vsto']
self['props'] = d4
#-- Add a convenient reference to the instance dict so PopReader and
# MolReader parent methods can work with the impact parameter grid.
# R_STAR is given in cm.
self['p'] = d4['p_rstar'] * self['pars']['r_star']
示例7: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import readDict [as 别名]
def __init__(self,path_gastronoom='runTest',vic=None,sphinx=0,\
replace_db_entry=0,cool_db=None,ml_db=None,sph_db=None,\
skip_cooling=0,recover_sphinxfiles=0,\
new_entries=[]):
"""
Initializing an instance of a GASTRoNOoM modeling session.
A single cooling model and a given set of molecules and transitions are
calculated here or are retrieved from the databases.
@keyword path_gastronoom: modeling folder in GASTRoNOoM home
(default: 'runTest')
@type path_gastronoom: string
@keyword vic: the vic manager for running sphinx models on VIC3
(default: None)
@type vic: Vic()
@keyword sphinx: Running Sphinx?
(default: 0)
@type sphinx: bool
@keyword replace_db_entry: replace an entry in the databases with a
newly calculated model with a new model id
(e.g. if some general data not included in
the inputfiles is changed)
(default: 0)
@type replace_db_entry: bool
@keyword new_entries: The new model_ids when replace_db_entry is 1
of other models in the grid. These are not
replaced!
(default: [])
@type new_entries: list[str]
@keyword skip_cooling: Skip running cooling in case a model is not
found in the database, for instance if it is
already known that the model will fail
(default: 0)
@type skip_cooling: bool
@keyword recover_sphinxfiles: Try to recover sphinx files from the disk
in case they were correctly calculated,
but not saved to the database for one
reason or another.
(default: 0)
@type recover_sphinxfiles: bool
@keyword cool_db: the cooling database
(default: None)
@type cool_db: Database()
@keyword ml_db: the mline database
(default: None)
@type ml_db: Database()
@keyword sph_db: the sphinx database
(default: None)
@type sph_db: Database()
"""
super(Gastronoom,self).__init__(code='GASTRoNOoM',\
path=path_gastronoom,\
replace_db_entry=replace_db_entry,\
new_entries=new_entries)
#-- Convenience path
cc.path.gout = os.path.join(cc.path.gastronoom,self.path)
self.vic = vic
self.trans_in_progress = []
self.sphinx = sphinx
cool_keys = os.path.join(cc.path.aux,'Input_Keywords_Cooling.dat')
ml_keys = os.path.join(cc.path.aux,'Input_Keywords_Mline.dat')
sph_keys = os.path.join(cc.path.aux,'Input_Keywords_Sphinx.dat')
self.cooling_keywords = [line.strip()
for line in DataIO.readFile(cool_keys)
if line]
self.mline_keywords = [line.strip()
for line in DataIO.readFile(ml_keys)
if line]
self.sphinx_keywords = [line.strip()
for line in DataIO.readFile(sph_keys)
if line]
DataIO.testFolderExistence(os.path.join(cc.path.gout,'data_for_mcmax'))
self.trans_bools = []
self.mline_done = False
self.cool_done = False
self.cooling_molec_keys = ['ENHANCE_ABUNDANCE_FACTOR',\
'ABUNDANCE_FILENAME',\
'NUMBER_INPUT_ABUNDANCE_VALUES',\
'KEYWORD_TABLE','MOLECULE_TABLE',\
'ISOTOPE_TABLE']
self.no_ab_molecs = ['12C16O','13C16O','1H1H16O','p1H1H16O',\
'1H1H17O','p1H1H17O','1H1H18O','p1H1H18O']
#- Read standard input file with all parameters that should be included
filename = os.path.join(cc.path.aux,'inputGASTRoNOoM.dat')
self.standard_inputfile = DataIO.readDict(filename,\
#.........这里部分代码省略.........