Example #1
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()
Example #2
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()
Example #3
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)
Example #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)
Example #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'))
Example #6
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()
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)
Example #8
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)
Example #9
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)
Example #10
0
    def test00(self):
        from PyMieSim.Scatterer import Sphere
        global sScat
        sScat = Sphere(Diameter=300e-9, Index=1.4, Source=LightSource)

        print('Sphere initialisation passed')
Example #11
0
 def step00(self):
     print("\nUnittest: <Scatterer>" + '='*100)
     self.sphere = Sphere(Diameter = 300e-9, Index = 1.4, Source = self.Source)
Example #12
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()
Example #13
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()
Example #14
0
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]
}


def CloseMatplotlib():
Example #15
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')
Example #16
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')
Example #17
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')