Example #1
0
def test_read_empty_array_via_path():
    res = {'a': np.array([[], []])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, path='a')
    assert_array_equal(res, [[], []])
    assert(np.shape(res) == (2, 0))
Example #2
0
def test_store_and_load_quantities_array():
    data = {'times': np.array([1, 2, 3]) * pq.ms, 'positions':
            np.array([1, 2, 3]) * pq.cm}
    h5w.save(fn, data, overwrite_dataset=True)
    # loading the whole data
    res = h5w.load(fn)
    assert(res['times'].dimensionality == data['times'].dimensionality)
Example #3
0
def test_write_empty_array():
    res = {'a': [], 'b': np.array([])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert_array_equal(res['a'], [])
    assert_array_equal(res['b'], [])
Example #4
0
def test_load_lazy_simple():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, lazy=True)
    for key, obj in res.items():
        assert(obj is None)
Example #5
0
def test_old_store_and_load_simpledata():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(simpledata_str, simpledata_val):
        assert(res[key] == val)
Example #6
0
def test_write_nested_empty_array():
    res = {'a': [[], []], 'b': np.array([[], []])}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert_array_equal(res['a'], [[], []])
    assert(np.shape(res['a']) == (2, 0))
    assert_array_equal(res['b'], [[], []])
    assert(np.shape(res['b']) == (2, 0))
Example #7
0
def test_store_and_load_numpy_datatypes():
    res = {}
    res['float64'] = np.float64(f0)
    res['int64'] = np.int64(i0)
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert(isinstance(res['float64'], np.float64))
    assert(isinstance(res['int64'], np.int64))
Example #8
0
def test_store_and_test_key_types():
    data = {'a': 1, (1, 2): {4: 2.}, 4.: 3.}
    h5w.save(fn, data, write_mode='w')
    res = h5w.load(fn)

    keys = ['a', (1, 2), 4.]
    for k in keys:
        assert(k in res)
    assert(4 in res[(1, 2)])
Example #9
0
def test_load_lazy_nested():
    res = {'a': 1, 'test1': {'b': 2}, 'test2': {
        'test3': {'c': np.array([1, 2, 3])}}}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn, lazy=True)
    assert(res['a'] is None)
    assert(res['test1']['b'] is None)
    assert(res['test2']['test3']['c'] is None)
Example #10
0
def test_store_and_load_arraydata():
    res = {}
    for key, val in zip(arraydata_str, arraydata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(arraydata_str, arraydata_val):
        assert_array_equal(res[key], val)
Example #11
0
def test_store_and_load_dictdata():
    res = {}
    for key, val in zip(dictdata_str, dictdata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for dkey, dval in zip(dictdata_str, dictdata_val):
        for key, val in dval.items():
            assert(res[dkey][key] == val)
Example #12
0
def test_store_and_load_tupledata():
    res = {}
    for key, val in zip(tupledata_str, tupledata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(tupledata_str, tupledata_val):
        assert(isinstance(res[key], tuple))
        assert_array_equal(res[key], np.array(val))
Example #13
0
def test_store_and_load_custom_array():
    a = np.array([[1, 2, 3, 4], [6, 7]])
    h5w.save(fn, {'a': a}, overwrite_dataset=True)
    # loading the whole data
    res = h5w.load(fn)
    for i in range(len(a)):
        assert_array_equal(a[i], res['a'][i])
    # loading path directly
    res = h5w.load(fn, path='a/')
    for i in range(len(a)):
        assert_array_equal(a[i], res[i])
Example #14
0
def test_handle_nonexisting_path():
    res = {}
    stest = 'this is a test'
    h5w.save(fn, res, write_mode='w')
    try:
        res = h5w.load(fn, path='test/')
        raise Exception()  # should not get until here
    except KeyError:
        res['test'] = stest
        h5w.save(fn, res)
        res.clear()
        res = h5w.load(fn, path='test/')
        assert(res == stest)
Example #15
0
def test_store_and_rehash_h5py():
    d0 = {
        'a': 'asd',
        'b': 0.12,
        'c': [3, 4, 5],
        'd': np.array([[3, 4, 5], [3, 4, 5]]),
        'e': True
    }
    hash0 = dicthash.generate_hash_from_dict(d0)
    h5w.save('store_and_rehash_h5py.h5', {'d0': d0}, 'w')
    d1 = h5w.load('store_and_rehash_h5py.h5', 'd0')
    hash1 = dicthash.generate_hash_from_dict(d1)

    assert(hash0 == hash1)
Example #16
0
def test_store_and_load_listdata():
    res = {}
    for key, val in zip(listdata_str, listdata_val):
        res[key] = val
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    for key, val in zip(listdata_str, listdata_val):
        if isinstance(val[0], list):
            for ii in range(len(val)):
                assert(isinstance(res[key][ii], list))
                assert_array_equal(res[key][ii], val[ii])
        else:
            assert(isinstance(res[key], type(val)))
            assert_array_equal(res[key], val)
Example #17
0
def test_file_close_on_exception():
    res = {'a': 5}
    h5w.save(fn, res, write_mode='w')
    try:
        h5w.save(fn, res, write_mode='a', overwrite_dataset=False)
    except KeyError:
        pass
    h5w.save(fn, res, write_mode='w')
Example #18
0
def test_overwrite_dataset():
    res = {'a': 5}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = {'a': 6}
    with pytest.raises(KeyError):
        h5w.save(fn, res, write_mode='a', overwrite_dataset=False)
    res.clear()
    res = h5w.load(fn)
    assert(res['a'] == 5)  # dataset should still contain old value
    res.clear()
    res = {'a': 6}
    h5w.save(
        fn, res, write_mode='a', overwrite_dataset=True)
    res.clear()
    res = h5w.load(fn)
    assert(res['a'] == 6)  # dataset should contain new value
Example #19
0
def test_write_and_load_with_label():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w', path='test_label')
    for key, val in zip(simpledata_str, simpledata_val):
        assert(h5w.load(fn, 'test_label/' + key) == val)
Example #20
0
def test_raises_error_for_dictlabel_and_path():
    res = {}
    with pytest.raises(ValueError):
        h5w.save(fn, res, dict_label='test', path='test')
def test_raises_error_for_dictlabel_and_path():
    res = {}
    with pytest.raises(ValueError):
        h5w.save(fn, res, dict_label='test', path='test')
Example #22
0
def test_store_and_load_with_compression():
    data = {'a': 1, 'test1': {'b': 2}, 'test2': {
        'test3': {'c': np.array([1, 2, 3])}}}
    h5w.save(fn, data, write_mode='w', compression='gzip')
    h5w.load(fn)
def test_write_and_load_with_label():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w', path='test_label')
    for key, val in zip(simpledata_str, simpledata_val):
        assert (h5w.load(fn, 'test_label/' + key) == val)
    for i, trans_func in enumerate(transfer_function):
        for j, value in enumerate(trans_func):
            transfer_function_with_synaptic_filter[i, j] = (
                value / complex(1., circ.omegas[j] * tau_s))

    eigenvalue_spectra_freqs, eigenvalue_spectra = (
        circ.create_eigenvalue_spectra('MH'))

    h5.save(filename, {
        'params': circ.params,
        'omegas': circ.omegas,
        'firing_rates': circ.th_rates,
        'transfer_function': transfer_function,
        'transfer_function_with_synaptic_filter':
        transfer_function_with_synaptic_filter,
        'power_spectra': power_spectra,
        'H': H,
        'MH': MH,
        'delay_dist': delay_dist,
        'eigenvalue_spectra': eigenvalue_spectra,
        'exemplary_frequency_idx': exemplary_frequency_idx
    },
            overwrite_dataset=True)

    # frequencies = [64, 241, 263, 267, 284]
    #
    # for f in frequencies:
    #
    #     Z = circ.get_sensitivity_measure(f)
    #
    # eigc = eigs[eig_index][np.argmin(abs(eigs[eig_index]-1))]
def test_store_none():
    res = {'a1': None}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert (res['a1'] is None)
Example #26
0
def test_store_and_load_dataset_directly():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    for key, val in zip(simpledata_str, simpledata_val):
        assert(h5w.load(fn, '/' + key) == val)
def test_store_and_load_dataset_directly():
    res = _construct_simpledata()
    h5w.save(fn, res, write_mode='w')
    for key, val in zip(simpledata_str, simpledata_val):
        assert (h5w.load(fn, '/' + key) == val)
Example #28
0
def test_store_none():
    res = {'a1': None}
    h5w.save(fn, res, write_mode='w')
    res.clear()
    res = h5w.load(fn)
    assert(res['a1'] is None)
Example #29
0
    # sigma = 1.5, $\nu = 10, 30$ Hz
    mean_input_2 = np.array([18.94, 20.96])
    sigma_2 = 1.5

    frequencies = np.logspace(-1, 2.8, num=500)
    zero_freq = 0.06

    fig, (axA, axB) = plt.subplots(1, 2, figsize=(15, 10))
    Phi1 = Phi1_mpmath_pcfu
    results_dict = plot_PRE_Schuecker_Fig4(frequencies, sigma_1, mean_input_1,
                                           sigma_2, mean_input_2)
    # fig.savefig(fix_path + 'PRE_Schuecker_Fig4.pdf')

    # save output
    h5.save(fix_path + 'Schuecker2015_data.h5',
            results_dict,
            overwrite_dataset=True)

    # Phi1 = Phi1_U_Kummer_fortran
    # plot_PRE_Schuecker_Fig4(['red', 'orange'], lw=2, markersize_cross=4)
    # axA.set_ylim(0, 15)
    # axB.set_ylim(-50, 10)
    # fig.savefig(fix_path + 'PRE_Schuecker_Fig4_Kummer_fortran.png')
    #
    # Phi1 = Phi1_U_Kummer_mpmath
    # plot_PRE_Schuecker_Fig4(['blue', 'green'], lw=2, markersize_cross=4)
    # axA.set_ylim(0, 15)
    # axB.set_ylim(-50, 10)
    # fig.savefig(fix_path + 'PRE_Schuecker_Fig4_Kummer_python.png')