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.

Computing scattered near field component: Ex
/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/PyMieSim/single/representations/nearfields.py:259: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
fields[component] = numpy.asarray(values).reshape(self.X.shape)
<Figure size 1200x600 with 4 Axes>
from PyMieSim.units import ureg
from PyMieSim.single.scatterer import Sphere
from PyMieSim.single.source import Gaussian
from PyMieSim.polarization import PolarizationState
from PyMieSim.single.setup import Setup
polarization_state = PolarizationState(angle=0 * ureg.degree)
source = Gaussian(
wavelength=300 * ureg.nanometer,
polarization=polarization_state,
optical_power=1 * ureg.watt,
numerical_aperture=0.3,
)
scatterer = Sphere(
diameter=400 * ureg.nanometer,
material=(1.4 + 5.j),
medium=1.,
)
setup = Setup(
scatterer=scatterer,
source=source,
)
near_field = setup.get_representation("nearfields")
near_field.plot(
"Ex:real",
"Ex:abs",
type="scattered",
plane_origin=(0.0, 0.0, 0.0),
plane_normal=(0.0, 1.0, 0.0),
sampling=100,
extent_scale=4,
tight_layout=True,
)
Total running time of the script: (0 minutes 0.722 seconds)