Note
Go to the end to download the full example code.
Near-Fields Computation and Visualization#
This example demonstrates the process of computing and visualizing the far-fields of a scatterer using PyMieSim.
Importing the package: PyMieSim
from TypedUnit import ureg
from PyMieSim.single.scatterer import Sphere
from PyMieSim.single.source import Gaussian
Defining the source
source = Gaussian(
wavelength=1400 * ureg.nanometer, # 1000 nm
polarization=30 * ureg.degree, # Right circular polarization
optical_power=1 * ureg.watt, # Arbitrary units
NA=0.3 * ureg.AU, # Numerical Aperture
)
Defining the scatterer
scatterer = Sphere(
diameter=1000 * ureg.nanometer, # 1000 nm
source=source,
property=1.8 * ureg.RIU, # Refractive index of the scatterer
medium_property=1.0 * ureg.RIU, # Refractive index of the surrounding medium
)
Computing the data
data = scatterer.get_nearfield(sampling=200, field_components=["Ex"])
Plotting the data
figure = data.plot()

[-1000.0 -989.9497487437186 -979.8994974874372 -969.8492462311558 -959.7989949748744 -949.748743718593 -939.6984924623116 -929.6482412060302 -919.5979899497487 -909.5477386934673 -899.4974874371859 -889.4472361809045 -879.3969849246231 -869.3467336683417 -859.2964824120603 -849.2462311557789 -839.1959798994975 -829.1457286432161 -819.0954773869346 -809.0452261306532 -798.9949748743718 -788.9447236180904 -778.894472361809 -768.8442211055276 -758.7939698492462 -748.7437185929648 -738.6934673366834 -728.643216080402 -718.5929648241206 -708.5427135678392 -698.4924623115578 -688.4422110552764 -678.391959798995 -668.3417085427136 -658.2914572864322 -648.2412060301508 -638.1909547738693 -628.1407035175879 -618.0904522613065 -608.0402010050251 -597.9899497487437 -587.9396984924623 -577.8894472361808 -567.8391959798994 -557.788944723618 -547.7386934673366 -537.6884422110552 -527.6381909547738 -517.5879396984924 -507.537688442211 -497.4874371859296 -487.4371859296482 -477.3869346733668 -467.3366834170854 -457.286432160804 -447.2361809045226 -437.1859296482412 -427.1356783919598 -417.0854271356783 -407.0351758793969 -396.9849246231155 -386.9346733668341 -376.8844221105527 -366.8341708542713 -356.7839195979899 -346.7336683417085 -336.6834170854271 -326.6331658291457 -316.5829145728643 -306.5326633165829 -296.4824120603015 -286.43216080402 -276.3819095477386 -266.3316582914572 -256.2814070351758 -246.2311557788944 -236.180904522613 -226.1306532663316 -216.0804020100502 -206.0301507537688 -195.9798994974874 -185.929648241206 -175.8793969849246 -165.8291457286432 -155.77889447236169 -145.7286432160803 -135.6783919597989 -125.62814070351749 -115.57788944723609 -105.52763819095469 -95.47738693467329 -85.42713567839189 -75.37688442211049 -65.3266331658291 -55.276381909547695 -45.226130653266296 -35.17587939698478 -25.125628140703384 -15.075376884421985 -5.025125628140586 5.025125628140813 15.075376884422212 25.12562814070361 35.17587939698501 45.22613065326641 55.27638190954781 65.32663316582921 75.3768844221106 85.427135678392 95.4773869346734 105.5276381909548 115.5778894472362 125.6281407035176 135.678391959799 145.7286432160804 155.7788944723618 165.82914572864343 175.87939698492482 185.92964824120622 195.97989949748762 206.03015075376902 216.08040201005042 226.13065326633182 236.18090452261322 246.23115577889462 256.281407035176 266.3316582914574 276.3819095477388 286.4321608040202 296.4824120603016 306.532663316583 316.5829145728644 326.6331658291458 336.6834170854272 346.7336683417086 356.78391959799 366.8341708542714 376.8844221105528 386.9346733668342 396.9849246231156 407.035175879397 417.08542713567863 427.13567839196 437.1859296482414 447.2361809045228 457.2864321608042 467.3366834170856 477.386934673367 487.4371859296484 497.4874371859298 507.5376884422112 517.5879396984926 527.638190954774 537.6884422110554 547.7386934673368 557.7889447236182 567.8391959798996 577.889447236181 587.9396984924624 597.9899497487438 608.0402010050252 618.0904522613066 628.140703517588 638.1909547738694 648.2412060301508 658.2914572864322 668.3417085427136 678.3919597989952 688.4422110552766 698.492462311558 708.5427135678394 718.5929648241208 728.6432160804022 738.6934673366836 748.743718592965 758.7939698492464 768.8442211055278 778.8944723618092 788.9447236180906 798.994974874372 809.0452261306534 819.0954773869348 829.1457286432162 839.1959798994976 849.246231155779 859.2964824120604 869.3467336683418 879.3969849246232 889.4472361809046 899.497487437186 909.5477386934674 919.5979899497488 929.6482412060304 939.6984924623118 949.7487437185932 959.7989949748746 969.849246231156 979.8994974874374 989.9497487437188 1000.0] nanometer <class 'pint.Quantity'>
Total running time of the script: (0 minutes 0.393 seconds)