本文整理汇总了Python中tempfile.TemporaryFile.isatty方法的典型用法代码示例。如果您正苦于以下问题:Python TemporaryFile.isatty方法的具体用法?Python TemporaryFile.isatty怎么用?Python TemporaryFile.isatty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile.TemporaryFile
的用法示例。
在下文中一共展示了TemporaryFile.isatty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tempfile import TemporaryFile [as 别名]
# 或者: from tempfile.TemporaryFile import isatty [as 别名]
class Normalizer:
"""
provide an iterator which returns h5 files with a normalizer function.
"""
signal_name_template_met_filter = (
'{}-{stop_mass_gev}-{lsp_mass_gev}-TMF{met_filter_gev:.0f}')
signal_name_template = '{}-{stop_mass_gev}-{lsp_mass_gev}'
def __init__(self,meta_path, hfiles, lumi_fb=20.3, quiet=False):
self.hfiles = hfiles
with open(meta_path) as yml:
self.filter_meta = yaml.load(yml)
self._lumi_fb = lumi_fb
self.signal_prestring = 'scharm'
self.outstream = sys.stdout
self.bugstream = sys.stderr
if quiet:
self.outstream = TemporaryFile('w+')
self.bugstream = TemporaryFile('w+')
self.out_prepend = ''
def _get_matched_signame(self,ds):
"""
this is slightly hackish, but does the right thing by renaming the
physics type.
"""
finder = re.compile(datasets.scharm_re)
stop_finder = re.compile(datasets.stop_re)
stop_finder2 = re.compile(datasets.stop2_re)
for finder in [finder, stop_finder, stop_finder2]:
try:
found = finder.search(ds).group
generator_info = {
'stop_mass_gev': int(found(1)),
'lsp_mass_gev': int(found(2)),
}
namestring = self.signal_name_template
return namestring.format(self.signal_prestring,
**generator_info)
except AttributeError:
pass
return None
def _get_physics_type(self, file_meta):
full_name = file_meta['full_name']
if not 'physics_type' in file_meta:
if full_name.startswith('data'):
physics_type = 'data'
else:
raise OSError('got unknown physics in {}'.format(full_name))
else:
physics_type = file_meta['physics_type']
if 'signal' in physics_type:
physics_type = self._get_matched_signame(full_name)
if not physics_type:
raise OSError("couldn't classify {}".format(full_name))
return physics_type
def _check_for_bugs(self, ds):
full_name = ds['full_name']
if not 'total_xsec_fb' in ds and not full_name.startswith('data'):
self.bugstream.write(
'no cross section for {}, skipping\n'.format(full_name))
return True
if 'n_corrupted_files' in ds:
self.bugstream.write(
'{} bad files in {}\n'.format(ds['n_corrupted_files'],
full_name))
return False
def _get_hist_scaler(self, file_meta):
"""
Factory of scalar factories: the returned function
returns scalar after it's been called on the h5 file
"""
ds_name = file_meta['full_name']
if ds_name.startswith('data'):
def scalar_fact(hfile):
return 1.0
else:
filteff = file_meta['filteff']
xsec = file_meta['total_xsec_fb']
kfactor = file_meta.get('kfactor',1)
n_before_sel = xsec * kfactor * filteff * self._lumi_fb
def scalar_fact(hfile):
sum_evt_weight = hfile.attrs['total_event_weight']
return n_before_sel / sum_evt_weight
return scalar_fact
def _print_prog(self, filenum, numfiles):
if self.outstream and self.outstream.isatty():
self.outstream.write(
'\r{}adding file {} of {}'.format(
self.out_prepend, filenum, numfiles))
self.outstream.flush()
#.........这里部分代码省略.........