예제 #1
0
def run():
    from PyMieSim.Detector import Photodiode

    Detector = Photodiode(NA=0.8,
                          Sampling=500,
                          GammaOffset=0,
                          PhiOffset=0,
                          Filter=None,
                          CouplingMode='Point')

    Detector.Plot()
예제 #2
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)
예제 #3
0
class DetectorTestCase(unittest.TestCase, BaseStepTest):
    @TestFactory('Photodiode initialisation')
    def step00(self):
        print("\nUnittest: <Detector>" + '=' * 100)
        self._Photodiode = Photodiode(**DetectorKwarg)

    @TestFactory('LPmode initialisation')
    def step01(self):
        self._LPmode = LPmode(Mode=(0, 1), **DetectorKwarg)

    @TestFactory('IntegratingSphere initialisation')
    def step02(self):
        self._IntegratingSphere = IntegratingSphere()

    @TestFactory('Photodiode plotting')
    def step03(self):
        GUI.invoke_after(PLOTTIME, Close)
        self._Photodiode.Plot()

    @TestFactory('Photodiode plotting')
    def step04(self):
        GUI.invoke_after(PLOTTIME, Close)
        self._LPmode.Plot()

    @TestFactory('IntegratingSphere plotting')
    def step05(self):
        GUI.invoke_after(PLOTTIME, Close)
        self._IntegratingSphere.Plot()
예제 #4
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)
예제 #5
0
    def test00(self):
        global Detector0
        Detector0 = Photodiode(Sampling=11,
                               NA=0.2,
                               GammaOffset=0,
                               PhiOffset=0,
                               CouplingMode='Centered')

        print('Photodiode initialisation passed')
예제 #6
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"
예제 #7
0
 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
예제 #8
0
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():
    """Close matplotlib scene."""
    figures = [
        manager.canvas.figure
예제 #9
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()
예제 #10
0
def run(Plot, Save):
    return
    import numpy as np
    from PyMieSim import Material
    from PyMieSim.Scatterer import Sphere
    from PyMieSim.Detector import Photodiode, LPmode
    from PyMieSim.Source import PlaneWave
    from PyMieSim.Experiment import ScatSet, SourceSet, Setup, DetectorSet

    DiameterList = np.linspace(100e-9, 1000e-9, 200)

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

    scatKwargs = {
        'Diameter': np.linspace(400e-9, 2000e-9, 200),
        'Material': Material('BK7'),
        'nMedium': [1]
    }

    sourceKwargs = {'Wavelength': 1e-6, 'Polarization': [0]}

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

    detecSet = DetectorSet([Detector0])

    scatSet = ScatSet(Scatterer=Sphere, kwargs=scatKwargs)

    sourceSet = SourceSet(Source=PlaneWave, kwargs=sourceKwargs)

    Experiment = Setup(ScattererSet=scatSet,
                       SourceSet=sourceSet,
                       DetectorSet=detecSet)

    # Metric can be "max"
    #               "min"
    #               "mean"
    #               "std+RI"
    #               "std+Diameter"
    #               "std+Polarization"
    #               "std+Wavelength"
    #               "std+Detector"
    #               "monotonic+RI"
    #               "monotonic+Diameter"
    #               "monotonic+Polarization"
    #               "monotonic+Wavelength"
    #               "monotonic+Detector"

    Opt = Experiment.Optimize(Setup=Experiment,
                              Metric='mean',
                              Parameter=['PhiOffset'],
                              Optimum='Maximum',
                              MinVal=[1e-5],
                              MaxVal=[180],
                              WhichDetector=0,
                              X0=[0.6],
                              MaxIter=350,
                              Tol=1e-4,
                              FirstStride=30)

    print(Opt.Result)

    df = Experiment.Coupling(AsType='dataframe')

    if Plot:
        df.Plot(y='Coupling', x='Diameter')  # can be "Couplimg"  or  "STD"
예제 #11
0
import matplotlib
from PyMieSim.Detector import Photodiode
from PyMieSim.Scatterer import Sphere
from PyMieSim.Sets import ScattererSet, ExperimentalSet
from PyMieSim.Source import PlaneWave
from scipy import interpolate
from scipy.integrate import dblquad
from PyMieSim.LMT.Scatterer import SPHERE, CYLINDER


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


Photodiode0 = Photodiode(NA                = 1.,
                         Sampling          = 101,
                         GammaOffset       = 0,
                         PhiOffset         = 0,
                         CouplingMode      = 'Centered')

DiameterList  = np.linspace(100e-9, 2000e-9, 100)

Set1 = ScattererSet(DiameterList  = DiameterList,
                    RIList        = [1.4],
                    Source        = LightSource)


Experience = ExperimentalSet(ScattererSet = Set1, Detectors=Photodiode0)

DF1 = Experience.DataFrame

Theoretical_coupling = []
예제 #12
0
 def step00(self):
     print("\nUnittest: <Detector>" + '=' * 100)
     self._Photodiode = Photodiode(**DetectorKwarg)