Exemplo n.º 1
0
def test_pullingoutguess():
    g = Sphere(center=(prior.Uniform(0, 1e-5, guess=.567e-5),
                       prior.Uniform(0, 1e-5, .567e-5),
                       prior.Uniform(1e-5, 2e-5, 15e-6)),
               r=prior.Uniform(1e-8, 1e-5, 8.5e-7),
               n=prior.ComplexPrior(prior.Uniform(1, 2, 1.59), 1e-4))

    model = ExactModel(g, calc_holo)

    s = Sphere(center=[.567e-5, .567e-5, 15e-6], n=1.59 + 1e-4j, r=8.5e-7)

    assert_equal(s.n, model.scatterer.guess.n)
    assert_equal(s.r, model.scatterer.guess.r)
    assert_equal(s.center, model.scatterer.guess.center)

    g = Sphere(center=(prior.Uniform(0, 1e-5, guess=.567e-5),
                       prior.Uniform(0, 1e-5, .567e-5),
                       prior.Uniform(1e-5, 2e-5, 15e-6)),
               r=prior.Uniform(1e-8, 1e-5, 8.5e-7),
               n=1.59 + 1e-4j)

    model = ExactModel(g, calc_holo)

    s = Sphere(center=[.567e-5, .567e-5, 15e-6], n=1.59 + 1e-4j, r=8.5e-7)

    assert_equal(s.n, model.scatterer.guess.n)
    assert_equal(s.r, model.scatterer.guess.r)
    assert_equal(s.center, model.scatterer.guess.center)
Exemplo n.º 2
0
 def test_map_composite_object(self):
     model = SimpleModel()
     parameter = [prior.ComplexPrior(0, 1), {'a': 2, 'b': [4, 5]}, 6]
     parameter_map = model._convert_to_map(parameter)
     expected = [[transformed_prior, [complex, [0, 1]]],
                 [dict, [[['a', 2], ['b', [4, 5]]]]], 6]
     self.assertEqual(parameter_map, expected)
Exemplo n.º 3
0
def test_ComplexPrior():
    parm = Sphere(
        n=prior.ComplexPrior(real=prior.Uniform(1.58, 1.59), imag=.001))
    model = AlphaModel(parm, alpha=prior.Uniform(.6, 1, .7))
    assert_equal(model.parameters['n.real'].name, 'n.real')
    interpreted_pars = {'alpha': .7, 'n': {'real': 1.585}}
    assert_equal(_interpret_parameters(model.parameters), interpreted_pars)
Exemplo n.º 4
0
 def test_complex_compound_name(self):
     model = SimpleModel()
     parameter = prior.ComplexPrior(prior.Uniform(0, 1),
                                    prior.Uniform(2, 3))
     model._convert_to_map(parameter, 'prefix')
     self.assertEqual(model._parameter_names[-2], 'prefix.real')
     self.assertEqual(model._parameter_names[-1], 'prefix.imag')
Exemplo n.º 5
0
 def test_map_complex(self):
     model = SimpleModel()
     parameter = prior.ComplexPrior(1, prior.Uniform(2, 3))
     position = len(model._parameters)
     parameter_map = model._convert_to_map(parameter)
     placeholder = "_parameter_{}".format(position)
     expected = [transformed_prior, [complex, [1, placeholder]]]
     self.assertEqual(parameter_map, expected)
Exemplo n.º 6
0
 def test_yaml_preserves_parameter_names(self):
     n = prior.ComplexPrior(prior.Uniform(1, 2), prior.Uniform(0, 0.1))
     sphere = Sphere(n=n, r=prior.Uniform(0, 1.5, name='radius'),
                     center=[1, 1, prior.Uniform(10, 20)])
     alpha = {'r': 0.6, 'g': prior.Uniform(0.6, 1.0)}
     model = AlphaModel(sphere, alpha=alpha)
     pre_names = model._parameter_names
     post_names = take_yaml_round_trip(model)._parameter_names
     self.assertEqual(pre_names, post_names)
Exemplo n.º 7
0
 def test_reads_optics_from_map(self):
     med_n = prior.ComplexPrior(1.5, prior.Uniform(0, 0.1))
     wl = {'red': 0.5, 'green': prior.Uniform(0, 1)}
     pol = [1, prior.Uniform(0.5, 1.5)]
     model = AlphaModel(Sphere(), medium_index=med_n,
                        illum_wavelen=wl, illum_polarization=pol)
     pars = [0.01, 0.6, 1]
     found_optics = model._find_optics(pars, None)
     expected = {'medium_index': complex(1.5, 0.01),
                 'illum_wavelen': {'red': 0.5, 'green': 0.6},
                 'illum_polarization': [1, 1]}
     self.assertEqual(found_optics, expected)
Exemplo n.º 8
0
 def test_add_3_way_tie(self):
     tied = prior.Uniform(-5, 5)
     n = prior.ComplexPrior(prior.Uniform(1, 2), prior.Uniform(0, 1))
     sphere = Sphere(n=n, r=prior.Uniform(0.5, 1),
                     center=[prior.Uniform(0, 1), prior.Uniform(0, 1),
                             prior.Uniform(0, 10)])
     model = AlphaModel(sphere)
     model.add_tie(['center.0', 'n.imag', 'center.1'])
     expected_map = [
         dict,
         [[['n', [transformed_prior, [complex, ['_parameter_0',
                                                '_parameter_1']]]],
           ['r', '_parameter_2'],
           ['center', ['_parameter_1', '_parameter_1', '_parameter_3']]]]]
     expected_parameters = [prior.Uniform(1, 2), prior.Uniform(0, 1),
                            prior.Uniform(0.5, 1), prior.Uniform(0, 10)]
     expected_names = ['n.real', 'n.imag', 'r', 'center.2']
     self.assertEqual(model._maps['scatterer'], expected_map)
     self.assertEqual(model._parameters, expected_parameters)
     self.assertEqual(model._parameter_names, expected_names)