def test_determine_default_theory_for_layered_spheres(self): layered_spheres = Spheres([Sphere(r=[0.5, 1], n=[1, 1.5])] * 2) with warnings.catch_warnings(): warnings.filterwarnings('ignore') default_theory = determine_default_theory_for(layered_spheres) correct_theory = Mie() self.assertTrue(default_theory == correct_theory)
def test_propagate_e_field(): e = calc_field(detector_grid(100, 0.1), Sphere(1.59, .5, (5, 5, 5)), illum_wavelen=0.66, medium_index=1.33, illum_polarization=(1, 0), theory=Mie(False)) prop_e = propagate(e, 10) verify(prop_e, 'propagate_e_field')
def residfunct(p, fjac=None): # nmpfit calls residfunct w/fjac as a kwarg, we ignore sphere = Sphere(n=p[0] + n_particle_imag * 1j, r=p[1], center=p[2:5]) thry = Mie(False) calculated = calc_holo(holo, sphere, scaling=p[5], theory=thry) status = 0 derivates = holo - calculated return ([status, get_values(flat(derivates))])
def _make_model(self): sphere = Sphere(center=(Uniform(0, 1e-5, guess=.567e-5), Uniform(0, 1e-5, .567e-5), Uniform(1e-5, 2e-5)), r=Uniform(1e-8, 1e-5, 8.5e-7), n=Uniform(1, 2, 1.59)) model = AlphaModel(sphere, theory=Mie(False), alpha=Uniform(0.1, 1, 0.6)) return model
def make_model(): # Makes a model with all the paramters used in make_fake_data(), # but with the guesses slightly off from the true values center_guess = [ Uniform(0, 1e-5, name='x', guess=5.6e-6), Uniform(0, 1e-5, name='y', guess=5.8e-6), Uniform(1e-5, 2e-5, name='z', guess=14e-6), ] scatterer = Sphere(n=Uniform(1, 2, name='n', guess=1.55), r=Uniform(1e-8, 1e-5, name='r', guess=8.5e-7), center=center_guess) alpha = Uniform(0.1, 1, name='alpha', guess=0.6) theory = Mie(compute_escat_radial=False) model = AlphaModel(scatterer, theory=theory, alpha=alpha) return model
def test_fit_mie_par_scatterer(): holo = normalize(get_example_data('image0001')) s = Sphere(center=(Uniform(0, 1e-5, guess=.567e-5), Uniform(0, 1e-5, .567e-5), Uniform(1e-5, 2e-5)), r=Uniform(1e-8, 1e-5, 8.5e-7), n=ComplexPrior(Uniform(1, 2, 1.59), 1e-4)) thry = Mie(False) model = AlphaModel(s, theory=thry, alpha=Uniform(.1, 1, .6)) result = fix_flat(NmpfitStrategy().fit(model, holo)) assert_obj_close(result.scatterer, gold_sphere, rtol=1e-3) # TODO: see if we can get this back to 3 sig figs correct alpha assert_approx_equal(result.parameters['alpha'], gold_alpha, significant=3) assert_equal(model, result.model) assert_read_matches_write(result)
def test_Shell(): s = Sphere( center=[7.141442573813124, 7.160766866147957, 11.095409800342143], n=[(1.27121212428 + 0j), (1.49 + 0j)], r=[0.960957713253 - 0.0055, 0.960957713253]) t = detector_grid(200, .071333) thry = Mie(False) h = calc_holo(t, s, 1.36, .658, illum_polarization=(1, 0), theory=thry, scaling=0.4826042444701572) verify(h, 'shell')
def test_fit_random_subset(): holo = normalize(get_example_data('image0001')) s = Sphere(center=(Uniform(0, 1e-5, guess=.567e-5), Uniform(0, 1e-5, .567e-5), Uniform(1e-5, 2e-5)), r=Uniform(1e-8, 1e-5, 8.5e-7), n=ComplexPrior(Uniform(1, 2, 1.59), 1e-4)) model = AlphaModel(s, theory=Mie(False), alpha=Uniform(.1, 1, .6)) np.random.seed(40) result = fix_flat(NmpfitStrategy(npixels=1000).fit(model, holo)) # TODO: this tolerance has to be rather large to pass, we should # probably track down if this is a sign of a problem assert_obj_close(result.scatterer, gold_sphere, rtol=1e-2) # TODO: figure out if it is a problem that alpha is frequently coming out # wrong in the 3rd decimal place. assert_approx_equal(result.parameters['alpha'], gold_alpha, significant=3) assert_equal(model, result.model) assert_read_matches_write(result)
def test_fit_mie_single(): holo = normalize(get_example_data('image0001')) parameters = [ Uniform(0, 1e-5, name='x', guess=.567e-5), Uniform(0, 1e-5, name='y', guess=.576e-5), Uniform(1e-5, 2e-5, name='z', guess=15e-6), Uniform(1, 2, name='n', guess=1.59), Uniform(1e-8, 1e-5, name='r', guess=8.5e-7) ] def make_scatterer(parlist): return Sphere(n=parlist[3], r=parlist[4], center=parlist[0:3]) thry = Mie(False) model = AlphaModel(make_scatterer(parameters), theory=thry, alpha=Uniform(.1, 1, name='alpha', guess=.6)) result = NmpfitStrategy().fit(model, holo) assert_obj_close(result.scatterer, gold_sphere, rtol=1e-3) assert_approx_equal(result.parameters['alpha'], gold_alpha, significant=3) assert_equal(model, result.model)
def test_io(): model = ExactModel(Sphere(1), calc_holo) assert_read_matches_write(model) model = ExactModel(Sphere(1), calc_holo, theory=Mie(False)) assert_read_matches_write(model)
def make_1_parameter_model(): alpha = Uniform(0.1, 1, name='alpha', guess=0.6) theory = Mie(compute_escat_radial=False) model = AlphaModel(SPHERE, theory=theory, alpha=alpha) return model
def test_determine_default_theory_for_sphere(self): default_theory = determine_default_theory_for(Sphere()) correct_theory = Mie() self.assertTrue(default_theory == correct_theory)