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_Spheres_construction_typechecking(): # heterogeneous composite should raise exception, since a # sphere cluster must contain only Spheres s1 = Sphere(n = 1.59, r = 5e-7, center = (1e-6, -1e-6, 10e-6)) s2 = Sphere(n = 1.59, r = 1e-6, center=[0,0,0]) s3 = Sphere(n = 1.59+0.0001j, r = 5e-7, center=[5e-6,0,0]) cs = Ellipsoid(n=1.59+0.0001j, r=(5e-7, 5e-7, 8e-7), center=[-5e-6, 0,0]) sc = Spheres(scatterers=[s1, s2, s3, cs])
def test_Ellipsoid_dda(): e = Ellipsoid(1.5, r = (.5, .1, .1), center = (1, -1, 10)) schema = detector_grid(10, .1) try: h = calc_holo(schema, e, illum_wavelen=.66, medium_index=1.33, illum_polarization = (1,0), theory=DDA(use_indicators=False)) cmd = DDA()._adda_predefined( e, medium_wavelen=.66, medium_index=1.33, temp_dir='temp_dir') cmdlist = ['-eq_rad', '0.5', '-shape', 'ellipsoid', '0.2', '0.2', '-m', '1.1278195488721805', '0.0', '-orient', '0.0', '0.0', '0.0'] assert_equal(cmd, cmdlist) verify(h, 'ellipsoid_dda') except DependencyMissing: raise SkipTest()
def test_predefined_scatterers(): # note this tests only that the code runs, not that it is correct try: scatterers = [Ellipsoid(n=1.5, r=(0.5, 1, 2), center=(0,0,1)), Spheroid(n=1.5, r=(0.5, 1), center=(0,0,1)), Capsule(n=1.5, h=1, d=0.5, center=(0,0,1)), Cylinder(n=1.5, h=1, d=0.5, center=(0,0,1)), Bisphere(n=1.5, h=1, d=0.5, center=(0,0,1)), Sphere(n=1.5, r=1, center=(0,0,1))] detector = detector_grid(5, .1) for s in scatterers: calc_holo(detector, s, illum_wavelen=.66, medium_index=1.33, illum_polarization = (1,0), theory=DDA(use_indicators=False)) except DependencyMissing: raise SkipTest
from holopy.core import detector_grid, detector_points from holopy.core.metadata import update_metadata, flat from holopy.scattering.theory.scatteringtheory import ScatteringTheory from holopy.scattering.theory import Mie from holopy.scattering.scatterer import Sphere, Spheres, Ellipsoid from holopy.scattering.errors import TheoryNotCompatibleError from holopy.scattering.interface import prep_schema from holopy.scattering.tests.common import xschema as XSCHEMA SPHERE = Sphere(n=1.5, r=1.0, center=(0, 0, 2)) SPHERES = Spheres([ Sphere(n=1.5, r=1.0, center=(-1, -1, 2)), Sphere(n=1.5, r=1.0, center=(+1, +1, 2)), ]) ELLIPSOID = Ellipsoid(n=1.5, r=(0.5, 0.5, 1.2), center=(0, 0, 2)) TOLS = {'atol': 1e-14, 'rtol': 1e-14} MEDTOLS = {'atol': 1e-7, 'rtol': 1e-7} SCAT_SCHEMA = prep_schema(detector_grid(shape=(5, 5), spacing=.1), medium_index=1.33, illum_wavelen=0.66, illum_polarization=False) class MockTheory(ScatteringTheory): """Minimally-functional daughter of ScatteringTheory for fast tests.""" def __init__(*args, **kwargs): pass # an init is necessary for the repr def _can_handle(self, scatterer):