def test_pde_user_funcs(): """test user supplied functions""" # test a simple case eq = PDE({"u": "get_x(gradient(u))"}, user_funcs={"get_x": lambda arr: arr[0]}) field = ScalarField.random_colored(grids.UnitGrid([32, 32])) rhs = eq.evolution_rate(field) np.testing.assert_allclose(rhs.data, field.gradient("natural").data[0]) f = eq._make_pde_rhs_numba(field) np.testing.assert_allclose(f(field.data, 0), field.gradient("natural").data[0])
def test_structure_factor_random(): """test the structure factor function for random input""" g1 = CartesianGrid([[0, 10]] * 2, 64, periodic=True) f1 = ScalarField.random_colored(g1, -2) # test invariance with re-meshing g2 = CartesianGrid([[0, 10]] * 2, [128, 64], periodic=True) f2 = f1.interpolate_to_grid(g2) ks = np.linspace(0.2, 3) k1, s1 = image_analysis.get_structure_factor(f1, wave_numbers=ks) k2, s2 = image_analysis.get_structure_factor(f2, wave_numbers=ks) np.testing.assert_equal(ks, k1) np.testing.assert_equal(ks, k2) np.testing.assert_allclose(s1, s2, atol=0.05) # test invariance with respect to scaling k2, s2 = image_analysis.get_structure_factor(100 * f1, wave_numbers=ks) np.testing.assert_equal(ks, k2) np.testing.assert_allclose(s1, s2, atol=0.05)