Exemplo n.º 1
0
def test_save_load_xarray_to_HDF5(tmpdir):
    import xarray as xr

    filename = tmpdir.join('test_file.h5')
    test_array = xr.DataArray([1, 2, 3])

    # Test save
    io.save_xarray_to_HDF5(test_array, str(filename))
    assert len(tmpdir.listdir()) == 1

    # Test load
    test_data = io.load_HDF5_to_xarray(str(filename))
    assert_array_equal(test_data.values, [1, 2, 3])
Exemplo n.º 2
0
def test_save_load_xarray_to_HDF5_with_metadata(tmpdir):
    import xarray as xr
    from javelin.unitcell import UnitCell

    filename = tmpdir.join('test_file.h5')
    test_array = xr.DataArray([1, 2, 3])
    test_array.attrs['unit_cell'] = UnitCell(5)

    # Test save
    io.save_xarray_to_HDF5(test_array, str(filename))
    assert len(tmpdir.listdir()) == 1

    # Test load
    test_data = io.load_HDF5_to_xarray(str(filename))
    assert_array_equal(test_data.values, [1, 2, 3])
    assert isinstance(test_data.attrs['unit_cell'], UnitCell)
    assert test_data.attrs['unit_cell'].a == 5