Esempio n. 1
0
def Correctness():
    Phi = np.linspace(-np.pi / 2, np.pi / 2, 100)
    Theta = np.linspace(-np.pi, np.pi, 100)

    THETA, PHI = np.meshgrid(Theta, Phi)

    beam = PlaneWave(Wavelength=1e-6)
    BSC = beam.GetBSC(MaxOrder=30)

    argsPy = {
        "Index": 1.4,
        "Diameter": 10e-6,
        "Wavelength": 1e-6,
        "nMedium": 1.0,
        "Polarization": 0.0,
        "E0": 1.0,
        "R": 1.0,
        "Phi": Phi,
        "Theta": Theta
    }

    argsLMT = {
        "Index": 1.4,
        "Diameter": 10e-6,
        "Wavelength": 1e-6,
        "nMedium": 1.0,
        "Polarization": 0.0,
        "E0": 1.0
    }

    argsGLMT = {
        "Index": 1.4,
        "Diameter": 10e-6,
        "Wavelength": 1e-6,
        "nMedium": 1.0,
        "Polarization": 0.0,
        "E0": 1.0,
        "BSC": beam._BSC_
    }

    PyEPhi, PyETheta = PyField(**argsPy)

    CppEPhi, CppETheta = SPHERELMT(**argsLMT).sFields(Phi=Phi,
                                                      Theta=Theta,
                                                      R=1.)

    GLMTCppEPhi, GLMTCppETheta = SPHEREGLMT(**argsGLMT).sFields(Phi=Phi,
                                                                Theta=Theta,
                                                                R=1.)

    PlotField(Theta, Phi, CppEPhi, CppETheta)

    PlotField(Theta, Phi, GLMTCppEPhi, GLMTCppETheta)

    #PlotField(Theta, Phi, PyEPhi, PyETheta)

    plt.show()
Esempio n. 2
0
    def step11(self):


        theoretical  = np.genfromtxt(f"{TestDataPath}/Figure810BH.csv", delimiter=',')
        x            = theoretical[:,0]
        y            = theoretical[:,1]

        Source       = PlaneWave(Wavelength  = 470e-9, Polarization = None, Amplitude = 1)
        Scat         = Cylinder(Diameter = 3000e-9, Source = Source, Index = 1.00+0.07j, nMedium = 1.0)
        S1S2         = Scat.S1S2(Phi = x+90)
        Data         = ( np.abs(S1S2['S1'])**2  + np.abs(S1S2['S2'])**2 ) * ( 0.5 / (np.pi * Source.k) )**(1/4)

        error = np.abs( ( Data - y ) / y )

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot( S1S2['Phi']-90, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( x, y,'k--', linewidth=1, label='B&H [8.10]')

        plt.xlabel('Scattering angle [degree]'); plt.ylabel('Phase function')
        plt.yscale('log'); plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()


        if not np.all(error < 1):
            raise
Esempio n. 3
0
def run():
    from PyMieSim.Scatterer import Cylinder
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, Amplitude=1)

    Scat = Cylinder(Diameter=800e-9, Source=Source, Index=1.445)
Esempio n. 4
0
def run(Plot, Save):
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source import PlaneWave
    from PyMieSim import Material

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1)

    Scat = Sphere(Diameter=800e-9, Source=Source, Index=1.445)
Esempio n. 5
0
def run():
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source import PlaneWave
    from PyOptik import ExpData

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, Amplitude=1)

    Scat = Sphere(Diameter=300e-9, Source=Source, Material=ExpData('BK7'))
def run(Plot, Save):
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1)

    Scat = Sphere(Diameter=800e-9, Source=Source, Index=1.4)

    print(Scat.Properties)
Esempio n. 7
0
def run():
    from PyMieSim.Tools.Directories import TestDataPath
    import matplotlib.pyplot as plt
    import numpy as np
    from PyMieSim.Scatterer import Cylinder
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=470e-9, Polarization=None, Amplitude=1)

    Scat = Cylinder(Diameter=2992e-9,
                    Source=Source,
                    Index=1.00 + 0.07j,
                    nMedium=1.0)

    x = Scat.SizeParameter

    theoretical = np.genfromtxt(f"{TestDataPath}/Figure810BH.csv",
                                delimiter=',')
    x = theoretical[:, 0]
    y = theoretical[:, 1]

    Source = PlaneWave(Wavelength=470e-9, Polarization=None, Amplitude=1)
    Scat = Cylinder(Diameter=3000e-9,
                    Source=Source,
                    Index=1.00 + 0.07j,
                    nMedium=1.0)
    S1S2 = Scat.S1S2(Phi=x + 90)
    data = (np.abs(S1S2['S1'])**2 +
            np.abs(S1S2['S2'])**2) * (0.5 / (np.pi * Source.k))**(1 / 4)

    error = np.abs((data - y) / y)
    print(error < 1)
    plt.figure()
    plt.plot(S1S2['Phi'] - 90, data, 'C1-', linewidth=3, label='PyMieSim')

    plt.plot(x, y, 'k--', linewidth=1, label='B&H [8.10]')

    plt.xlabel('Scattering angle [degree]')
    plt.ylabel('Phase function')
    # plt.yscale('log')
    plt.grid()
    plt.legend()
    plt.show()
Esempio n. 8
0
def run():
    from PyMieSim.Scatterer import Sphere, Cylinder
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=500e-9, Polarization=0, Amplitude=1)

    Scat = Sphere(Diameter=1000e-9, Source=Source, Index=1.4, nMedium=1.0)

    SPF = Scat.SPF(Num=300)

    SPF.Plot()
Esempio n. 9
0
def run():
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, Amplitude=1)

    Scat = Sphere(Diameter=300e-9, Source=Source, Index=1.4)

    Stokes = Scat.Stokes(Num=100)

    Stokes.Plot()
Esempio n. 10
0
def run(Plot, Save):
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Detector import Photodiode

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1)

    Detector = Photodiode(NA=0.8, Sampling=1001, GammaOffset=0, PhiOffset=0)

    if Plot:
        Detector.Plot()

    if Save:
        from pathlib import Path
        dir = f'docs/images/{Path(__file__).stem}'
        Detector.SaveFig(dir)
Esempio n. 11
0
def run(Plot, Save):
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source import PlaneWave

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1)

    Scat = Sphere(Diameter=300e-9, Source=Source, Index=1.4)

    Fields = Scat.FarField(Num=100)

    if Plot:
        Fields.Plot()

    if Save:
        from pathlib import Path
        dir = f'docs/images/{Path(__file__).stem}'
        Fields.SaveFig(Directory=dir)
Esempio n. 12
0
def run():
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Source   import PlaneWave


    Source = PlaneWave(Wavelength   = 1000e-9,
                       Polarization = 0,
                       Amplitude    = 1)

    Scat = Sphere(Diameter    = 500e-9,
                  Source      = Source,
                  Index       = 1.4)


    Fields = Scat.FarField(Num=100)

    Fields.Plot()
Esempio n. 13
0
def run(Plot, Save):
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Detector import Photodiode
    from PyMieSim.Scatterer import Sphere

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1)

    Detector = Photodiode(Sampling=201,
                          NA=0.2,
                          GammaOffset=0,
                          PhiOffset=0,
                          CouplingMode='Centered')

    Scat = Sphere(Diameter=300e-9, Source=Source, Index=1.4)

    Coupling = Detector.Coupling(Scatterer=Scat)

    print(Coupling)  # 6.566085549292496e-18 Watt  (6.57e-03 fWatt)
Esempio n. 14
0
def run(Plot, Save):
    return
    import numpy as np
    from PyMieSim.Detector import Photodiode, LPmode
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Optimizer import Optimize
    from PyMieSim.Sets import ExperimentalSet, ScattererSet

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, E0=1e5)

    Detector0 = Photodiode(NA=0.1,
                           Sampling=300,
                           GammaOffset=20,
                           PhiOffset=0,
                           CouplingMode='Centered')

    Detector1 = Photodiode(NA=0.1,
                           Sampling=300,
                           GammaOffset=30,
                           PhiOffset=0,
                           CouplingMode='Centered')

    ScatSet = ScattererSet(DiameterList=np.linspace(100e-9, 1500e-9, 300),
                           IndexList=np.linspace(1.5, 1.8, 1).round(1),
                           Source=Source)

    Set = ExperimentalSet(ScattererSet=ScatSet, Detectors=(Detector0))

    Opt = Optimize(ExperimentalSet=Set,
                   Metric='Monotonic',
                   Parameter=['NA', 'PhiOffset'],
                   MinVal=[1e-1, None],
                   MaxVal=[1, None],
                   WhichDetector=0,
                   X0=[0.1, 30],
                   MaxIter=350,
                   Tol=1e-4,
                   FirstStride=30)

    print(Opt.Result)

    df = Set.DataFrame
    if Plot:
        df.Plot('Coupling')  # can be "Couplimg"  or  "STD"
Esempio n. 15
0
def run():
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Detector import LPmode
    from PyMieSim.Scatterer import Sphere

    Source = PlaneWave(Wavelength=450e-9, Polarization=0, Amplitude=1)

    Detector = LPmode(Mode=(1, 1),
                      Sampling=600,
                      NA=0.2,
                      GammaOffset=180,
                      PhiOffset=0,
                      CouplingMode='Point')

    Scat = Sphere(Diameter=300e-9, Source=Source, Index=1.4)

    Coupling = Detector.Coupling(Scatterer=Scat)

    print(Coupling)  # 6.566085549292496e-18 Watt  (6.57e-03 fWatt)
Esempio n. 16
0
def run(Plot, Save):
    from PyMieSim.Source   import PlaneWave
    from PyMieSim.Detector import LPmode


    Source = PlaneWave(Wavelength   = 450e-9,
                      Polarization = 0,
                      E0           = 0)

    Detector = LPmode(Mode         = (1, 1),
                     Rotation     = 0.,
                     Sampling     = 201,
                     NA           = 0.4,
                     GammaOffset  = 0,
                     PhiOffset    = 40,
                     CouplingMode = 'Centered')

    if Plot:
        Detector.Plot()

    if Save:
        from pathlib import Path
        dir = f'docs/images/{Path(__file__).stem}'
        Detector.SaveFig(dir)
Esempio n. 17
0
from numpy import linspace, pi
from pyface.api import GUI
import matplotlib.pyplot as plt
import numpy as np

from PyMieSim.Scatterer import Sphere, Cylinder, WMSample
from PyMieSim.Source import PlaneWave, GaussianBeam
from PyMieSim.GLMT.python.Sphere import SPF
from PyMieSim.Detector import LPmode, Photodiode, _Photodiode
from PyMieSim.Experiment import ScatSet, Setup, SourceSet, SampleSet, DetectorSet
from PyMieSim.Tools.Mesh import FibonacciMesh
from PyMieSim.Tools.Plots import *
from PyMieSim.Tools.Representations import S1S2
from unittest.mock import patch

LightSource = PlaneWave(Wavelength=450e-9, Polarization=0)
Scat = Sphere(Diameter=300e-9, Index=1.4, Source=LightSource)
Samp = WMSample(g=0.8, lc=1e-5, D=2.5, Nc=1e4, Source=LightSource)
Detector = LPmode(Mode=(0, 1, 'h'), Sampling=11, NA=0.2)
Detector1 = Photodiode(Sampling=11, NA=0.2)
phi = linspace(-pi / 2, pi / 2, 4)
theta = linspace(-pi, pi, 4)

scatKwargs = {'Diameter': 200e-9, 'Index': [4], 'nMedium': [1]}

sourceKwargs = {
    'Wavelength': np.linspace(400e-9, 1000e-9, 10),
    'Polarization': [0]
}

Esempio n. 18
0
class QuantitativeTestCase(unittest.TestCase, BaseStepTest):
    Source = PlaneWave(**SourceKwarsgs)

    sphere = Sphere(Diameter = 300e-9, Index = 1.4, Source = Source)

    @TestFactory('Validation QSca - CrossSection')
    def step00(self):
        print("\nUnittest: <Quantitative>" + '='*100)
        Mesh   = FibonacciMesh(MaxAngle = np.pi, Sampling = 1000, PhiOffset = 0, GammaOffset = 0)
        val0   = self.sphere.CrossSection(Mesh)
        val1   = self.sphere.Qsca * self.sphere.Area
        if not np.isclose( val0, val1, 1e-50 ):
            raise

    @TestFactory('Validation EnergyFlow - coupling')
    def step01(self):
        detector        = Photodiode(Sampling = 500, NA = 2.0)
        val0            = self.sphere.EnergyFlow(detector.Mesh)
        val1            = detector.Coupling(self.sphere)
        if not np.isclose( val0, val1, 1e-10 ):
            raise

    @TestFactory('Validation scattering cross-section -> Scott Prahl')
    def step02(self):
        Value = Sphere(Diameter = 1e-6, Index = 1.5, Source = self.Source).Csca
        if not np.isclose( Value, 2.7349e-12, 0.001 ):
            raise


    @TestFactory('Validation g = <cos> -> Scott Prahl')
    def step03(self):
        Value = Sphere(Diameter = 1e-6, Index = 1.5, Source = self.Source).g
        if not np.isclose( Value, 0.72924, 0.001 ):
            raise

    @TestFactory('Validation extinction cross-section -> Scott Prahl')
    def step04(self):
        Value = Sphere(Diameter = 1e-6, Index = 1.5 + 1j, Source = self.Source).Cext
        if not np.isclose( Value, 2.1422e-12, 0.001 ):
            raise


    @TestFactory('Validation cylinder with BH figure 8.7')
    def step05(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/Figure87BH.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 6e-6, 800)
        Volume       = np.pi * (Diameter/2)**2
        scatSet      = CylinderSet(Diameter =  Diameter, Index = 1.55, nMedium = 1.)
        sourceSet    = SourceSet(Wavelength = 632.8e-9, Polarization = [0, 90], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Csca).Data.squeeze()/Volume*1e-4/100

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data[0],'C0-', linewidth=3, label='PyMieSim' )
        plt.plot(Diameter, Data[1],'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical[0],'k--', linewidth=1, label='BH 8.8')
        plt.plot( Diameter, theoretical[1],'k--', linewidth=1, label='BH 8.8')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering cross section [Cylinder]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()


        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation cylinder with BH figure 8.8')
    def step06(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/Figure88BH.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 6e-6, 800)
        Volume       = np.pi * (Diameter/2)**2
        scatSet      = CylinderSet(Diameter =  Diameter, Index = 1.55, nMedium = 1.335)
        sourceSet    = SourceSet(Wavelength = 632.8e-9, Polarization = [0, 90], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Csca).Data.squeeze()/Volume*1e-4/100

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data[0],'C0-', linewidth=3, label='PyMieSim' )
        plt.plot(Diameter, Data[1],'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical[0],'k--', linewidth=1, label='BH 8.8')
        plt.plot( Diameter, theoretical[1],'k--', linewidth=1, label='BH 8.8')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering cross section [Cylinder]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()

        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation PyMieScatt sphere')
    def step07(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/PyMieScattQsca.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 6e-6, 800)
        scatSet      = SphereSet(Diameter =  Diameter, Index = 1.4, nMedium = 1.)
        sourceSet    = SourceSet(Wavelength = 632.8e-9, Polarization = [None], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Qsca).Data.squeeze()

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical,'k--', linewidth=1, label='PyMieScatt')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering efficiency [Sphere]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()

        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation PyMieScatt sphere + nMedium')
    def step08(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/PyMieScattQscaMedium.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 6e-6, 800)
        scatSet      = SphereSet(Diameter =  Diameter, Index = 1.4, nMedium = 1.21)
        sourceSet    = SourceSet(Wavelength = 632.8e-9, Polarization = [None], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Qsca).Data.squeeze()

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical,'k--', linewidth=1, label='PyMieScatt')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering efficiency [Sphere + nMedium]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()

        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation PyMieScatt CoreShell')
    def step09(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/PyMieScattQscaCoreShell.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 500e-9, 400)
        scatSet      = CoreShellSet(CoreDiameter = Diameter, ShellDiameter = 600e-9, CoreIndex = 1.4, ShellIndex=1.5, nMedium = 1.0)
        sourceSet    = SourceSet(Wavelength = 600e-9, Polarization = [None], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Qsca).Data.squeeze()

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical,'k--', linewidth=1, label='PyMieScatt')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering efficiency [CoreShell]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()

        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation PyMieScatt CoreShell + nMedium')
    def step10(self):
        theoretical  = np.genfromtxt(f"{TestDataPath}/PyMieScattQscaCoreShellMedium.csv", delimiter=',')

        Diameter     = np.geomspace(10e-9, 500e-9, 400)
        scatSet      = CoreShellSet(CoreDiameter = Diameter, ShellDiameter = 600e-9, CoreIndex = 1.4, ShellIndex=1.5, nMedium = 1.2)
        sourceSet    = SourceSet(Wavelength = 600e-9, Polarization = [None], Amplitude = 1)
        ExpSet       = Setup(ScattererSet = scatSet, SourceSet = sourceSet, DetectorSet  = None)
        Data         = ExpSet.Get(Measure.Qsca).Data.squeeze()

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot(Diameter, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( Diameter, theoretical,'k--', linewidth=1, label='PyMieScatt')

        plt.xlabel(r'Diameter [\mu m]'); plt.ylabel('Scattering efficiency [CoreShell + nMedium]')
        plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()

        if not np.all(np.isclose(Data,theoretical, 1e-9)):
            raise


    @TestFactory('Validation cylinder with BH figure 8.10')
    def step11(self):


        theoretical  = np.genfromtxt(f"{TestDataPath}/Figure810BH.csv", delimiter=',')
        x            = theoretical[:,0]
        y            = theoretical[:,1]

        Source       = PlaneWave(Wavelength  = 470e-9, Polarization = None, Amplitude = 1)
        Scat         = Cylinder(Diameter = 3000e-9, Source = Source, Index = 1.00+0.07j, nMedium = 1.0)
        S1S2         = Scat.S1S2(Phi = x+90)
        Data         = ( np.abs(S1S2['S1'])**2  + np.abs(S1S2['S2'])**2 ) * ( 0.5 / (np.pi * Source.k) )**(1/4)

        error = np.abs( ( Data - y ) / y )

        GUI.invoke_after(PLOTTIME, Close)
        plt.figure()
        plt.plot( S1S2['Phi']-90, Data,'C1-', linewidth=3, label='PyMieSim' )

        plt.plot( x, y,'k--', linewidth=1, label='B&H [8.10]')

        plt.xlabel('Scattering angle [degree]'); plt.ylabel('Phase function')
        plt.yscale('log'); plt.grid(); plt.legend(); plt.tight_layout()
        plt.show()


        if not np.all(error < 1):
            raise
Esempio n. 19
0
class ScattererTestCase(unittest.TestCase, BaseStepTest):

    Source        = PlaneWave(Wavelength = 450e-9, Polarization = 0)

    photodiode         = Photodiode(**DetectorKwarg)

    lpmode             = LPmode(Mode  = (0,1), **DetectorKwarg)

    integratingSphere  = IntegratingSphere()


    #___________________________________SPHERE________________________________________________________________
    @TestFactory('Spherical scatterer initialization')
    def step00(self):
        print("\nUnittest: <Scatterer>" + '='*100)
        self.sphere = Sphere(Diameter = 300e-9, Index = 1.4, Source = self.Source)


    @TestFactory('Spherical Scatterer <S1S2> compute')
    def step03(self):
        self.sphere.S1S2(Num=40)


    @TestFactory('Spherical Scatterer <Stokes> compute')
    def step04(self):
        self.sphere.Stokes(Num=40)


    @TestFactory('Spherical Scatterer <FarFields> compute')
    def step04(self):
        self.sphere.FarField(Num=30)


    @TestFactory('Spherical Scatterer <SPF> compute')
    def step05(self):
        self.sphere.SPF(Num=30)


    @TestFactory('Spherical Scatterer <An & Bn> compute')
    def step06(self):
        pass
        self.sphere.an(3)
        self.sphere.an()
        self.sphere.bn(3)
        self.sphere.bn()
        self.sphere.cn(3)
        self.sphere.cn()
        self.sphere.dn(3)
        self.sphere.dn()


    @TestFactory('Spherical Scatterer <S1S2> plotting')
    def step07(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.sphere.S1S2(Num=40).Plot()


    @TestFactory('Spherical Scatterer <Stokes> plotting')
    def step08(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.sphere.Stokes(Num=40).Plot()


    @TestFactory('Spherical Scatterer <FarField> plotting')
    def step09(self):
        GUI.invoke_after(PLOTTIME, Close)
        GUI.invoke_after(2*PLOTTIME, Close)
        self.sphere.FarField(Num=40).Plot()


    @TestFactory('Spherical Scatterer <SPF> plotting')
    def step10(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.sphere.SPF(Num=40).Plot()


    @TestFactory('Spherical <Photodiode> coupling')
    def step11(self):
        self.photodiode.Coupling(Scatterer = self.sphere)


    @TestFactory('Spherical <LPmode> coupling')
    def step12(self):
        self.lpmode.Coupling(Scatterer = self.sphere)


    @TestFactory('Spherical <IntegratingSphere> coupling')
    def step13(self):
        self.integratingSphere.Coupling(Scatterer = self.sphere)


    @TestFactory('Spherical Photodiode footprint compute')
    def step14(self):
        self.photodiode.Footprint(Scatterer=self.sphere)


    @TestFactory('Spherical LPmode footprint compute')
    def step15(self):
        self.lpmode.Footprint(Scatterer=self.sphere)


    #___________________________________CYLINDER________________________________________________________________
    @TestFactory('Cylindrical scatterer initialization')
    def step16(self):
        self.cylinder = Cylinder(Diameter = 300e-9, Index = 1.4, Source = self.Source)


    @TestFactory('Cylindrical Scatterer <S1S2> compute')
    def step17(self):
        self.cylinder.S1S2(Num=40)


    @TestFactory('Cylindrical Scatterer <Stokes> compute')
    def step18(self):
        self.cylinder.Stokes(Num=40)


    @TestFactory('Cylindrical Scatterer <FarFields> compute')
    def step19(self):
        self.cylinder.FarField(Num=30)


    @TestFactory('Cylindrical Scatterer <SPF> compute')
    def step20(self):
        self.cylinder.SPF(Num=30)


    @TestFactory('Cylindrical Scatterer <An & Bn> compute')
    def step21(self):
        self.cylinder.an(3)
        self.cylinder.an()
        self.cylinder.bn(3)
        self.cylinder.bn()


    @TestFactory('Cylindrical Scatterer <S1S2> plotting')
    def step22(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.cylinder.S1S2(Num=10).Plot()


    @TestFactory('Cylindrical Scatterer <Stokes> plotting')
    def step23(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.cylinder.Stokes(40).Plot()


    @TestFactory('Cylindrical Scatterer <FarField> plotting')
    def step24(self):
        GUI.invoke_after(PLOTTIME, Close)
        GUI.invoke_after(2*PLOTTIME, Close)
        self.cylinder.FarField(40).Plot()


    @TestFactory('Cylindrical Scatterer <SPF> plotting')
    def step25(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.cylinder.SPF(40).Plot()


    @TestFactory('Cylindrical <Photodiode> coupling')
    def step26(self):
        self.photodiode.Coupling(Scatterer = self.cylinder)


    @TestFactory('Cylindrical <LPmode> coupling')
    def step27(self):
        self.lpmode.Coupling(Scatterer = self.cylinder)


    @TestFactory('Cylindrical <IntegratingSphere> coupling')
    def step28(self):
        self.integratingSphere.Coupling(Scatterer = self.cylinder)


    @TestFactory('Cylindrical Photodiode footprint compute')
    def step29(self):
        self.photodiode.Footprint(Scatterer=self.cylinder)


    @TestFactory('Cylindrical LPmode footprint compute')
    def step30(self):
        self.lpmode.Footprint(Scatterer=self.cylinder)


    # #___________________________________CORESHELL________________________________________________________________
    @TestFactory('Core/Shell scatterer initialization')
    def step31(self):
        self.coreShell = ShellSphere(CoreDiameter = 300e-9, ShellWidth=200e-9, CoreIndex = 1.4, ShellIndex=1.5, Source = self.Source)


    @TestFactory('Core/Shell Scatterer <S1S2> compute')
    def step32(self):
        self.coreShell.S1S2(Num=40)


    @TestFactory('Core/Shell Scatterer <Stokes> compute')
    def step33(self):
        self.coreShell.Stokes(Num=40)


    @TestFactory('Core/Shell Scatterer <FarFields> compute')
    def step34(self):
        self.coreShell.FarField(Num=30)


    @TestFactory('Core/Shell Scatterer <SPF> compute')
    def step35(self):
        self.coreShell.SPF(Num=30)


    @TestFactory('Core/Shell Scatterer <An & Bn> compute')
    def step36(self):
        self.coreShell.an(3)
        self.coreShell.an()
        self.coreShell.bn(3)
        self.coreShell.bn()


    @TestFactory('Core/Shell Scatterer <S1S2> plotting')
    def step37(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.coreShell.S1S2(Num=10).Plot()


    @TestFactory('Core/Shell Scatterer <Stokes> plotting')
    def step38(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.coreShell.Stokes(40).Plot()


    @TestFactory('Core/Shell Scatterer <FarField> plotting')
    def step39(self):
        GUI.invoke_after(PLOTTIME, Close)
        GUI.invoke_after(2*PLOTTIME, Close)
        self.coreShell.FarField(40).Plot()


    @TestFactory('Core/Shell Scatterer <SPF> plotting')
    def step40(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.coreShell.SPF(40).Plot()


    @TestFactory('Core/Shell <Photodiode> coupling')
    def step41(self):
        self.photodiode.Coupling(Scatterer = self.coreShell)


    @TestFactory('Core/Shell <LPmode> coupling')
    def step42(self):
        self.lpmode.Coupling(Scatterer = self.coreShell)


    @TestFactory('Core/Shell <IntegratingSphere> coupling')
    def step43(self):
        self.integratingSphere.Coupling(Scatterer = self.coreShell)


    @TestFactory('Core/Shell Photodiode footprint compute')
    def step44(self):
        self.photodiode.Footprint(Scatterer=self.coreShell)


    @TestFactory('Core/Shell LPmode footprint compute')
    def step45(self):
        self.footprint = self.lpmode.Footprint(Scatterer=self.coreShell)


    @TestFactory('Core/Shell Scatterer <Footprint> plotting')
    def step46(self):
        GUI.invoke_after(PLOTTIME, Close)
        self.footprint.Plot()
Esempio n. 20
0
 def test02(self):
     global PWbeam
     PWbeam = PlaneWave(Wavelength=0.632e-6, Polarization=0)
     print('PlaneWave beam initialisation passed')
Esempio n. 21
0
def run(Plot, Save):
    # import PyMieSim
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Scatterer import Sphere

    # import other librairies
    import math
    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.axes_grid1 import make_axes_locatable
    import matplotlib

    # set the source using PyMieSim
    Source = PlaneWave(Wavelength=450e-9, Polarization=0, Amplitude=1)
    # create an empty list that will contain the heatmap values
    heatmap = []

    # loop through all the values to generate the heatmap
    # first, loop through the diameter values
    for i in range(1, 517):
        x = []
        # second, loop through the index values
        for j in range(-100, 501):
            if j == 0:
                continue

            Scat = Sphere(Diameter=i / 3 * 1e-9,
                          Source=Source,
                          Index=(j /
                                 10)**0.5)  # square root since permittivity
            # is the index squared
            # Get the scattering efficiency using GetProperties()
            prop = Scat.GetProperties()
            Qsca = prop[1]
            x.append(Qsca)
        # append list (row) to the heatmap (list of lists)
        heatmap.append(x)

    # convert the heatmap to a numpy array
    data = np.array(heatmap)

    # create the plot
    fig, ax = plt.subplots()
    # show the data and adjust the color scale
    im = ax.imshow(data,
                   norm=matplotlib.colors.LogNorm(vmin=0.1, vmax=10),
                   cmap='viridis')

    # graph title
    ax.set_title("Scattering efficiency of a sphere")

    # x axis settings
    ax.set_xlabel("Permittivity")
    ax.set_xticks(np.linspace(0, len(heatmap[0]), 7))
    ax.set_xticklabels([-10, 0, 10, 20, 30, 40, 50])

    # y axis settings
    ax.set_ylabel("Size parameter")
    ax.invert_yaxis()
    ax.set_yticks(np.linspace(0, len(heatmap), 7))
    ax.set_yticklabels([0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2])

    # colorbar settings
    divider = make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(im, cax=cax)

    # display the plot in a tight layout
    fig.tight_layout()
    plt.show()
Esempio n. 22
0
 def test02(self):
     Source = PlaneWave(Wavelength=1e-6)
     Csca = Sphere(Diameter=1e-6, Index=1.5, Source=Source).Csca
     assert np.isclose(Csca, 2.7349e-12, 0.001)
     print('Validation scattering cross-section -> Scott Prahl')
Esempio n. 23
0
 def test04(self):
     Source = PlaneWave(Wavelength=1e-6)
     Cext = Sphere(Diameter=1e-6, Index=1.5 + 1j, Source=Source).Cext
     assert np.isclose(Cext, 2.1422e-12, 0.001)
     print('Validation extinction sross-section -> Scott Prahl')
Esempio n. 24
0
 def test03(self):
     Source = PlaneWave(Wavelength=1e-6)
     g = Sphere(Diameter=1e-6, Index=1.5, Source=Source).g
     assert np.isclose(g, 0.72924, 0.001)
     print('Validation g = <cos> -> Scott Prahl')