.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/results/coherent_diffuse.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_auto_examples_results_coherent_diffuse.py: Coherent and diffuse scattering in an absorbing ensemble ================================================================ Absorption belongs to the random-medium configuration, so every realization has a reproducible kappa field. Compare total intensity, the intensity of the mean scattered amplitude, and their difference through third Born order. .. GENERATED FROM PYTHON SOURCE LINES 9-69 .. code-block:: Python import matplotlib.pyplot as plt from bornsim import ConvergenceReport, EnsembleSampling, GaussianMedium, Grid, Solver, Source from bornsim.units import ureg medium = GaussianMedium( background_refractive_index=1.33, refractive_index_std=0.002, correlation_length=60 * ureg.nanometer, extinction_coefficient=0.0005, ) grid = Grid( shape=(8, 8, 8), spacing=30 * ureg.nanometer, ) source = Source(wavelength=633 * ureg.nanometer) solver = Solver(source=source, order=3) ensemble_sampling = EnsembleSampling(realizations=8, seed=42) result = solver.ensemble( medium=medium, grid=grid, ensemble_sampling=ensemble_sampling, ) averaged = result.azimuth_average() figure, axis = plt.subplots(layout="constrained") for label, data in ( ("Total", averaged.differential), ("Coherent", averaged.coherent_differential), ("Diffuse", averaged.diffuse_differential), ): axis.plot(result.angles.to("degree").magnitude, data.magnitude[-1], label=label) axis.set(xlabel="Scattering angle (degrees)", ylabel="Differential coefficient (m⁻¹ sr⁻¹)") axis.legend() plt.show() absorption_figure, absorption_axis = plt.subplots(layout="constrained") absorption_axis.errorbar( [1, 2, 3], result.mu_a.to("1 / meter").magnitude, yerr=result.mu_a_stderr.to("1 / meter").magnitude, fmt="o-", ) absorption_axis.set(xlabel="Cumulative scattering order", ylabel="Absorption coefficient (m⁻¹)", xticks=[1, 2, 3]) plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/results/images/sphx_glr_coherent_diffuse_001.png :alt: coherent diffuse :srcset: /auto_examples/results/images/sphx_glr_coherent_diffuse_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/results/images/sphx_glr_coherent_diffuse_002.png :alt: coherent diffuse :srcset: /auto_examples/results/images/sphx_glr_coherent_diffuse_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 70-78 Statistical interpretation ---------------------------- Coherent means squared sample-mean scattered amplitude, not the unscattered laser. Diffuse is the population-normalized sample variance of amplitudes. For N realizations its expectation is (N-1)/N times the true variance; with one realization it is zero, not evidence of no diffuse scattering. Increase ensemble size to assess these effects. Error bars here describe sampling uncertainty in absorption, not mesh errors or model validity. .. GENERATED FROM PYTHON SOURCE LINES 80-84 Ensemble-size stability ------------------------- Shared initial seeds correlate the estimates. These are stability comparisons, not independent estimates of an error bar on the difference. .. GENERATED FROM PYTHON SOURCE LINES 84-94 .. code-block:: Python size_results = [] for count in (4, 8, 16): seeds = EnsembleSampling(realizations=count, seed=42) size_results.append(solver.ensemble(medium=medium, grid=grid, ensemble_sampling=seeds)) report = ConvergenceReport(results=tuple(size_results), labels=("4 seeds", "8 seeds", "16 seeds")) print(report.summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none Observable stability (not a physical-validity certificate): 4 seeds: mu_s=17.3245 m^-1, mu_a=9919.034467737558, residual=9.354673840879905e-11, stable=False 8 seeds: mu_s=17.7404 m^-1, mu_a=9918.220264466316, residual=9.375477992306911e-11, stable=False Changes: {'mu_s': 0.02343873593135006, 'mu_a': 8.208493214641103e-05, 'g': 0.11485254677613699, 'phase_l1': 0.16452609011267225} 16 seeds: mu_s=15.9665 m^-1, mu_a=9918.270279016817, residual=9.375477992306911e-11, stable=False Changes: {'mu_s': 0.0999915664222087, 'mu_a': 5.042668640212119e-06, 'g': 0.0013280618258851296, 'phase_l1': 0.010823332785659437} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.544 seconds) .. _sphx_glr_download_auto_examples_results_coherent_diffuse.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: coherent_diffuse.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: coherent_diffuse.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: coherent_diffuse.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_