本文整理汇总了Python中pyasdf.ASDFDataSet.add_auxiliary_data_file方法的典型用法代码示例。如果您正苦于以下问题:Python ASDFDataSet.add_auxiliary_data_file方法的具体用法?Python ASDFDataSet.add_auxiliary_data_file怎么用?Python ASDFDataSet.add_auxiliary_data_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasdf.ASDFDataSet
的用法示例。
在下文中一共展示了ASDFDataSet.add_auxiliary_data_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_adding_arbitrary_files
# 需要导入模块: from pyasdf import ASDFDataSet [as 别名]
# 或者: from pyasdf.ASDFDataSet import add_auxiliary_data_file [as 别名]
def test_adding_arbitrary_files(tmpdir):
"""
Tests that adding arbitrary files works.
"""
test_filename = os.path.join(tmpdir.strpath, "temp.json")
test_dict = {"a": 1, "b": 2}
with open(test_filename, "wt") as fh:
json.dump(test_dict, fh, sort_keys=True)
asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
data_set = ASDFDataSet(asdf_filename)
data_set.add_auxiliary_data_file(
test_filename, tag="test_file", parameters={"1": 1})
data_set.__del__()
del data_set
new_data_set = ASDFDataSet(asdf_filename)
# Extraction works the same as always, but now has a special attribute,
# that returns the data as a BytesIO.
aux_data = new_data_set.auxiliary_data.File.test_file
assert aux_data.parameters == {"1": 1}
assert aux_data.tag == "test_file"
new_test_dict = json.loads(aux_data.file.read().decode())
assert test_dict == new_test_dict
aux_data.file.seek(0, 0)
with open(test_filename, "rb") as fh:
assert fh.read() == aux_data.file.read()