.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/inverse/fit_unit_aware_diameter.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_unit_aware_diameter.py: Fit a unit-aware diameter ========================= Parameters can carry Pint units. The model receives values with the original units, so the physics code does not need to know how the optimizer stores its internal scalar coordinates. The fitted diameter is approximately 120 nanometers: doubling it reproduces the 240 nm observation. This scalar example demonstrates unit handling, not a scattering forward model. .. GENERATED FROM PYTHON SOURCE LINES 13-36 .. rst-class:: sphx-glr-script-out .. code-block:: none 120.00007629394531 nanometer | .. code-block:: Python from PyMieSim import FitParameter, MeasuredData, fit_parameters, ureg observation = MeasuredData(values=240 * ureg.nanometer) def model(parameters): diameter = parameters["diameter"] return 2 * diameter result = fit_parameters( model=model, observation=observation, parameters=[ FitParameter( name="diameter", initial=150 * ureg.nanometer, bounds=(50 * ureg.nanometer, 300 * ureg.nanometer), ) ], ) print(result.parameters["diameter"]) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.004 seconds) .. _sphx_glr_download_gallery_inverse_fit_unit_aware_diameter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fit_unit_aware_diameter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fit_unit_aware_diameter.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fit_unit_aware_diameter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_