.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_asm1_SO_ramp_hypersurface.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_example_asm1_SO_ramp_hypersurface.py: ASM1: samples in the SO ramp manifold in phase space ============================================================================ .. GENERATED FROM PYTHON SOURCE LINES 6-48 .. code-block:: Python # Copyright (C) 2024 Juan Pablo Carbajal # Copyright (C) 2024 Mariane Yvonne Schneider # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Author: Juan Pablo Carbajal # Author: Mariane Yvonne Schneider from pathlib import Path import matplotlib.pyplot as plt import pandas as pd import seaborn as sns from sympy import * try: import dsafeatures except ModuleNotFoundError: import sys import os sys.path.insert(0, os.path.abspath("../..")) import dsafeatures.levelsample as ls from dsafeatures.printing import * from dsafeatures.odemodel import ODEModel init_printing() plt.style.use('figures.mplstyle') .. GENERATED FROM PYTHON SOURCE LINES 49-51 Select model ------------- .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python model = ODEModel.from_csv(name='ASM1') .. GENERATED FROM PYTHON SOURCE LINES 54-56 Sample the ramp manifold ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 56-67 .. code-block:: Python max_O2 = 8.0 # WARNING: if changed delete pickle file max_O2_inflow = 1e3 # WARNING: if changed delete pickle file filepath = Path('example_asm1_SO_ramp_hypersurface.pkl') if not filepath.exists(): points, rng = ls.sample_ramp(model=model, file=filepath, npoints=1024, max_O2_inflow=max_O2_inflow, S_O2=(1e-9, max_O2), append=False, show=False) else: points = pd.read_pickle(filepath) .. rst-class:: sphx-glr-script-out .. code-block:: none Elapsed time: 7.694 seconds (1011 points) .. GENERATED FROM PYTHON SOURCE LINES 68-70 Plot samples on the ramp manifold ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 70-78 .. code-block:: Python nhx_T = 'NHx level' nT = points[nhx_T].sum() lbls = {True: fr"$S_\text{{NHx}}$ < T ({nT})", False: fr"$S_\text{{NHx}}$ ≥ T ({points.shape[0] - nT})"} tmp_ = points.replace({nhx_T: lbls}) hue_order = [lbls[True], lbls[False]] fd, fig = ls.plot_samples_ramp(points=tmp_, hue=nhx_T, hue_order=hue_order, show=False, plot_kws={'alpha': 0.1}) .. image-sg:: /auto_examples/images/sphx_glr_example_asm1_SO_ramp_hypersurface_001.png :alt: N = 1011 :srcset: /auto_examples/images/sphx_glr_example_asm1_SO_ramp_hypersurface_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 79-87 .. code-block:: Python for ax_ in fd.axes[-1, :]: for ax in (ax_.xaxis, ax_.yaxis): lbl = ax.get_label() if lbl.get_text() == 'dotO2': s = r'$\dot{S}_\text{O2}$' lbl.set_text(s) fig.tight_layout(pad=0.2) fig.subplots_adjust(left=0.05, bottom=0.075, right=0.99, top=1.0) .. GENERATED FROM PYTHON SOURCE LINES 88-119 .. code-block:: Python for l in fd.legend.get_lines(): l.set_markersize(16) l.set_alpha(1.0) fd.legend.set_title('') # Inset with regression and other coloring n = len(points.columns) - 2 inset = fig.add_subplot(n, n, 3) inset.set_position([0.55, 0.55, 0.29, 0.39]) Xa_lvl = r'$X_\text{a}$ level' bins = [0, 150, 250, 1e6] tmp_[Xa_lvl] = pd.cut(tmp_[r'$X_\text{a}$'], bins, labels=[f"≤ {bins[1]}", f" [{bins[1]}, {bins[-2]}]", f"> {bins[-2]}"]) sns.kdeplot(tmp_, x='dotO2', y=r'$S_\text{NHx}$', hue=Xa_lvl, palette='tab10', fill=True, cut=0, levels=2, bw_adjust=1.5, ax=inset) sns.scatterplot(tmp_, x='dotO2', y=r'$S_\text{NHx}$', marker='.', color='k', alpha=0.25, ax=inset, legend=False) inset.axhline(1, c='r') # # Regression plot # args_ = dict(x='dotO2', y=r'$S_\text{NHx}$', ax=inset, marker='.') # sns.regplot(points[points[nhx_T]], **args_) # sns.regplot(points[~points[nhx_T]], **args_) inset.set_xlabel(r'$\dot{S}_\text{O2} \left[g m^{-3} d^{-1}\right]$') inset.set_ylabel(r'$S_\text{NHx} \left[g m^{-3}\right]$') inset.set_ylim(-1e-2, inset.get_ylim()[1]) .. rst-class:: sphx-glr-script-out .. code-block:: none (-0.01, 4.999997967651565) .. GENERATED FROM PYTHON SOURCE LINES 120-122 Plot the quality of the ramp conditions --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 122-127 .. code-block:: Python fig, axs = ls.plot_quality_ramp(points=tmp_, hue=nhx_T, hue_order=hue_order, stat="proportion", bins=25, common_norm=False, show=False) axs[0].set_xlabel(r'$\ddot{S}_\text{O2} \left[g m^{-3} d^{-2}\right]$') axs[1].set_xlabel(r'$\dot{S}_\text{O2} \left[g m^{-3} d^{-1}\right]$') .. image-sg:: /auto_examples/images/sphx_glr_example_asm1_SO_ramp_hypersurface_002.png :alt: example asm1 SO ramp hypersurface :srcset: /auto_examples/images/sphx_glr_example_asm1_SO_ramp_hypersurface_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 128-128 .. code-block:: Python plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 23.083 seconds) **Estimated memory usage:** 169 MB .. _sphx_glr_download_auto_examples_example_asm1_SO_ramp_hypersurface.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_asm1_SO_ramp_hypersurface.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_asm1_SO_ramp_hypersurface.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_asm1_SO_ramp_hypersurface.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_