本文整理汇总了Python中cc.tools.io.DataIO.testFolderExistence方法的典型用法代码示例。如果您正苦于以下问题:Python DataIO.testFolderExistence方法的具体用法?Python DataIO.testFolderExistence怎么用?Python DataIO.testFolderExistence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.tools.io.DataIO
的用法示例。
在下文中一共展示了DataIO.testFolderExistence方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copyOutput
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def copyOutput(self,entry,old_id,new_id):
'''
Copy modelling output based on model_id.
@param entry: the modeling object for which output is copied
@type entry: Molecule() or Transition()
@param old_id: The old model_id
@type old_id: string
@param new_id: the new_model_id
@type new_id: string
'''
folder_old = os.path.join(cc.path.gout,'models',old_id)
folder_new = os.path.join(cc.path.gout,'models',new_id)
lsprocess = subprocess.Popen('ls %s'%folder_old,shell=True,\
stdout=subprocess.PIPE)
lsfile = lsprocess.communicate()[0].split('\n')
lsfile = [os.path.split(line)[1]
for line in lsfile
if ((line[0:2] == 'ml' or line[0:4] == 'cool') \
and not entry.isMolecule()) \
or line[0:7] == 'coolfgr' \
or line[0:4] == 'para' \
or line[0:5] == 'input']
if not entry.isMolecule():
lsfile = [line
for line in lsfile
if not (line[0:2] == 'ml' \
and line.split('_')[-1].replace('.dat','') \
!= entry.molecule.molecule)]
lsfile = [line
for line in lsfile
if not (line[0:4] == 'cool' \
and (line.split('_')[-1].replace('.dat','') \
!= entry.molecule.molecule \
or line.split('_')[-1].replace('.dat','')=='sampling'\
or line[0:7] == 'coolfgr'))]
new_lsfile = [line.replace(old_id,new_id) for line in lsfile]
DataIO.testFolderExistence(folder_new)
lsprocess = subprocess.Popen('ls %s'%folder_new,shell=True,\
stdout=subprocess.PIPE)
already_done = lsprocess.communicate()[0].split('\n')
for ls,nls in zip(lsfile,new_lsfile):
if not nls in already_done:
subprocess.call(['ln -s %s %s'%(os.path.join(folder_old,ls),\
os.path.join(folder_new,nls))],\
shell=True)
示例2: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __init__(self,code,path,replace_db_entry=0,new_entries=[],\
single_session=0):
"""
Initializing an instance of ModelingSession.
@param code: code for which the modelingsession is created
@type code: string
@param path: modeling output folder in the code's home folder
@type path: string
@keyword replace_db_entry: replace an entry in the database with a
newly calculated model with a new model id
(eg 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 single_session: If this is the only CC session. Speeds up db
check.
(default: 0)
@type single_session: bool
"""
self.path = path
self.code = code
self.model_id = ''
self.replace_db_entry = replace_db_entry
self.new_entries = new_entries
self.single_session = single_session
if code == 'Chemistry':
self.mutable = []
else:
mutablefile = os.path.join(cc.path.aux,\
'Mutable_Parameters_%s.dat'%code)
self.mutable = [line[0]
for line in DataIO.readFile(mutablefile,delimiter=' ')
if ' '.join(line)]
self.mutable = [line for line in self.mutable if line[0] != '#']
fout = os.path.join(getattr(cc.path,self.code.lower()),self.path)
DataIO.testFolderExistence(os.path.join(fout,'models'))
示例3: setOutputFolders
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def setOutputFolders(self):
'''
Set the output folders.
If the folders do not already exist, they are created.
The locations are saved in cc.path for later use, but this is generally
only done inside a ComboCode session. Each module sets these themselves
'''
cc.path.gout = os.path.join(cc.path.gastronoom,self.path_gastronoom)
cc.path.mout = os.path.join(cc.path.mcmax,self.path_mcmax)
DataIO.testFolderExistence(cc.path.gout)
DataIO.testFolderExistence(cc.path.mout)
示例4: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [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=['#','*'])
示例5: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __init__(self,star_name='model',inputfilename=None,\
path='',code='GASTRoNOoM',fn_add_star=1):
"""
Initializing an instance of PlottingSession.
@keyword star_name: name of the star from Star.dat, use default only
when never using any star model specific things
(default: "model")
@type star_name: string
@keyword path: Output modeling folder in code home folder
(default: '')
@type path: string
@keyword inputfilename: name of inputfile that is also copied to the
output folder of the plots,
if None nothing is copied
(default: None)
@type inputfilename: string
@keyword code: the modeling code
(default: GASTRoNOoM)
@type code: string
@keyword fn_add_star: Add the star name to the requested plot filename.
Only relevant if fn_plt is given in a sub method.
(default: 1)
@type fn_add_star: bool
"""
self.inputfilename = inputfilename
self.star_name = star_name
self.star_index = DataIO.getInputData(path=cc.path.usr).index(star_name)
self.star_name_plots = DataIO.getInputData(path=cc.path.usr,
keyword='STAR_NAME_PLOTS',\
remove_underscore=1,\
rindex=self.star_index)
#-- Can't use convenience paths here through cc.path, because the
# module is not code specific. Within a single python session, there
# may be multiple instances of PlottingSession
if not path:
print('Warning! %s model output folder not set.'%code)
self.path = path
fn_mcm = os.path.join(cc.path.aux,'Mutable_Parameters_MCMax.dat')
self.mutable_mcmax = [line[0]
for line in DataIO.readFile(fn_mcm,delimiter=' ')
if ''.join(line).strip()]
self.mutable_mcmax = [line
for line in self.mutable_mcmax
if line[0] != '#']
fn_gas = os.path.join(cc.path.aux,'Mutable_Parameters_GASTRoNOoM.dat')
self.mutable_gastronoom = [line[0]
for line in DataIO.readFile(fn_gas,\
delimiter=' ')
if ''.join(line).strip()]
self.mutable_gastronoom = [line
for line in self.mutable_gastronoom
if line[0] != '#']
self.mutable = self.mutable_mcmax + self.mutable_gastronoom
self.plot_id = 'plot_%.4i-%.2i-%.2ih%.2i-%.2i-%.2i' \
%(gmtime()[0],gmtime()[1],gmtime()[2],\
gmtime()[3],gmtime()[4],gmtime()[5])
self.code = code
#-- Folder management and copying inputfile to plot output folder
pout = os.path.join(getattr(cc.path,self.code.lower()),self.path,\
'stars')
pstar = os.path.join(pout,self.star_name)
self.pplot = os.path.join(pstar,self.plot_id)
for pp in [pout,pstar]:
DataIO.testFolderExistence(pp)
self.fn_add_star = fn_add_star
示例6: setFnPlt
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def setFnPlt(self,fn_plt,fn_suffix='',fn_subfolder=''):
'''
Create a plot filename. The base filename (fn_plt) defines which of 3
cases is requested:
1) path is given, and the object has fn_add_star set to 1.
2) path is given, and the object has fn_add_star set to 0.
3) path is not given, in which case the star name is never added (it
is included in the default folder name)
In all cases, a base filename must be given, and a suffix can be defined
in addition.
Returns empty string if fn_plt is not defined or empty.
@param fn_plt: A plot filename that can be given to each plotting sub
method, or through the cfg file (managed by the sub
method). If not given, each sub method defines a
default. This includes the path if required.
@type fn_plt: string
@keyword fn_suffix: An optional suffix to be appended to the filename
(default: '')
@type fn_suffix: str
@keyword fn_subfolder: An additional subfolder in the default self.pplot
can be added. Not used when path is included in
fn_plt.
(default: '')
@type fn_subfolder: str
@return: The full path + filename without extension is returned.
@rtype: str
'''
if not fn_plt: return ''
#-- Split path and filename, remove extension.
path, pfn = os.path.split(fn_plt)
pfn = os.path.splitext(fn_plt)[0]
#-- Add extra filename segments
if path and self.fn_add_star: pfn = '_'.join([pfn,self.star_name])
if fn_suffix: pfn = '_'.join([pfn,fn_suffix])
#-- Copy inputfilename over to the plot id folder if it is made.
if not path:
DataIO.testFolderExistence(self.pplot)
if not self.inputfilename is None:
ipfn = os.path.split(self.inputfilename)[1]
newf = os.path.join(self.pplot,ipfn)
if not os.path.isfile(newf):
subprocess.call([' '.join(['cp',self.inputfilename,newf])],\
shell=True)
#-- Define default path, check if the path exists
if not path and fn_subfolder:
path = os.path.join(self.pplot,fn_subfolder)
DataIO.testFolderExistence(path)
elif not path:
path = self.pplot
return os.path.join(path,pfn)
示例7: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __init__(self,star_name='model',inputfilename=None,\
path='codeJun2010',code='GASTRoNOoM'):
"""
Initializing an instance of PlottingSession.
@keyword star_name: name of the star from Star.dat, use default only
when never using any star model specific things
(default: "model")
@type star_name: string
@keyword path: Output modeling folder in code home folder
(default: 'codeJun2010')
@type path: string
@keyword inputfilename: name of inputfile that is also copied to the
output folder of the plots,
if None nothing is copied
(default: None)
@type inputfilename: string
@keyword code: the modeling code
(default: GASTRoNOoM)
@type code: string
"""
self.inputfilename = inputfilename
self.star_name = star_name
self.star_index = DataIO.getInputData(path=cc.path.usr)\
.index(self.star_name)
self.star_name_plots = DataIO.getInputData(path=cc.path.usr,
keyword='STAR_NAME_PLOTS',\
remove_underscore=1,\
rindex=self.star_index)
#-- Can't use convenience paths here through cc.path, because the
# module is not code specific. Within a single pything session, there
# may be multiple instances of PlottingSession
self.path = path
fn_mcm = os.path.join(cc.path.aux,'Mutable_Parameters_MCMax.dat')
self.mutable_mcmax = [line[0]
for line in DataIO.readFile(fn_mcm,delimiter=' ')
if ''.join(line).strip()]
self.mutable_mcmax = [line
for line in self.mutable_mcmax
if line[0] != '#']
fn_gas = os.path.join(cc.path.aux,'Mutable_Parameters_GASTRoNOoM.dat')
self.mutable_gastronoom = [line[0]
for line in DataIO.readFile(fn_gas,\
delimiter=' ')
if ''.join(line).strip()]
self.mutable_gastronoom = [line
for line in self.mutable_gastronoom
if line[0] != '#']
self.mutable = self.mutable_mcmax + self.mutable_gastronoom
self.plot_id = 'plot_%.4i-%.2i-%.2ih%.2i-%.2i-%.2i' \
%(gmtime()[0],gmtime()[1],gmtime()[2],\
gmtime()[3],gmtime()[4],gmtime()[5])
self.code = code
#-- Folder management and copying inputfile to plot output folder
pout = os.path.join(getattr(cc.path,self.code.lower()),self.path,\
'stars')
pstar = os.path.join(pout,self.star_name)
self.pplot = os.path.join(pstar,self.plot_id)
for pp in [pout,pstar,self.pplot]:
DataIO.testFolderExistence(pp)
if self.inputfilename <> None:
ipfn = os.path.split(self.inputfilename)[1]
newf = os.path.join(self.pplot,ipfn)
subprocess.call(['cp %s %s'%(self.inputfilename,newf)],shell=True)
示例8: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __init__(self,star_name,instrument_name,oversampling,\
code='GASTRoNOoM',path=None,intrinsic=1,path_linefit='',\
blend_factor=1.2):
"""
Initializing an instance of Instrument.
@param star_name: The name of the star from Star.py
@type star_name: string
@param instrument_name: The name of the instrument (SPIRE or PACS)
@type instrument_name: string
@param oversampling: The instrumental oversampling, for correct
convolution of the Sphinx output.
@type oversampling: int
@keyword code: The radiative transfer code used to model the data
(default: 'GASTRoNOoM')
@type code: string
@keyword path: Output folder in the code's home folder. Used to locate
eg PACS database. If None, no model info required (eg
for line measurement matching/identification)
(default: None)
@type path: string
@keyword intrinsic: Use the intrinsic Sphinx line profiles for
convolving with the spectral resolution? Otherwise
the beam convolved line profiles are used.
(default: 1)
@type intrinsic: bool
@keyword path_linefit: The folder name for linefit results from Hipe
(created by Pierre, assuming his syntax). The
folder is located in $path_pacs$/$star_name$/.
If no folder is given, no linefits are
processed.
(default: '')
@type path_linefit: string
@keyword blend_factor: The relative factor with respect to the intrinsic
instrumental FWHM that is compared with the
fitted Gaussian FWHM to determine whether an
emission line may be blended.
(default: 1.2)
@type blend_factor: float
"""
self.path = path
self.code = code
self.star_name = star_name
self.path_linefit = path_linefit
self.instrument = instrument_name.lower()
self.path_instrument = getattr(cc.path,'d%s'%self.instrument)
self.intrinsic = intrinsic
self.oversampling = int(oversampling)
self.blend_factor = float(blend_factor)
self.data_filenames = []
istar = DataIO.getInputData(keyword='STAR_NAME').index(star_name)
#-- Set relevant velocities in cm/s
self.c = 2.99792458e10
self.vlsr = float(DataIO.getInputData(keyword='V_LSR',rindex=istar))*10**5
if not self.path is None:
pp = getattr(cc.path,self.code.lower())
DataIO.testFolderExistence(os.path.join(pp,self.path,'stars'))
DataIO.testFolderExistence(os.path.join(pp,self.path,'stars',\
self.star_name))
self.readTelescopeProperties()
示例9: doChemistry
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def doChemistry(self,star):
"""
Running Chemistry.
@param star: The parameter set for this session
@type star: Star()
"""
print '***********************************'
#- Create the input dictionary for this Chemistry run
print '** Making input file for Chemistry'
#-- Add the previous model_id to the list of new entries, so it does
# not get deleted if replace_db_entry == 1.
if self.model_id:
self.new_entries.append(self.model_id)
self.model_id = ''
self.command_list = dict()
# Bijzonder gevallen hier ipv in loop over orig
# Dan is input_lines/command_list wat er in de database staat
# input_lines = d
if star['PERFORM_ROUTINE'] == 0:
self.command_list['ROUTINE_RADIUS'] = 0
else:
self.command_list['ROUTINE_RADIUS'] = star['ROUTINE_RADIUS']
#*star['R_STAR']*star.Rsun
self.command_list['R_STAR'] = star['R_STAR']*star.Rsun
#self.command_list['R_INNER_CHEM'] = star['R_INNER_CHEM']*\
#star['R_STAR']*star.Rsun
#self.command_list['R_OUTER_CHEM'] = star['R_OUTER_CHEM']*\
#star['R_STAR']*star.Rsun
self.command_list['REACTIONS_FILE'] = '"'+os.path.join(cc.path.csource,\
'rates',star['REACTIONS_FILE'])+'"'
self.command_list['SPECIES_FILE'] = '"'+os.path.join(cc.path.csource,\
'specs',star['SPECIES_FILE'])+'"'
self.command_list['FILECO'] = '"'+os.path.join(cc.path.csource,\
'shielding',star['FILECO'])+'"'
self.command_list['FILEN2'] = '"'+os.path.join(cc.path.csource,\
star['FILEN2'])+'"'
add_keys = [k
for k in self.standard_inputfile.keys()
if not self.command_list.has_key(k)]
[self.setCommandKey(k,star,star_key=k.upper(),\
alternative=self.standard_inputfile[k])
for k in add_keys]
print '** DONE!'
print '***********************************'
#-- Check the Chemistry database if the model was calculated before
modelbool = self.checkDatabase()
#-- if no match found in database, calculate new model with new model id
#-- if the calculation did not fail, add entry to database for new model
if not modelbool:
input_dict = self.command_list.copy()
input_lines = []
orig = DataIO.readFile(self.inputfilename)
for i,s in enumerate(orig):
split = s.split()
if s[0] == '!':
input_lines.append(s)
else:
input_lines.append(" ".join(split[0:2])+' '+\
str(self.command_list[split[0]]))
output_folder = os.path.join(cc.path.cout,'models',self.model_id)
DataIO.testFolderExistence(output_folder)
input_lines.append('OUTPUT_FOLDER = "' +\
output_folder+'/"')
input_filename = os.path.join(cc.path.cout,'models',\
'inputChemistry_%s.txt'%self.model_id)
DataIO.writeFile(filename=input_filename,input_lines=input_lines)
#subprocess.call(' '.join([cc.path.ccode,input_filename]),shell=True)
subprocess.call(' '.join([os.path.join(cc.path.csource,'csmodel'),input_filename]),shell=True)
# files die worden aangemaakt op einde, test of successvol
testf1 = os.path.join(output_folder,'cscoldens.out')
testf2 = os.path.join(output_folder,'csfrac.out')
if os.path.exists(testf1) and os.path.exists(testf2) and \
os.path.isfile(testf1) and os.path.isfile(testf2):
del self.db[self.model_id]['IN_PROGRESS']
self.db.addChangedKey(self.model_id)
else:
print '** Model calculation failed. No entry is added to ' + \
'the database.'
del self.db[self.model_id]
self.model_id = ''
if not self.single_session: self.db.sync()
#- Note that the model manager now adds/changes MUTABLE input keys,
#- which MAY be overwritten by the input file inputComboCode.dat
print '***********************************'
示例10: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __init__(self,star_name,oversampling,path=None,redo_convolution=0,\
intrinsic=1,path_linefit=''):
'''
Initializing an instance of Pacs().
@param star_name: Name of the star from Star.dat
@type star_name: string
@param oversampling: The PACS instrumental oversampling, for correct
convolution of the Sphinx output]
@type oversampling: int
@keyword path: Output folder in the code's home folder. Used to locate
the PACS database. If None, it is not used (eg for line
measurement matching/identification)
(default: None)
@type path: string
@keyword intrinsic: Use the intrinsic Sphinx line profiles for
convolving with the spectral resolution? Otherwise
the beam convolved line profiles are used.
(default: 1)
@type intrinsic: bool
@keyword redo_convolution: if you want to do the convolution of the
sphinx models regardless of what's already in
the database. The pacs id will not change, nor
the entry in the db, and the old convolved
model will be copied to a backup
(default: 0)
@type redo_convolution: bool
@keyword path_linefit: The folder name for linefit results from Hipe
(created by Pierre, assuming his syntax). The
folder is located in $path_pacs$/$star_name$/.
If no folder is given, no linefits are
processed.
(default: '')
@type path_linefit: string
'''
super(Pacs,self).__init__(star_name=star_name,code='GASTRoNOoM',\
path_linefit=path_linefit,path=path,\
oversampling=oversampling,blend_factor=1.2,\
instrument_name='PACS',intrinsic=intrinsic)
self.data_wave_list = []
self.data_flux_list = []
self.data_ordernames = []
self.data_orders = []
self.data_delta_list = []
self.redo_convolution = redo_convolution
if not self.path is None:
#-- Convenience path
cc.path.gout = os.path.join(cc.path.gastronoom,self.path)
#-- Check the path for the PACS database if a model folder is known
db_path = os.path.join(cc.path.gout,'stars',self.star_name)
if os.path.isdir(db_path):
self.db_path = os.path.join(db_path,'GASTRoNOoM_pacs_models.db')
self.db = Database.Database(self.db_path)
DataIO.testFolderExistence(os.path.join(cc.path.gout,'stars',\
self.star_name,'PACS_results'))
else:
self.db = None
self.db_path = None
self.sphinx_prep_done = 0
self.readLineFit()
示例11: __convolveSphinx
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def __convolveSphinx(self,star):
'''
Check if sphinx output has already been convolved (pacs db) and do so
if not.
@param star: The parameter set
@type star: Star()
'''
#- check for which filenames the convolution has already been done
finished_conv_filenames = self.checkStarDb(star)
finished_conv_filenames = [this_f
for this_f in finished_conv_filenames
if this_f in [os.path.split(f)[1]
for f in self.data_filenames]]
#- if after db check pacs id is undefined, then there is no pacs model,
#- and the convolution will be done anyway
if self.redo_convolution and star['LAST_PACS_MODEL']:
for filename in finished_conv_filenames:
ori = os.path.join(cc.path.gout,'stars',self.star_name,\
'PACS_results',star['LAST_PACS_MODEL'],\
'_'.join(['sphinx',filename]))
backup = os.path.join(cc.path.gout,'stars',self.star_name,\
'PACS_results',star['LAST_PACS_MODEL'],\
'_'.join(['backup','sphinx',filename]))
subprocess.call(['mv %s %s'%(ori,backup)],shell=True)
self.db[star['LAST_PACS_MODEL']]['filenames'] = []
finished_conv_filenames = []
filenames_to_do = [this_f
for this_f in [os.path.split(f)[1]
for f in self.data_filenames]
if this_f not in finished_conv_filenames]
#-Get sphinx model output and merge, for all star models in star_grid
if filenames_to_do:
#- if list is not empty, some filenames still need a convolution
print '* Reading Sphinx model and merging.'
merged = star['LAST_GASTRONOOM_MODEL'] \
and self.mergeSphinx(star) \
or [[],[]]
sphinx_wave = merged[0]
sphinx_flux = merged[1]
if not sphinx_wave:
print '* No Sphinx data found.'
return
#- convolve the model fluxes with a gaussian at central wavelength
#- from data_wave_list for every star, and appropriate sigma
print '* Convolving Sphinx model, after correction for v_lsr.'
if not self.data_delta_list:
self.setDataResolution()
for filename in filenames_to_do:
i_file = [os.path.split(f)[1]
for f in self.data_filenames].index(filename)
if not star['LAST_PACS_MODEL']:
star['LAST_PACS_MODEL'] = \
'pacs_%.4i-%.2i-%.2ih%.2i-%.2i-%.2i'\
%(gmtime()[0],gmtime()[1],gmtime()[2],\
gmtime()[3],gmtime()[4],gmtime()[5])
self.db[star['LAST_PACS_MODEL']] = \
dict([('filenames',[]),\
('trans_list',star.getTransList(dtype='PACS')),\
('cooling_id',star['LAST_GASTRONOOM_MODEL'])])
DataIO.testFolderExistence(\
os.path.join(cc.path.gout,'stars',self.star_name,\
'PACS_results',star['LAST_PACS_MODEL']))
#-- Correct for the v_lsr of the central source
sphinx_wave_corr = array(sphinx_wave)*(1./(1-self.vlsr/self.c))
sph_conv = Data.doConvolution(\
x_in=sphinx_wave_corr,\
y_in=sphinx_flux,\
x_out=self.data_wave_list[i_file],\
widths=self.data_delta_list[i_file],\
oversampling=self.oversampling)
sph_fn = os.path.join(cc.path.gout,'stars',self.star_name,\
'PACS_results',star['LAST_PACS_MODEL'],\
'_'.join(['sphinx',filename]))
DataIO.writeCols(filename=sph_fn,\
cols=[self.data_wave_list[i_file],sph_conv])
self.db[star['LAST_PACS_MODEL']]['filenames'].append(filename)
self.db.addChangedKey(star['LAST_PACS_MODEL'])
示例12: doCooling
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [as 别名]
def doCooling(self,star):
"""
Run Cooling.
First, database is checked for retrieval of old model.
@param star: The parameter set for this session
@type star: Star()
"""
#-- Collect H2O and CO molecule definitions for inclusion in the
# cooling inputfile. Also includes abundance_filename info for H2O if
# requested
if star.getMolecule('1H1H16O') <> None:
h2o_dict = star.getMolecule('1H1H16O').makeDict()
else:
h2o_dict = Molecule('1H1H16O',45,45,648,50).makeDict()
if star.getMolecule('12C16O') <> None:
co_dict = star.getMolecule('12C16O').makeDict()
else:
co_dict = Molecule('12C16O',61,61,240,50).makeDict()
#-- no abundance profiles should be possible for CO.
if co_dict.has_key('MOLECULE_TABLE'):
raise IOError('CO cannot be attributed a custom abundance ' + \
'profile at this time.')
#-- F_H2O is irrelevant if an abundance file is passed for oH2O
if h2o_dict.has_key('MOLECULE_TABLE'):
del self.command_list['F_H2O']
#-- Collect all H2O molecular information important for cooling
molec_dict = dict([(k,h2o_dict[k])
for k in self.cooling_molec_keys
if h2o_dict.has_key(k)])
#-- Check database: only include H2O extra keywords if
# abundance_filename is present. CO can't have this anyway.
model_bool = self.checkCoolingDatabase(molec_dict=molec_dict)
#- Run cooling if above is False
if not model_bool:
DataIO.testFolderExistence(os.path.join(cc.path.gout,'models',\
self.model_id))
commandfile = ['%s=%s'%(k,v)
for k,v in sorted(self.command_list.items())
if k != 'R_POINTS_MASS_LOSS'] + \
['####'] + \
['%s=%s'%(k,co_dict['MOLECULE'])] + \
['%s=%s'%(k,h2o_dict[k])
for k in self.cooling_molec_keys + ['MOLECULE']
if h2o_dict.has_key(k)] + ['####']
if self.command_list.has_key('R_POINTS_MASS_LOSS'):
commandfile.extend(['%s=%s'%('R_POINTS_MASS_LOSS',v)
for v in self.command_list\
['R_POINTS_MASS_LOSS']] + \
['####'])
filename = os.path.join(cc.path.gout,'models',\
'gastronoom_' + self.model_id + '.inp')
DataIO.writeFile(filename,commandfile)
if not self.skip_cooling:
self.execGastronoom(subcode='cooling',filename=filename)
self.cool_done = True
if os.path.isfile(os.path.join(cc.path.gout,'models',\
self.model_id,'coolfgr_all%s.dat'\
%self.model_id)):
#-- Add the other input keywords for cooling to the H2O info.
# This is saved to the db
molec_dict.update(self.command_list)
self.cool_db[self.model_id] = molec_dict
self.cool_db.sync()
else:
print 'Cooling model calculation failed. No entry is added '+ \
'to the database.'
self.model_id = ''
示例13: __init__
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import testFolderExistence [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,\
#.........这里部分代码省略.........