Exemplo n.º 1
0
    def test_record_data_matrix(self, sampler_args):
        mesh, poslist, fn_hdf5, roi = sampler_args
        S = simnibs_gpc.gPCSampler(mesh, poslist, fn_hdf5, roi)

        rand_vars1 = [.1, .2]
        potential1 = np.random.rand(100)
        E1 = np.random.rand(100, 3)
        S.record_data_matrix(potential1, 'potential', 'data')
        S.record_data_matrix(rand_vars1, 'random_vars', 'data')
        S.record_data_matrix(E1, 'E', 'data')

        rand_vars2 = [.2, .4]
        potential2 = np.random.rand(100)
        E2 = np.random.rand(100, 3)
        S.record_data_matrix(potential2, 'potential', 'data')
        S.record_data_matrix(rand_vars2, 'random_vars', 'data')
        S.record_data_matrix(E2, 'E', 'data')

        with h5py.File(fn_hdf5) as f:
            assert np.allclose(f['data/random_vars'][0, :], rand_vars1)
            assert np.allclose(f['data/random_vars'][1, :], rand_vars2)
            assert np.allclose(f['data/potential'][0, :], potential1)
            assert np.allclose(f['data/potential'][1, :], potential2)
            assert np.allclose(f['data/E'][0, ...], E1)
            assert np.allclose(f['data/E'][1, ...], E2)
Exemplo n.º 2
0
 def test_run_N_random_simulations(self, sampler_args):
     mesh, poslist, fn_hdf5, roi = sampler_args
     S = simnibs_gpc.gPCSampler(mesh, poslist, fn_hdf5, roi)
     S.run_simulation = Mock()
     S.run_N_random_simulations(1000)
     for c in S.run_simulation.call_args_list:
         assert c[0][0][0] <= .4
         assert c[0][0][0] >= .3
Exemplo n.º 3
0
 def test_update_poslist(self, sampler_args):
     mesh, poslist, fn_hdf5, roi = sampler_args
     S = simnibs_gpc.gPCSampler(mesh, poslist, fn_hdf5, roi)
     random_vars = [0.35]
     poslist = S._update_poslist(random_vars)
     assert np.isclose(poslist.cond[2].value, 0.35)
     assert np.isclose(poslist.cond[3].value, 1)
     assert np.isclose(poslist.cond[4].value, 10)
Exemplo n.º 4
0
    def test_set_up_sampler(self, sampler_args):
        mesh, poslist, fn_hdf5, roi = sampler_args
        S = simnibs_gpc.gPCSampler(mesh, poslist, fn_hdf5, roi)

        assert np.all(S.mesh_roi.elm.tag1 == 3)

        S.create_hdf5()
        with h5py.File(fn_hdf5) as f:
            assert f['mesh']
            assert f['mesh_roi']
            assert f['cond']
            assert np.all(f['roi'][()] == 3)

        S2 = simnibs_gpc.gPCSampler.load_hdf5(fn_hdf5)
        assert S2.mesh.nodes.nr == mesh.nodes.nr
        assert S2.mesh.elm.nr == mesh.elm.nr
        assert S2.roi == roi
        for i, c in enumerate(S2.poslist.cond):
            assert c.name == poslist.cond[i].name
            assert c.value == poslist.cond[i].value
            assert c.distribution_type == poslist.cond[i].distribution_type
            assert c.distribution_parameters == poslist.cond[i].distribution_parameters
Exemplo n.º 5
0
 def test_calc_E(self, sampler_args):
     mesh, poslist, fn_hdf5, roi = sampler_args
     S = simnibs_gpc.gPCSampler(mesh, poslist, fn_hdf5, roi)
     v = mesh_io.NodeData(mesh.nodes.node_coord[:, 0], mesh=mesh)
     E = S._calc_E(v, None)
     assert np.allclose(E, [-1e3, 0, 0])