.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/spectro/beer_lambert/plot_01_beer_lambert.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_api_gallery_spectro_beer_lambert_plot_01_beer_lambert.py: Beer-Lambert absorbance, and its deviation from linearity at high concentration ================================================================================== Absorbance is exactly linear in concentration by the ideal Beer-Lambert law. A small amount of instrumental stray light (light that reaches the detector without having passed through the fully absorbing sample path) causes the apparent absorbance to fall increasingly below the true value as concentration -- and hence true absorbance -- increases, the classic "rolling over" deviation seen in real UV-Vis instruments. .. GENERATED FROM PYTHON SOURCE LINES 14-30 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.spectro.systems.beer_lambert import absorbance, apparent_absorbance_with_stray_light from chemistrykit.spectro.visualizers.spectro_plots import plot_beer_lambert_deviation epsilon = 8000.0 # L mol^-1 cm^-1 path_length = 1.0 # cm concentrations = np.linspace(1e-6, 5e-4, 200) true_absorbance = absorbance(epsilon, concentrations, path_length) apparent = np.array([apparent_absorbance_with_stray_light(epsilon, c, path_length, stray_light_fraction=0.002) for c in concentrations]) print(f"At the lowest concentration, true A = {true_absorbance[0]:.4f}, apparent A = {apparent[0]:.4f}") print(f"At the highest concentration, true A = {true_absorbance[-1]:.4f}, apparent A = {apparent[-1]:.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none At the lowest concentration, true A = 0.0080, apparent A = 0.0071 At the highest concentration, true A = 4.0000, apparent A = 2.6778 .. GENERATED FROM PYTHON SOURCE LINES 31-35 The deviation (true minus apparent) grows sharply once the true absorbance gets large enough that the fixed stray-light fraction is no longer negligible next to the (exponentially shrinking) transmitted intensity: .. GENERATED FROM PYTHON SOURCE LINES 35-40 .. code-block:: Python deviation = true_absorbance - apparent print(f"Deviation at A~0.1: {deviation[np.argmin(np.abs(true_absorbance - 0.1))]:.5f}") print(f"Deviation at A~3.5: {deviation[np.argmin(np.abs(true_absorbance - 3.5))]:.5f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Deviation at A~0.1: 0.00111 Deviation at A~3.5: 0.86348 .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python ax = plot_beer_lambert_deviation(molar_absorptivity=epsilon, path_length=path_length, concentrations=concentrations, stray_light_fraction=0.002) plt.show() .. image-sg:: /api/gallery/spectro/beer_lambert/images/sphx_glr_plot_01_beer_lambert_001.png :alt: Beer-Lambert law: deviation from linearity :srcset: /api/gallery/spectro/beer_lambert/images/sphx_glr_plot_01_beer_lambert_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.036 seconds) .. _sphx_glr_download_api_gallery_spectro_beer_lambert_plot_01_beer_lambert.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_beer_lambert.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_beer_lambert.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_beer_lambert.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_