diff --git a/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb b/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb new file mode 100644 index 000000000..5e5065e42 --- /dev/null +++ b/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb @@ -0,0 +1,223 @@ +{ + "cells": [ + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "[![preview notebook](https://img.shields.io/static/v1?label=render%20on&logo=github&color=87ce3e&message=GitHub)](https://github.com/open-atmos/PySDM/blob/main/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb)\n", + "[![launch on mybinder.org](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/open-atmos/PySDM.git/main?urlpath=lab/tree/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb)\n", + "[![launch on Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/open-atmos/PySDM/blob/main/examples/PySDM_examples/_HOWTOs/fractionation_factors.ipynb)" + ], + "id": "be4d0663e92430ea" + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "# Isotopic fractionation factors (kinetic and equilibrium) HOWTO\n", + "- $\\alpha(T)$ is a fractionation factor for water isotopologues, factors are different wrt ice and liquid phase\n", + "- effective, equilibrium and kinetic\n", + "- plot description" + ], + "id": "b7a9153ddefcdf76" + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-17T15:35:49.920503Z", + "start_time": "2025-11-17T15:35:49.917010Z" + } + }, + "cell_type": "code", + "source": [ + "import sys\n", + "if 'google.colab' in sys.modules:\n", + " !pip --quiet install open-atmos-jupyter-utils\n", + " from open_atmos_jupyter_utils import pip_install_on_colab\n", + " pip_install_on_colab('PySDM-examples')" + ], + "id": "dbb2b5f1c8d451d6", + "outputs": [], + "execution_count": 3 + }, + { + "cell_type": "code", + "id": "initial_id", + "metadata": { + "collapsed": true, + "ExecuteTime": { + "end_time": "2025-11-17T15:39:18.823256Z", + "start_time": "2025-11-17T15:39:18.756973Z" + } + }, + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot\n", + "from functools import partial\n", + "from open_atmos_jupyter_utils import show_plot\n", + "\n", + "from PySDM import Formulae\n", + "from PySDM.physics import si" + ], + "outputs": [], + "execution_count": 8 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "formulae, considered saturation range, temperature profile (here linear)", + "id": "7011f12adc2d5dbd" + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-17T15:35:53.370217Z", + "start_time": "2025-11-17T15:35:52.792830Z" + } + }, + "cell_type": "code", + "source": [ + "formulae = Formulae(\n", + " isotope_equilibrium_fractionation_factors=\"MerlivatAndNief1967+Majoube1970+Majoube1971\",\n", + " isotope_kinetic_fractionation_factors=\"JouzelAndMerlivat1984\",\n", + " isotope_diffusivity_ratios=\"Stewart1975\"\n", + ")\n", + "\n", + "saturation = np.linspace(.7, 1.1, 7)\n", + "\n", + "temperature_C = np.linspace(-30, 0)\n", + "temperature = formulae.trivia.C2K(temperature_C) * si.K" + ], + "id": "5f8f76c80c1d2286", + "outputs": [], + "execution_count": 5 + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "fractionation factors for $^2$H in given temperature range (wrt ice and liquid, kinetic and equilibrium)", + "id": "e6d93020d01aefbd" + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-17T15:35:55.364926Z", + "start_time": "2025-11-17T15:35:53.375406Z" + } + }, + "cell_type": "code", + "source": [ + "alpha_l = formulae.isotope_equilibrium_fractionation_factors.alpha_l_2H(temperature)\n", + "alpha_l_kinetic = partial(\n", + " formulae.isotope_kinetic_fractionation_factors.alpha_kinetic,\n", + " alpha_equilibrium=alpha_l,\n", + " D_ratio_heavy_to_light=formulae.isotope_diffusivity_ratios.ratio_2H_heavy_to_light(temperature)\n", + ")\n", + "\n", + "alpha_i = formulae.isotope_equilibrium_fractionation_factors.alpha_i_2H(temperature)\n", + "alpha_i_kinetic = partial(\n", + " formulae.isotope_kinetic_fractionation_factors.alpha_kinetic,\n", + " alpha_equilibrium=alpha_i,\n", + " D_ratio_heavy_to_light=formulae.isotope_diffusivity_ratios.ratio_2H_heavy_to_light(temperature)\n", + ")" + ], + "id": "810fcbb7b502850d", + "outputs": [], + "execution_count": 6 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-17T15:35:56.081460Z", + "start_time": "2025-11-17T15:35:55.392476Z" + } + }, + "cell_type": "code", + "source": [ + "for S in saturation:\n", + " alpha_eff = alpha_l * alpha_l_kinetic(saturation=S)\n", + " pyplot.plot(alpha_eff, temperature_C, 'k', alpha=0.1)\n", + " pyplot.annotate(f'{S:.3g}', xy=(alpha[4], temperature_C[4]), rotation=55, color='k', alpha=0.5, size=10)\n", + "\n", + "pyplot.plot(alpha_i_kinetic(saturation=1)*alpha_i, temperature_C, label=r'$\\alpha_\\text{eff}$ wrt ice')\n", + "pyplot.plot(alpha_l_kinetic(saturation=1)*alpha_l, temperature_C, label=r'$\\alpha_\\text{eff}$ wrt liquid')\n", + "pyplot.gca().set(\n", + " xlabel='Fractionation factor',\n", + " ylabel=\"Temperature [K]\",\n", + ")\n", + "pyplot.gca().invert_yaxis()\n", + "pyplot.title(\"Effective fractionation factors wrt ice and liquid\")\n", + "pyplot.legend()\n", + "show_plot()\n" + ], + "id": "2f1aeb9076b01e6f", + "outputs": [ + { + "data": { + "text/plain": [ + "
" + ], + "image/svg+xml": "\n\n\n \n \n \n \n 2025-11-17T16:35:56.047092\n image/svg+xml\n \n \n Matplotlib v3.10.0, https://matplotlib.org/\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n" + }, + "metadata": {}, + "output_type": "display_data", + "jetTransient": { + "display_id": null + } + }, + { + "data": { + "text/plain": [ + "HBox(children=(HTML(value=\"./tmp45rn_gjh.pdf
\"), HTML(value…" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "2bf128d9b42b47e3880eba1c79df6520" + } + }, + "metadata": {}, + "output_type": "display_data", + "jetTransient": { + "display_id": null + } + } + ], + "execution_count": 7 + }, + { + "metadata": { + "ExecuteTime": { + "end_time": "2025-11-17T15:35:56.120809Z", + "start_time": "2025-11-17T15:35:56.116965Z" + } + }, + "cell_type": "code", + "source": "", + "id": "79642bd18579086a", + "outputs": [], + "execution_count": null + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}