{ "cells": [ { "cell_type": "markdown", "id": "7089c522dababc77", "metadata": {}, "source": [ "# Logging 📄\n", "\n", "This notebook introduces the concept of logging using Python's built-in logging module. Logging is essential for tracking events that happen when some software runs. The module provides a way to configure different log handlers and severity levels.\n", "\n", "This notebook can be downloaded from the source code [here](https://github.com/andersretznerSGU/gwrefpy/blob/main/docs/user_guide/6_logging.ipynb).\n", "\n", "The logging levels available in `gwrefpy` are:\n", "- `DEBUG`: Detailed information, typically of interest only when diagnosing problems.\n", "- `INFO`: Confirmation that things are working as expected. This is the default logging level.\n", "- `WARNING`: An indication that something unexpected happened, or indicative of some problem in the near future\n", "- `ERROR`: Due to a more serious problem, the software has not been able to perform some function. Typically, these are issues will also raise exceptions." ] }, { "cell_type": "markdown", "id": "e90d19164555a7c1", "metadata": {}, "source": [ "Let's start by importing the necessary libraries and setting the logging level to `DEBUG` using the `set_logging_level` function." ] }, { "cell_type": "code", "execution_count": 1, "id": "8055b90446a20e26", "metadata": { "ExecuteTime": { "end_time": "2025-10-03T11:05:09.000549Z", "start_time": "2025-10-03T11:05:07.628620Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Log level set to DEBUG\n" ] } ], "source": [ "import gwrefpy as gr\n", "import numpy as np\n", "import pandas as pd\n", "\n", "gr.set_log_level(\"DEBUG\") # Set logging level to DEBUG" ] }, { "cell_type": "markdown", "id": "820ba12d41db682c", "metadata": {}, "source": [ "We can now create some well objects and a model to see the logging in action." ] }, { "cell_type": "code", "execution_count": 2, "id": "1aa3bef7234032fc", "metadata": { "ExecuteTime": { "end_time": "2025-10-03T11:05:09.082579Z", "start_time": "2025-10-03T11:05:09.077763Z" }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "# Create some example data\n", "n_days = 100\n", "dates = pd.date_range(\"2020-01-01\", periods=n_days, freq=\"D\")\n", "\n", "# Observed and reference values with some noise\n", "values_obs1 = (\n", " 25.75\n", " + 0.7 * np.sin(np.linspace(0, 4 * np.pi, n_days))\n", " + np.random.normal(0, 0.1, n_days)\n", ")\n", "values_obs1 = pd.Series(values_obs1, index=dates)\n", "values_ref1 = (\n", " 18.75\n", " + 0.3 * np.sin(np.linspace(0, 4 * np.pi, n_days))\n", " + np.random.normal(0, 0.05, n_days)\n", ")\n", "values_ref1 = pd.Series(values_ref1, index=dates)" ] }, { "cell_type": "code", "execution_count": 3, "id": "d4cf851212fa7c3b", "metadata": { "ExecuteTime": { "end_time": "2025-10-03T11:05:10.334614Z", "start_time": "2025-10-03T11:05:10.328097Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added timeseries to well Obs. well\n", "Added timeseries to well Ref. well\n", "Well 'Obs. well' added to model 'Logging Example Model'.\n", "Well 'Ref. well' added to model 'Logging Example Model'.\n" ] } ], "source": [ "# Creat the observed and reference wells\n", "obs1 = gr.Well(name=\"Obs. well\", is_reference=False)\n", "obs1.add_timeseries(values_obs1) # <-- Here we will see logging messages\n", "ref1 = gr.Well(name=\"Ref. well\", is_reference=True)\n", "ref1.add_timeseries(values_ref1) # <-- Here we will see logging messages\n", "\n", "# Create the model and add the wells\n", "model1 = gr.Model(name=\"Logging Example Model\")\n", "model1.add_well(obs1) # <-- Here we will see logging messages\n", "model1.add_well(ref1) # <-- Here we will see logging messages" ] }, { "cell_type": "markdown", "id": "96d264e429d5e067", "metadata": {}, "source": [ "As you can see, we got logging messages in the console when adding the wells to the model. Now let's fit the model to see more logging messages." ] }, { "cell_type": "code", "execution_count": 4, "id": "c97e4e0ebc9559fc", "metadata": { "ExecuteTime": { "end_time": "2025-10-03T11:05:11.579185Z", "start_time": "2025-10-03T11:05:10.344199Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using linear regression method for fitting.\n", "Fit completed for model 'Logging Example Model' with RMSE 0.149733294816474.\n", "Fitting model 'Logging Example Model' using reference well 'Ref. well' and observation well 'Obs. well'.\n", "Fit Results: Obs. well ~ Ref. well\n", "==================================\n", "Statistic Value Description\n", "--------------------------------------------------\n", "RMSE 0.1497 Root Mean Square Error\n", "R² 0.8992 Coefficient of Determination\n", "R-value 0.9483 Correlation Coefficient\n", "Slope 2.2368 Linear Regression Slope\n", "Intercept -16.1609 Linear Regression Intercept\n", "P-value 0.0000 Statistical Significance\n", "N 80 Number of Data Points\n", "Std Error 0.1516 Standard Error\n", "Confidence 95.0 % Confidence Level\n", "\n", "Calibration Period: 2020-01-01 00:00:00 to 2020-03-20 00:00:00\n", "Time Offset: 0D\n", "Aggregation Method: mean\n" ] }, { "data": { "text/html": [ "\n", "
| Statistic | \n", "Value | \n", "Description | \n", "
|---|---|---|
| RMSE | \n", "0.1497 | \n", "Root Mean Square Error | \n", "
| R² | \n", "0.8992 | \n", "Coefficient of Determination | \n", "
| R-value | \n", "0.9483 | \n", "Correlation Coefficient | \n", "
| Slope | \n", "2.2368 | \n", "Linear Regression Slope | \n", "
| Intercept | \n", "-16.1609 | \n", "Linear Regression Intercept | \n", "
| P-value | \n", "0.0000 | \n", "Statistical Significance | \n", "
| N | \n", "80 | \n", "Number of Data Points | \n", "
| Std Error | \n", "0.1516 | \n", "Standard Error | \n", "
| Confidence | \n", "95.0% | \n", "Confidence Level | \n", "
\n",
" Calibration Period: 2020-01-01 00:00:00 to 2020-03-20 00:00:00
\n",
" Time Offset: 0D
\n",
" Aggregation Method: mean\n",
"
| Statistic | \n", "Value | \n", "Description | \n", "
|---|---|---|
| RMSE | \n", "0.1544 | \n", "Root Mean Square Error | \n", "
| R² | \n", "0.8919 | \n", "Coefficient of Determination | \n", "
| R-value | \n", "0.9444 | \n", "Correlation Coefficient | \n", "
| Slope | \n", "2.1586 | \n", "Linear Regression Slope | \n", "
| Intercept | \n", "-14.7255 | \n", "Linear Regression Intercept | \n", "
| P-value | \n", "0.0000 | \n", "Statistical Significance | \n", "
| N | \n", "80 | \n", "Number of Data Points | \n", "
| Std Error | \n", "0.1563 | \n", "Standard Error | \n", "
| Confidence | \n", "95.0% | \n", "Confidence Level | \n", "
\n",
" Calibration Period: 2020-01-01 00:00:00 to 2020-03-20 00:00:00
\n",
" Time Offset: 0D
\n",
" Aggregation Method: mean\n",
"