def test_hdf5_export_import(): """Try subsequent export and import to pickle.""" data = io_test.gen_example_data() with tempfile.TemporaryDirectory() as tdir: filename = 'test.hdf5' with h5py.File(os.path.join(tdir, filename), 'w') as f: hdf5_io.save_to_hdf5(f, data) with h5py.File(os.path.join(tdir, filename), 'r') as f: data_imported = hdf5_io.load_from_hdf5(f) io_test.assert_equal_data(data_imported, data)
def test_import_from_datadir(fn): print("import ", fn) filename = os.path.join(io_test.datadir, fn) with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=FutureWarning) with h5py.File(filename, 'r') as f: data = hdf5_io.load_from_hdf5(f) if 'version' in data: data_expected = io_test.gen_example_data(data['version']) else: data_expected = io_test.gen_example_data('0.4.0') io_test.assert_equal_data(data, data_expected)
def test_hdf5_export_import(tmp_path): """Try subsequent export and import to pickle.""" data = io_test.gen_example_data() io_test.assert_event_handler_example_works( data) #if this fails, it's not import/export filename = tmp_path / 'test.hdf5' with h5py.File(str(filename), 'w') as f: hdf5_io.save_to_hdf5(f, data) with h5py.File(str(filename), 'r') as f: data_imported = hdf5_io.load_from_hdf5(f) io_test.assert_equal_data(data_imported, data) io_test.assert_event_handler_example_works(data_imported)
def load_data( chi=30, Jx=1., Jy=1., Jz=0., L=3, prefix='data/', ): file_name = full_path(chi, Jx, Jy, Jz, L, prefix=prefix, suffix='.h5') if not Path(file_name).exists(): return -1 with h5py.File(file_name, 'r') as f: data = hdf5_io.load_from_hdf5(f) return data