.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/inverse/fit_sphere_scattering.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_inverse_fit_sphere_scattering.py: Fit an isolated-sphere scattering measurement ============================================== Recover a sphere diameter from one dimensionless scattering-efficiency measurement. This uses the isolated-particle Mie model. It does not represent multiple scattering, near-field coupling, or positional correlations in dense particle systems. The fitted diameter is approximately 180 nanometers within the stated bounds. The prediction is a scalar dimensionless efficiency. One noiseless channel with a fixed refractive index demonstrates parameter recovery; it does not establish uniqueness over a wider diameter range. .. GENERATED FROM PYTHON SOURCE LINES 15-53 .. rst-class:: sphx-glr-script-out .. code-block:: none iteration 1 | objective 0.035303537 | step 0.1 iteration 2 | objective 0.0083962553 | step 0.1 iteration 3 | objective 0.00081984712 | step 0.1 iteration 4 | objective 0.00081984712 | step 0.05 iteration 5 | objective 0.00081984712 | step 0.025 iteration 6 | objective 1.2293524e-05 | step 0.025 iteration 7 | objective 1.2293524e-05 | step 0.0125 iteration 8 | objective 1.2293524e-05 | step 0.00625 iteration 9 | objective 1.2293524e-05 | step 0.00313 iteration 10 | objective 1.9310194e-07 | step 0.00313 iteration 11 | objective 1.9310194e-07 | step 0.00156 iteration 12 | objective 1.9310194e-07 | step 0.000781 iteration 13 | objective 1.9310194e-07 | step 0.000391 iteration 14 | objective 3.0152357e-09 | step 0.000391 iteration 15 | objective 3.0152357e-09 | step 0.000195 iteration 16 | objective 3.0152357e-09 | step 9.77e-05 iteration 17 | objective 3.0152357e-09 | step 4.88e-05 iteration 18 | objective 4.711693e-11 | step 4.88e-05 iteration 19 | objective 4.711693e-11 | step 2.44e-05 iteration 20 | objective 4.711693e-11 | step 1.22e-05 iteration 21 | objective 4.711693e-11 | step 6.1e-06 iteration 22 | objective 7.3619446e-13 | step 6.1e-06 iteration 23 | objective 7.3619446e-13 | step 3.05e-06 iteration 24 | objective 7.3619446e-13 | step 1.53e-06 iteration 25 | objective 7.3619446e-13 | step 7.63e-07 converged after 25 iterations | objective 7.3619446e-13 converged (52 model evaluations) objective = 0.000000 | .. code-block:: Python from PyMieSim import ( Measure, FitParameter, MeasuredData, PlaneWave, PolarizationState, Simulation, Sphere, fit_parameters, ureg, ) source = PlaneWave( wavelength=532 * ureg.nanometer, polarization=PolarizationState(angle=0 * ureg.degree), amplitude=1 * ureg.volt / ureg.meter, ) target_diameter = 180 * ureg.nanometer target = Simulation( scatterer=Sphere(diameter=target_diameter, material=1.59, medium=1.0), source=source, ).get(Measure.QSCA) def model(parameters): sphere = Sphere(diameter=parameters["diameter"], material=1.59, medium=1.0) return Simulation(scatterer=sphere, source=source).get(Measure.QSCA) result = fit_parameters( model=model, observation=MeasuredData(values=target), parameters=[ FitParameter( name="diameter", initial=130 * ureg.nanometer, bounds=(80 * ureg.nanometer, 260 * ureg.nanometer), ) ], max_iterations=250, show_progress=True, ) print(result.summary()) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.013 seconds) .. _sphx_glr_download_gallery_inverse_fit_sphere_scattering.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fit_sphere_scattering.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fit_sphere_scattering.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fit_sphere_scattering.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_