當前位置: 首頁>>代碼示例>>Python>>正文


Python ASDFDataSet.add_auxiliary_data_file方法代碼示例

本文整理匯總了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()
開發者ID:petrrr,項目名稱:pyasdf,代碼行數:34,代碼來源:test_asdf_data_set.py


注:本文中的pyasdf.ASDFDataSet.add_auxiliary_data_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。