def test_from_parameters(): s_prior = Sphere(n=1.6, r=Uniform(0.5, 0.7), center=[10, 10, 10]) s_guess = Sphere(n=1.6, r=0.6, center=[10, 10, 10]) s_new_r = Sphere(n=1.6, r=0.7, center=[10, 10, 10]) s_new_nr = Sphere(n=1.7, r=0.7, center=[10, 10, 10]) pars = {'n': 1.7, 'r': 0.7} assert_equal(s_prior.from_parameters({}), s_guess) assert_equal(s_prior.from_parameters(pars, overwrite=False), s_new_r) assert_equal(s_prior.from_parameters(pars, overwrite=True), s_new_nr)
def test_Sphere_parameters(): s = Sphere(n=1.59 + 1e-4j, r=5e-7, center=(1e-6, -1e-6, 10e-6)) assert_equal( s.parameters, dict([('center', (1e-6, -1e-6, 1e-5)), ('n', 1.59 + 1e-4j), ('r', 5e-07)])) sp = s.from_parameters(s.parameters) assert_equal(s.r, sp.r) assert_equal(s.n, sp.n) assert_equal(s.center, sp.center)
def test_multidim(): par_s = Sphere(n={ 'r': prior.Uniform(-1, 1), 'g': 0, 'b': prior.Gaussian(0, 1), 'a': 0 }, r=xr.DataArray( [prior.Gaussian(0, 1), prior.Uniform(-1, 1), 0, 0], dims='alph', coords={'alph': ['a', 'b', 'c', 'd']}), center=[prior.Uniform(-1, 1), 0, 0]) params = { 'n:r': 3, 'n:g': 4, 'n:b': 5, 'n:a': 6, 'r:a': 7, 'r:b': 8, 'r:c': 9, 'r:d': 10, 'center.0': 7, 'center.1': 8, 'center.2': 9 } out_s = Sphere(n={ 'r': 3, 'g': 0, 'b': 5, 'a': 0 }, r={ 'a': 7, 'b': 8, 'c': 0, 'd': 0 }, center=[7, 0, 0]) assert_obj_close(par_s.from_parameters(params), out_s) m = ExactModel(out_s, np.sum) parletters = { 'r': prior.Uniform(-1, 1), 'g': 0, 'b': prior.Gaussian(0, 1), 'a': 0 } parcount = xr.DataArray( [prior.Gaussian(0, 1), prior.Uniform(-1, 1), 0, 0], dims='numbers', coords={'numbers': ['one', 'two', 'three', 'four']}) m._use_parameters({'letters': parletters, 'count': parcount}) expected_params = { 'letters:r': prior.Uniform(-1, 1, 0, 'letters:r'), 'letters:b': prior.Gaussian(0, 1, 'letters:b'), 'count:one': prior.Gaussian(0, 1, 'count:one'), 'count:two': prior.Uniform(-1, 1, 0, 'count:two') } assert_equal(m.parameters, expected_params)
def test_from_parameters(): s_prior = Sphere(n=1.6, r=Uniform(0.5, 0.7), center=[10, 10, 10]) s_new_nr = Sphere(n=1.7, r=0.7, center=[10, 10, 10]) pars = {'n': 1.7, 'r': 0.7} assert_equal(s_prior.from_parameters(pars), s_new_nr)