def test_transforms_correctly_with_polarization_rotation(self): # We test that rotating the lab frame correctly rotates # the polarization. # If we rotate (x0, y0) -> (y1, -x1), then the polarization # in the new coordinates should be # E1x = E0y, E1y = -E1x scatterer = test_common.sphere medium_wavevec = 2 * np.pi / test_common.wavelen medium_index = test_common.index theory = Lens( lens_angle=LENS_ANGLE, theory=Mie(False, False), quad_npts_theta=200, quad_npts_phi=200, ) krho = np.linspace(0, 100, 11) phi_0 = 0 * krho phi_1 = np.full_like(krho, -np.pi / 2) kz = np.full_like(krho, 20.0) pol_0 = xr.DataArray([1.0, 0, 0]) pos_0 = np.array([krho, phi_0, kz]) pol_1 = xr.DataArray([0, -1.0, 0]) pos_1 = np.array([krho, phi_1, kz]) args = (scatterer, medium_wavevec, medium_index) fields_0 = theory._raw_fields(pos_0, *args, pol_0) fields_1 = theory._raw_fields(pos_1, *args, pol_1) tols = {'atol': 1e-5, 'rtol': 1e-5} assert_allclose(fields_1[0], fields_0[1], **tols) assert_allclose(fields_1[1], -fields_0[0], **tols)
def test_Mie_multiple(): s1 = Sphere(n = 1.59, r = 5e-7, center = (1e-6, -1e-6, 10e-6)) s2 = Sphere(n = 1.59, r = 1e-6, center=[8e-6,5e-6,5e-6]) s3 = Sphere(n = 1.59+0.0001j, r = 5e-7, center=[5e-6,10e-6,3e-6]) sc = Spheres(scatterers=[s1, s2, s3]) thry = Mie(False) schema = yschema fields = calc_field(schema, sc, index, wavelen, ypolarization, thry) verify(fields, 'mie_multiple_fields') calc_intensity(schema, sc, index, wavelen, ypolarization, thry) holo = calc_holo(schema, sc, index, wavelen, theory=thry) verify(holo, 'mie_multiple_holo') # should throw exception when fed a ellipsoid el = Ellipsoid(n = 1.59, r = (1e-6, 2e-6, 3e-6), center=[8e-6,5e-6,5e-6]) with assert_raises(TheoryNotCompatibleError) as cm: calc_field(schema, el, index, wavelen, theory=Mie) assert_equal(str(cm.exception), "Mie scattering theory can't handle " "scatterers of type Ellipsoid") assert_raises(TheoryNotCompatibleError, calc_field, schema, el, index, wavelen, xpolarization, Mie) assert_raises(TheoryNotCompatibleError, calc_intensity, schema, el, index, wavelen, xpolarization, Mie) assert_raises(TheoryNotCompatibleError, calc_holo, schema, el, index, wavelen, xpolarization, Mie)
def test_fit_mie_single(): holo = normalize(get_example_data('image0001.yaml')) parameters = [ Parameter(name='x', guess=.567e-5, limit=[0.0, 1e-5]), Parameter(name='y', guess=.576e-5, limit=[0, 1e-5]), Parameter(name='z', guess=15e-6, limit=[1e-5, 2e-5]), Parameter(name='n', guess=1.59, limit=[1, 2]), Parameter(name='r', guess=8.5e-7, limit=[1e-8, 1e-5]) ] def make_scatterer(x, y, z, r, n): return Sphere(n=n + 1e-4j, r=r, center=(x, y, z)) thry = Mie(False) model = Model(Parametrization(make_scatterer, parameters), thry.calc_holo, alpha=Parameter(name='alpha', guess=.6, limit=[.1, 1])) assert_raises(InvalidMinimizer, fit, model, holo, minimizer=Sphere) result = 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_calculate_scattering_matrix_has_correct_spherical_coords(self): theory = Mie() scat_matrs = theory.calculate_scattering_matrix(SPHERE, SCAT_SCHEMA) true_r = np.array([ 2., 2.00249844, 2.00997512, 2.02237484, 2.03960781, 2.00249844, 2.00499377, 2.01246118, 2.02484567, 2.04205779, 2.00997512, 2.01246118, 2.01990099, 2.03224014, 2.04939015, 2.02237484, 2.02484567, 2.03224014, 2.04450483, 2.06155281, 2.03960781, 2.04205779, 2.04939015, 2.06155281, 2.07846097 ]) true_theta = np.array([ 0., 0.0499584, 0.09966865, 0.14888995, 0.19739556, 0.0499584, 0.07059318, 0.11134101, 0.15681569, 0.20330703, 0.09966865, 0.11134101, 0.1404897, 0.17836178, 0.21998798, 0.14888995, 0.15681569, 0.17836178, 0.2090333, 0.24497866, 0.19739556, 0.20330703, 0.21998798, 0.24497866, 0.2756428 ]) true_phi = np.array([ 0., 1.57079633, 1.57079633, 1.57079633, 1.57079633, 0., 0.78539816, 1.10714872, 1.24904577, 1.32581766, 0., 0.46364761, 0.78539816, 0.98279372, 1.10714872, 0., 0.32175055, 0.5880026, 0.78539816, 0.92729522, 0., 0.24497866, 0.46364761, 0.64350111, 0.78539816 ]) packed_r = scat_matrs.coords['r'].values packed_theta = scat_matrs.coords['theta'].values packed_phi = scat_matrs.coords['phi'].values self.assertTrue(np.allclose(true_r, packed_r, **MEDTOLS)) self.assertTrue(np.allclose(true_theta, packed_theta, **MEDTOLS)) self.assertTrue(np.allclose(true_phi, packed_phi, **MEDTOLS))
def test_radialEscat(): thry_1 = Mie() thry_2 = Mie(False) sphere = Sphere(r = 1e-6, n = 1.4 + 0.01j, center = [10e-6, 10e-6, 1.2e-6]) h1 = calc_holo(xschema, sphere, index, wavelen, illum_polarization=xpolarization) h2 = calc_holo(xschema, sphere, index, wavelen, illum_polarization=xpolarization, theory=thry_2) try: assert_array_almost_equal(h1, h2, decimal=12) except AssertionError: pass # no way to do "assert array not equal" in numpy.testing else: raise AssertionError("Holograms w/ and w/o full radial fields" + " are exactly equal")
def test_calculate_scattering_matrix_has_correct_s1s2s3s4_labels(self): theory = Mie() scat_matrs = theory.calculate_scattering_matrix(SPHERE, SCAT_SCHEMA) epar_coords = scat_matrs.coords['Epar'].values eperp_coords = scat_matrs.coords['Eperp'].values self.assertTrue(np.all(epar_coords == np.array(['S2', 'S3']))) self.assertTrue(np.all(eperp_coords == np.array(['S4', 'S1'])))
def test_calc_field(): s = Sphere(n=1.59, r=.5, center=(0, 0, 1)) t = update_metadata(detector_grid(shape=(2, 2), spacing=.1), illum_wavelen=0.66, medium_index=1.33, illum_polarization=(1, 0)) thry = Mie(False) f = calc_field(t, s, 1.33, .66, (1, 0), theory=thry) assert_obj_close(t.attrs, f.attrs) gold = xr.DataArray(np.array([[[ -3.95866810e-01 + 2.47924378e+00j, 0.00000000e+00 + 0.00000000e+00j, 0.00000000e+00 - 0.00000000e+00j ], [ -4.91260953e-01 + 2.32779296e+00j, 9.21716363e-20 - 5.72226912e-19j, 2.99878926e-18 - 1.41959276e-17j ]], [[ -4.89755627e-01 + 2.31844748e+00j, 0.00000000e+00 + 0.00000000e+00j, 4.89755627e-02 - 2.31844748e-01j ], [ -5.71886751e-01 + 2.17145168e+00j, 1.72579090e-03 - 8.72241140e-03j, 5.70160960e-02 - 2.16272927e-01j ]]]), dims=['x', 'y', 'vector'], coords={ 'x': t.x, 'y': t.y, 'vector': ['x', 'y', 'z'] }) assert abs((f - gold).max()) < 5e-9
def test_calc_holo(): s = Sphere(n=1.59, r=.5, center=(0, 0, 1)) t = detector_grid(shape=(2, 2), spacing=.1) thry = Mie(False) h = calc_holo(t, s, 1.33, .66, (1, 0), theory=thry) assert_allclose( h, np.array([[[6.51162661], [5.67743548]], [[5.63554802], [4.89856241]]]))
def determine_default_theory_for(scatterer): if isinstance(scatterer, Sphere): theory = Mie() elif isinstance(scatterer, Spheres): if all([np.isscalar(scat.r) for scat in scatterer.scatterers]): theory = Multisphere() else: warn("HoloPy's multisphere theory can't handle coated spheres." + "Using Mie theory.") theory = Mie() elif isinstance(scatterer, Spheroid) or isinstance(scatterer, Cylinder): theory = Tmatrix() elif DDA()._can_handle(scatterer): theory = DDA() else: raise AutoTheoryFailed(scatterer) return theory
def test_calc_holo_theta_npts_not_equal_phi_npts(self): scatterer = test_common.sphere pts = detector_grid(shape=4, spacing=test_common.pixel_scale) pts = update_metadata(pts, illum_wavelen=test_common.wavelen, medium_index=test_common.index, illum_polarization=test_common.xpolarization) theory = Lens(LENS_ANGLE, Mie(), quad_npts_theta=8, quad_npts_phi=10) holo = calc_holo(pts, scatterer, theory=theory) self.assertTrue(True)
def test_raw_scat_matrs_same_as_mie(self): theory_mie = Mie() theory_tmat = Tmatrix() pos = np.array([10, 0, 0])[:,None] s = Sphere(n=1.59, r=0.9, center=(2, 2, 80)) s_mie = theory_mie._raw_scat_matrs(s, pos, 2*np.pi/.660, 1.33) s_tmat = theory_tmat._raw_scat_matrs(s, pos, 2*np.pi/.660, 1.33) self.assertTrue(np.allclose(s_mie, s_tmat))
def calc_model(cls, data, params, theory_type='mielens'): scatterer = cls._make_scatterer(params) if theory_type == 'mielens': theory = MieLens(lens_angle=params['lens_angle']) scaling = 1.0 else: theory = Mie() scaling = params['alpha'] model = calc_holo(data, scatterer, theory=theory, scaling=scaling) return model
def _get_theory_and_scaling(self, params): if self.theory == 'mielens': theory = MieLens(lens_angle=params['lens_angle']) # 0.0015 ms scaling = 1.0 elif self.theory == 'mieonly': theory = Mie() scaling = params['alpha'] elif self.theory == 'mielensalpha': theory = MieLens(lens_angle=params['lens_angle']) # 0.0015 ms scaling = params['alpha'] return theory, scaling
def test_raw_fields_similar_to_mie(self): theory_mie = Mie(False, False) theory_tmat = Tmatrix() pos = np.array([10, 0, 0])[:,None] s = Sphere(n=1.59, r=0.9, center=(2, 2, 80)) pol = pd.Series([1, 0]) fields_mie = theory_mie._raw_fields(pos, s, 2*np.pi/.660, 1.33, pol) fields_tmat = theory_tmat._raw_fields(pos, s, 2*np.pi/.660, 1.33, pol) self.assertTrue(np.allclose(fields_mie, fields_tmat))
def test_fit_superposition(): """ Fit Mie superposition to a calculated hologram from two spheres """ # Make a test hologram optics = Optics(wavelen=6.58e-07, index=1.33, polarization=[0.0, 1.0], divergence=0, spacing=None, train=None, mag=None, pixel_scale=[2 * 2.302e-07, 2 * 2.302e-07]) s1 = Sphere(n=1.5891 + 1e-4j, r=.65e-6, center=(1.56e-05, 1.44e-05, 15e-6)) s2 = Sphere(n=1.5891 + 1e-4j, r=.65e-6, center=(3.42e-05, 3.17e-05, 10e-6)) sc = Spheres([s1, s2]) alpha = .629 theory = Mie(optics, 100) holo = theory.calc_holo(sc, alpha) # Now construct the model, and fit parameters = [ Parameter(name='x0', guess=1.6e-5, limit=[0, 1e-4]), Parameter('y0', 1.4e-5, [0, 1e-4]), Parameter('z0', 15.5e-6, [0, 1e-4]), Parameter('r0', .65e-6, [0.6e-6, 0.7e-6]), Parameter('nr', 1.5891, [1, 2]), Parameter('x1', 3.5e-5, [0, 1e-4]), Parameter('y1', 3.2e-5, [0, 1e-4]), Parameter('z1', 10.5e-6, [0, 1e-4]), Parameter('r1', .65e-6, [0.6e-6, 0.7e-6]) ] def make_scatterer(x0, x1, y0, y1, z0, z1, r0, r1, nr): s = Spheres([ Sphere(center=(x0, y0, z0), r=r0, n=nr + 1e-4j), Sphere(center=(x1, y1, z1), r=r1, n=nr + 1e-4j) ]) return s model = Model(parameters, Mie, make_scatterer=make_scatterer, alpha=Parameter('alpha', .63, [.5, 0.8])) result = fit(model, holo) assert_obj_close(result.scatterer, sc) assert_approx_equal(result.alpha, alpha, significant=4) assert_equal(result.model, model) assert_read_matches_write(result)
def test_calc_intensity(): s = Sphere(n=1.59, r=.5, center=(0, 0, 1)) t = detector_grid(shape=(2, 2), spacing=.1) thry = Mie(False) i = calc_intensity(t, s, illum_wavelen=.66, medium_index=1.33, illum_polarization=(1, 0), theory=thry) assert_allclose( i, np.array([[[6.30336023], [5.65995739]], [[5.61505927], [5.04233591]]]))
def evaluate_model(self, params): scatterer = self.make_scatterer(params) if self.theory == 'mieonly': theory = Mie() else: theory = MieLens(lens_angle=params['lens_angle']) if self.theory == 'mielens': scaling = 1.0 else: scaling = params['alpha'] model = calc_holo(self.data, scatterer, theory=theory, scaling=scaling) return model
def test_single_sphere(): # single sphere hologram (only tests that functions return) thry = Mie(False) holo = calc_holo(xschema, sphere, index, wavelen, xpolarization, theory=thry, scaling=scaling_alpha) field = calc_field(xschema, sphere, index, wavelen, xpolarization, theory=thry) intensity = calc_intensity(xschema, sphere, medium_index=index, illum_wavelen=wavelen, illum_polarization=xpolarization, theory=thry) verify(holo, 'single_holo') verify(field, 'single_field') # now test some invalid scatterers and confirm that it rejects calculating # for them # large radius (calculation not attempted because it would take forever assert_raises(InvalidScatterer, calc_holo, xschema, Sphere(r=1, n = 1.59, center = (5,5,5)), medium_index=index, illum_wavelen=wavelen)
def test_fit_single_openopt(): holo = normalize(get_example_data('image0001.yaml')) s = Sphere(center = (par(guess=.567e-5, limit=[.4e-5,.6e-5]), par(.567e-5, (.4e-5, .6e-5)), par(15e-6, (1.3e-5, 1.8e-5))), r = par(8.5e-7, (5e-7, 1e-6)), n = ComplexParameter(par(1.59, (1.5,1.8)), 1e-4j)) model = Model(s, Mie(False).calc_holo, alpha = par(.6, [.1,1])) try: minimizer = OpenOpt('scipy_slsqp') except ImportError: raise SkipTest result = fit(model, holo, minimizer = minimizer) 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)
def test_fit_mie_par_scatterer(): holo = normalize(get_example_data('image0001.yaml')) s = Sphere(center = (par(guess=.567e-5, limit=[0,1e-5]), par(.567e-5, (0, 1e-5)), par(15e-6, (1e-5, 2e-5))), r = par(8.5e-7, (1e-8, 1e-5)), n = ComplexParameter(par(1.59, (1,2)), 1e-4j)) thry = Mie(False) model = Model(s, thry.calc_holo, alpha = par(.6, [.1,1])) result = 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_calculate_scattering_matrix_has_correct_cartesian_coords(self): theory = Mie() scat_matrs = theory.calculate_scattering_matrix(SPHERE, SCAT_SCHEMA) true_x = np.array([ 0., 0., 0., 0., 0., 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3, 0.4, 0.4, 0.4, 0.4, 0.4 ]) true_y = np.array([ 0., 0.1, 0.2, 0.3, 0.4, 0., 0.1, 0.2, 0.3, 0.4, 0., 0.1, 0.2, 0.3, 0.4, 0., 0.1, 0.2, 0.3, 0.4, 0., 0.1, 0.2, 0.3, 0.4 ]) true_z = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]) packed_x = scat_matrs.coords['x'].values packed_y = scat_matrs.coords['y'].values packed_z = scat_matrs.coords['z'].values self.assertTrue(np.allclose(true_x, packed_x, **MEDTOLS)) self.assertTrue(np.allclose(true_y, packed_y, **MEDTOLS)) self.assertTrue(np.allclose(true_z, packed_z, **MEDTOLS))
def test_fit_random_subset(): holo = normalize(get_example_data('image0001.yaml')) s = Sphere(center=(par(guess=.567e-5, limit=[0, 1e-5]), par(.567e-5, (0, 1e-5)), par(15e-6, (1e-5, 2e-5))), r=par(8.5e-7, (1e-8, 1e-5)), n=ComplexParameter(par(1.59, (1, 2)), 1e-4)) model = Model(s, Mie(False).calc_holo, alpha=par(.6, [.1, 1])) np.random.seed(40) result = fit(model, holo, random_subset=.1) # 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_mie_polarization(): # test holograms for orthogonal polarizations; make sure they're # not the same, nor too different from one another. thry = Mie(False) xholo = calc_holo(xschema, sphere, index, wavelen, illum_polarization=xpolarization, scaling=scaling_alpha) yholo = calc_holo(yschema, sphere, index, wavelen, illum_polarization=ypolarization, scaling=scaling_alpha) # the two arrays should not be equal try: assert_array_almost_equal(xholo, yholo) except AssertionError: pass else: raise AssertionError("Holograms computed for both x- and y-polarized " "light are too similar.") # but their max and min values should be close assert_obj_close(xholo.max(), yholo.max()) assert_obj_close(xholo.min(), yholo.min()) return xholo, yholo
def test_raw_fields(): sp = Sphere(r=.5, n=1.6, center=(10, 10, 5)) wavelen = .66 index = 1.33 pol = to_vector((0, 1)) sch = detector_grid(3, .1) wavevec=2*np.pi/(wavelen/index) pos = Mie._transform_to_desired_coordinates( sch, (10, 10, 5), wavevec=wavevec) rf = Mie()._raw_fields( pos, sp, medium_wavevec=wavevec, medium_index=index, illum_polarization=pol) assert_allclose(rf, [[(0.0015606995428858754-0.0019143174710834162j), (-0.0003949071974815011-0.0024154494284017187j), (-0.002044525390662322-0.001302770747742109j), (-0.0003949071974815009-0.002415449428401719j), (-0.002055824337886397-0.0012853546864338861j), (-0.00230285180386436+0.000678693819245102j), (-0.0020445253906623225-0.0013027707477421095j), (-0.0023028518038643603+0.0006786938192451026j), (-0.0010011090105680883+0.0021552249454706712j)], [(-0.0010507058414478587+0.0036584360153097306j), (0.0020621595919700776+0.003210547679920805j), (0.0037794246074692407+0.000585690417403587j), (0.0020542215584045407+0.0031619947065620246j), (0.0037426710578253295+0.000527040269055415j), (0.002871631795307833-0.002470099566862354j), (0.0036968090916832948+0.0005330478443315597j), (0.002824872178181336-0.0024563186266035124j), (2.261564613123139e-06-0.003751168280253104j)], [(0.0010724312167657794+0.0039152445632936j), (0.003651474601303447+0.0017688083711547462j), (0.003740131549224567-0.001566271371618957j), (0.0036883581831347947+0.0017866751223785315j), (0.0037648739662344477-0.001614943488355339j), (0.0012643679510138835-0.003894481935619062j), (0.003816460764514863-0.0015982360934887314j), (0.0012772696647997395-0.0039342215472070105j), (-0.0021320123934202356-0.0035427449839031066j)]])
def test_calc_scat_coeffs(): sp = Sphere(r=.5, n=1.6, center=(10, 10, 5)) wavevec = 2* np.pi / (.66/1.33) scat_coeffs = Mie()._scat_coeffs(sp, wavevec, 1.33) assert_allclose(scat_coeffs, [[(0.893537889855249-0.308428158974303j), (0.8518237942576172-0.35527456677079167j), (0.8514945265371544-0.3556003343845751j), (0.6716114989265135-0.4696269726455193j), (0.4463235347943387-0.49711048780228473j), (0.10807327505985087-0.31047293324489444j), (0.007047039370772889-0.08365033536621158j), (0.00023637042768157927-0.01537252603518683j), (4.947915829486452e-06-0.002224385611267839j), (6.65551498173517e-08-0.00025798283932805245j), (5.916757117384697e-10-2.4324385118403086e-05j), (3.5939293107529156e-12-1.895766154023222e-06j), (1.5398821099306434e-14-1.2409198644274415e-07j), (4.7871541500938646e-17-6.918926325734264e-09j), (1.1064408835358364e-19-3.3263206152381594e-10j), (1.941747305677948e-22-1.3934659327295906e-11j)], [(0.9165672213503293-0.2765352601323488j), (0.8925153551366475-0.3097284229481555j), (0.724406068807489-0.44681306637381196j), (0.79999539554102-0.40000345330282716j), (0.5815720097871232-0.4933011323920608j), (0.059989429815427465-0.23746725695524293j), (0.0016746678595338474-0.040888425588350694j), (3.157538369132347e-05-0.005619109065187133j), (4.0598276866269854e-07-0.0006371676418656946j), (3.5327216259785343e-09-5.943670257928523e-05j), (2.1212298756767418e-11-4.605681139236351e-06j), (9.027481439768403e-14-3.004576748856249e-07j), (2.7948125784531043e-16-1.6717692958219755e-08j), (6.442879235052296e-19-8.026754783255993e-10j), (1.128893090815587e-21-3.359900431286003e-11j), (1.5306616534558257e-24-1.2371991163332706e-12j)]])
def test_mielens_is_close_to_mieonly(self): """Tests that a mielens hologram is similar to a mie-only hologram.""" theory_mielens = MieLens() theory_mieonly = Mie() holo_mielens = calc_holo( xschema, sphere, index, wavelen, xpolarization, theory=theory_mielens) holo_mieonly = calc_holo( xschema, sphere, index, wavelen, xpolarization, scaling=1.0, theory=theory_mieonly) # the two arrays should not be equal self.assertFalse(np.allclose(holo_mielens, holo_mieonly, **TOLS)) # but their max and min values should be close: ptp_close_ish = np.isclose( holo_mielens.values.ptp(), holo_mieonly.values.ptp(), atol=0.1) # and their median should be close: median_close_ish = np.isclose( np.median(holo_mielens), np.median(holo_mieonly), atol=0.1) self.assertTrue(ptp_close_ish) self.assertTrue(median_close_ish)
def test_farfield_holo(): # Tests that a far field calculation gives a hologram that is # different from a full radial dependence calculation, but not too different holo_full = calc_holo(xschema, sphere, index, wavelen, xpolarization, scaling=scaling_alpha) holo_far = calc_holo(xschema, sphere, index, wavelen, xpolarization, scaling=scaling_alpha, theory=Mie(False, False)) # the two arrays should not be equal try: assert_array_almost_equal(holo_full, holo_far) except AssertionError: pass else: raise AssertionError("Holograms computed for near and far field " "are too similar.") # but their max and min values should be close assert_obj_close(holo_full.max(), holo_far.max(), .1, context="Near and Far field holograms too different") assert_obj_close(holo_full.min(), holo_far.min(), .1, context="Near and Far field holograms too different")
def test_io(): model = Model(Sphere(par(1)), calc_holo) assert_read_matches_write(model) model = Model(Sphere(par(1)), calc_holo, theory=Mie(False)) assert_read_matches_write(model)
def test_pickle_mie_object(): m = Mie() assert_pickle_roundtrip(m) assert_pickle_roundtrip(m.calc_holo, True)
def test_pickle_mie_object(): m = Mie() assert_pickle_roundtrip(m)