.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_simulation/plot_100_logparser_intro.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_howto_simulation_plot_100_logparser_intro.py: Logparser: Introduction ======================= This simple example demonstrates how to analyze the OGS (OpenGeoSys) log output to extract performance information regarding various computational parts of OGS. Here we utilize the project file from the benchmark titled: `OGS: Constant viscosity (Hydro-Thermal) `_ .. GENERATED FROM PYTHON SOURCE LINES 16-19 Complete example ================ For detailed explanation see all sections below. .. GENERATED FROM PYTHON SOURCE LINES 19-36 .. code-block:: Python import pandas as pd from ogstools.examples import ( log_const_viscosity_thermal_convection, ) from ogstools.logparser import ( fill_ogs_context, parse_file, time_step_vs_iterations, ) records = parse_file(log_const_viscosity_thermal_convection) df_records = pd.DataFrame(records) df_log = fill_ogs_context(df_records) df_ts_it = time_step_vs_iterations(df_log) df_ts_it .. raw:: html
iteration_number
time_step
0 1
1 2
2 1
3 1
4 1
5 3
6 1
7 1
8 1
9 2
10 2
11 2
12 4
13 1
14 4
15 1
16 4
17 4
18 5
19 5
20 7
21 7
22 8
23 9
24 17
25 23
26 20


.. GENERATED FROM PYTHON SOURCE LINES 40-58 The log file ------------- Running `ogs` in the command line outputs the logs into the console output. With `tee `_ in Linux and Mac and `Tee-Object `_ in Windows Powershell the log gets directed into a file and into the console. * **Linux/Mac**: ``ogs | tee `` * **Windows**: ``ogs | Tee-Object -FilePath `` For first step we recommend to use either **`ogs -l info`** or `ogs - l debug`. Make sure the log file does not contain `ANSI escape (e.g.color) code `_. You can remove it with: ``cat ogs.log | sed 's/\x1b\[[0-9;]*m//g' > ogs.log`` .. GENERATED FROM PYTHON SOURCE LINES 61-69 Parsing steps ------------- The functions :py:mod:`ogstools.logparser.parse_file` and :py:mod:`ogstools.logparser.fill_ogs_context` are explained in :ref:`sphx_glr_auto_examples_howto_simulation_plot_102_logparser_advanced.py`. All predefined analyses need the result of fill_ogs_context. Here `const_viscosity_thermal_convection_log` is string representing the location of the ogs log file. .. GENERATED FROM PYTHON SOURCE LINES 69-70 .. code-block:: Python print(log_const_viscosity_thermal_convection) .. rst-class:: sphx-glr-script-out .. code-block:: none /builds/ogs/tools/ogstools/ogstools/examples/logs/ConstViscosityThermalConvection.log .. GENERATED FROM PYTHON SOURCE LINES 71-75 .. code-block:: Python records = parse_file(log_const_viscosity_thermal_convection) df_records = pd.DataFrame(records) df_log = fill_ogs_context(df_records) .. GENERATED FROM PYTHON SOURCE LINES 76-88 Use predefined analyses ----------------------- :py:mod:`ogstools.logparser.time_step_vs_iterations` is one of many predefined analyses. All possibilities are shown here: :ref:`sphx_glr_auto_examples_howto_simulation_plot_101_logparser_analyses.py`. Here we are interested in every time step of the simulation and how many iterations have been needed. The predefined analyses only work with logs from `ogs` run with level `info` or finer (`debug`), like `ogs -l info` or `ogs - l debug`. (see `OGS Developer Guide - log and debug output `_ .. GENERATED FROM PYTHON SOURCE LINES 88-95 .. code-block:: Python df_ts_it = time_step_vs_iterations(df_log) # The result is a pandas.DataFrame. You may manipulate the dataframe to your # needs with pandas functionality. pd.set_option("display.max_rows", 8) # for visualization only df_ts_it .. raw:: html
iteration_number
time_step
0 1
1 2
2 1
3 1
... ...
23 9
24 17
25 23
26 20

27 rows × 1 columns



.. GENERATED FROM PYTHON SOURCE LINES 96-101 Pandas to plot -------------- You can directly use `plot` ` `_ from pandas. .. GENERATED FROM PYTHON SOURCE LINES 101-102 .. code-block:: Python df_ts_it.plot(grid=True) .. image-sg:: /auto_examples/howto_simulation/images/sphx_glr_plot_100_logparser_intro_001.png :alt: plot 100 logparser intro :srcset: /auto_examples/howto_simulation/images/sphx_glr_plot_100_logparser_intro_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.098 seconds) .. _sphx_glr_download_auto_examples_howto_simulation_plot_100_logparser_intro.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_100_logparser_intro.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_100_logparser_intro.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_100_logparser_intro.zip `