本文整理汇总了Python中pymontecarlo.options.options.Options.read方法的典型用法代码示例。如果您正苦于以下问题:Python Options.read方法的具体用法?Python Options.read怎么用?Python Options.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymontecarlo.options.options.Options
的用法示例。
在下文中一共展示了Options.read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_version6
# 需要导入模块: from pymontecarlo.options.options import Options [as 别名]
# 或者: from pymontecarlo.options.options.Options import read [as 别名]
def _update_version6(self, filepath):
logging.debug('Updating from "version 6"')
hdf5file = h5py.File(filepath, 'r+')
hdf5file.attrs['version'] = b'7' # Change version
hdf5file.attrs['_class'] = b'Results'
# Update root options
options_source = _update_options(hdf5file.attrs['options'])
hdf5file.attrs['options'] = options_source
# Create identifier of results
identifier = Options.read(BytesIO(options_source)).uuid
hdf5file.attrs.create('identifiers', [identifier],
dtype=h5py.special_dtype(vlen=str))
result_groups = list(hdf5file)
group = hdf5file.create_group('result-' + identifier)
group.attrs['options'] = options_source
for result_group in result_groups:
hdf5file[result_group].attrs['_class'] = \
np.string_(hdf5file[result_group].attrs['_class'])
hdf5file.copy(result_group, group)
del hdf5file[result_group]
hdf5file.close()
return self._update_version7(filepath)
示例2: _load
# 需要导入模块: from pymontecarlo.options.options import Options [as 别名]
# 或者: from pymontecarlo.options.options.Options import read [as 别名]
def _load(filepaths, list_options=None):
for filepath in filepaths:
if os.path.isdir(filepath):
_load(glob.glob(os.path.join(filepath, '*.xml')), list_options)
list_options.sort()
return
list_options.append(Options.read(filepath))
示例3: _update_version2
# 需要导入模块: from pymontecarlo.options.options import Options [as 别名]
# 或者: from pymontecarlo.options.options.Options import read [as 别名]
def _update_version2(self, filepath):
logging.debug('Updating from "version 2"')
# Find options
xmlfilepath = os.path.splitext(filepath)[0] + '.xml'
if not os.path.exists(xmlfilepath):
raise ValueError('Update requires an options file saved at %s' % xmlfilepath)
with open(xmlfilepath, 'rb') as fp:
source = fp.read()
source = _update_options(source)
options = Options.read(BytesIO(source))
oldzip = ZipFile(filepath, 'r')
newzip = ZipFile(filepath + ".new", 'w')
# Add options file
fp = BytesIO()
options.write(fp)
newzip.writestr(OPTIONS_FILENAME, fp.getvalue())
# Add other files to new zip
for zipinfo in oldzip.infolist():
data = oldzip.read(zipinfo)
newzip.writestr(zipinfo, data)
# Add version
newzip.comment = b'version=3'
oldzip.close()
newzip.close()
# Remove old zip and replace with new one
os.remove(filepath)
os.rename(filepath + ".new", filepath)
return self._update_version3(filepath)
示例4: _validate
# 需要导入模块: from pymontecarlo.options.options import Options [as 别名]
# 或者: from pymontecarlo.options.options.Options import read [as 别名]
def _validate(self, filepath):
Options.read(filepath)