How to use hickle - 10 common examples

To help you get started, we’ve selected a few hickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github telegraphic / hickle / tests / test_hickle.py View on Github external
def test_list_order():
    """ https://github.com/telegraphic/hickle/issues/26 """
    d = [np.arange(n + 1) for n in range(20)]
    hickle.dump(d, 'test.h5')
    d_hkl = hickle.load('test.h5')
    
    try:
        for ii, xx in enumerate(d):
            assert d[ii].shape == d_hkl[ii].shape
        for ii, xx in enumerate(d):
            assert np.allclose(d[ii], d_hkl[ii])
    except AssertionError:
        print(d[ii], d_hkl[ii])
        raise
github telegraphic / hickle / tests / test_astropy.py View on Github external
def test_astropy_angle():
    for uu in ['radian', 'degree']:
        a = Angle(1.02, unit=uu)

        hkl.dump(a, "test_ap.h5")
        b = hkl.load("test_ap.h5")
        assert a == b
        assert a.unit == b.unit
github telegraphic / hickle / tests / test_astropy.py View on Github external
def test_astropy_time_array():
    times = ['1999-01-01T00:00:00.123456789', '2010-01-01T00:00:00']
    t1 = Time(times, format='isot', scale='utc')
    hkl.dump(t1, "test_ap2.h5")
    t2 = hkl.load("test_ap2.h5")

    print(t1)
    print(t2)
    assert t1.value.shape == t2.value.shape
    for ii in range(len(t1)):
        assert t1.value[ii] == t2.value[ii]
    assert t1.format == t2.format
    assert t1.scale == t2.scale

    times = [58264, 58265, 58266]
    t1 = Time(times, format='mjd', scale='utc')
    hkl.dump(t1, "test_ap2.h5")
    t2 = hkl.load("test_ap2.h5")

    print(t1)
    print(t2)
github telegraphic / hickle / tests / test_hickle.py View on Github external
def test_list_order():
    """ https://github.com/telegraphic/hickle/issues/26 """
    d = [np.arange(n + 1) for n in range(20)]
    hickle.dump(d, 'test.h5')
    d_hkl = hickle.load('test.h5')

    try:
        for ii, xx in enumerate(d):
            assert d[ii].shape == d_hkl[ii].shape
        for ii, xx in enumerate(d):
            assert np.allclose(d[ii], d_hkl[ii])
    except AssertionError:
        print(d[ii], d_hkl[ii])
        raise
github telegraphic / hickle / tests / test_hickle_dev.py View on Github external
def test_ndarray():

    a = np.array([1,2,3])
    b = np.array([2,3,4])
    z = (a, b)

    print "Original:"
    pprint(z)
    dump(z, 'test.hkl', mode='w')

    print "\nReconstructed:"
    z = load('test.hkl')
    pprint(z)
github telegraphic / hickle / tests / test_hickle.py View on Github external
def test_embedded_array():
    """ See https://github.com/telegraphic/hickle/issues/24 """

    d_orig = [[np.array([10., 20.]), np.array([10, 20, 30])], [np.array([10, 2]), np.array([1.])]]
    hickle.dump(d_orig, 'test.h5')
    d_hkl = hickle.load('test.h5')

    for ii, xx in enumerate(d_orig):
        for jj, yy in enumerate(xx):
            assert np.allclose(d_orig[ii][jj], d_hkl[ii][jj])

    print(d_hkl)
    print(d_orig)
github telegraphic / hickle / tests / test_scipy.py View on Github external
sm0 = csr_matrix((3, 4), dtype=np.int8).toarray()

    row = np.array([0, 0, 1, 2, 2, 2])
    col = np.array([0, 2, 2, 0, 1, 2])
    data = np.array([1, 2, 3, 4, 5, 6])
    sm1 = csr_matrix((data, (row, col)), shape=(3, 3))
    sm2 = csc_matrix((data, (row, col)), shape=(3, 3))

    indptr = np.array([0, 2, 3, 6])
    indices = np.array([0, 2, 2, 0, 1, 2])
    data = np.array([1, 2, 3, 4, 5, 6]).repeat(4).reshape(6, 2, 2)
    sm3 = bsr_matrix((data,indices, indptr), shape=(6, 6))

    hickle.dump(sm1, 'test_sp.h5')
    sm1_h = hickle.load('test_sp.h5')
    hickle.dump(sm2, 'test_sp2.h5')
    sm2_h = hickle.load('test_sp2.h5')
    hickle.dump(sm3, 'test_sp3.h5')
    sm3_h = hickle.load('test_sp3.h5')

    assert isinstance(sm1_h, csr_matrix)
    assert isinstance(sm2_h, csc_matrix)
    assert isinstance(sm3_h, bsr_matrix)

    assert np.allclose(sm1_h.data, sm1.data)
    assert np.allclose(sm2_h.data, sm2.data)
    assert np.allclose(sm3_h.data, sm3.data)

    assert sm1_h. shape == sm1.shape
    assert sm2_h. shape == sm2.shape
    assert sm3_h. shape == sm3.shape
github telegraphic / hickle / tests / test_hickle_helpers.py View on Github external
def test_check_is_scipy_sparse_array():
    t_csr = scipy.sparse.csr_matrix([0])
    t_csc = scipy.sparse.csc_matrix([0])
    t_bsr = scipy.sparse.bsr_matrix([0])
    assert check_is_scipy_sparse_array(t_csr) is True
    assert check_is_scipy_sparse_array(t_csc) is True
    assert check_is_scipy_sparse_array(t_bsr) is True
    assert check_is_scipy_sparse_array(np.array([1])) is False
github telegraphic / hickle / tests / test_scipy.py View on Github external
def test_is_sparse():
    sm0 = csr_matrix((3, 4), dtype=np.int8)
    sm1 = csc_matrix((1, 2))

    assert check_is_scipy_sparse_array(sm0)
    assert check_is_scipy_sparse_array(sm1)
github telegraphic / hickle / tests / test_hickle_helpers.py View on Github external
def test_check_is_scipy_sparse_array():
    t_csr = scipy.sparse.csr_matrix([0])
    t_csc = scipy.sparse.csc_matrix([0])
    t_bsr = scipy.sparse.bsr_matrix([0])
    assert check_is_scipy_sparse_array(t_csr) is True
    assert check_is_scipy_sparse_array(t_csc) is True
    assert check_is_scipy_sparse_array(t_bsr) is True
    assert check_is_scipy_sparse_array(np.array([1])) is False