{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "# Working with live data\n", "\n", "In this tutorial we will explore how to work with live data when using the `gwrefpy` package.\n", "\n", "This notebook can be downloaded from the source code [here](https://github.com/andersretznerSGU/gwrefpy/blob/main/docs/turorials/livedata.ipynb).\n", "\n", "We will cover the following topics:\n", "1. Create some synthetic live data\n", "2. Create a model and add wells and fit them\n", "3. Update the wells with new data\n", "4. Track the fit quality over time" ], "id": "632415d87a345ed2" }, { "metadata": {}, "cell_type": "markdown", "source": [ "## 1. Create some synthetic live data\n", "We start by creating some synthetic data. In a real-world scenario, this data would be read from a database or a file. We will create two sets of data: an initial set and a live set. The initial set will be used to fit the model, and the live set will be used to update the model." ], "id": "2d6e69c54e96e45a" }, { "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-09-24T14:33:25.329562Z", "start_time": "2025-09-24T14:33:24.626403Z" } }, "cell_type": "code", "source": [ "import gwrefpy as gr\n", "import pandas as pd\n", "import numpy as np\n", "gr.set_log_level(\"ERROR\")\n", "\n", "ndays_init = 180 # initial data length\n", "ndays_live = 365 # live data length\n", "dates_init = pd.date_range(start=\"2020-01-01\", periods=ndays_init, freq=\"D\") # initial dates\n", "dates_live = pd.date_range(start=dates_init[-1], periods=ndays_live, freq=\"D\") # live dates\n", "\n", "# create synthetic data\n", "obs_init = pd.Series(5 + np.sin(np.linspace(0, 4 * np.pi, ndays_init)) + (np.random.normal(0, 0.1, ndays_init) * 2), index=dates_init)\n", "ref_init = pd.Series(10 + np.sin(np.linspace(0, 4 * np.pi, ndays_init)) + np.random.normal(0, 0.1, ndays_init), index=dates_init)\n", "obs_live = pd.Series(5 + np.sin(np.linspace(0, 6 * np.pi, ndays_live)) + (np.random.normal(0, 0.11, ndays_live) * 2), index=dates_live)\n", "# add a drawdown event in the middle of the live data\n", "start = int(ndays_live / 4)\n", "end = int(ndays_live / 2)\n", "half = (end - start) // 2\n", "x = np.concatenate([\n", " np.linspace(0, 1, half, endpoint=False),\n", " np.linspace(1, 0, (end - start) - half)\n", "])\n", "obs_live[start:end] -= 1.2 * x**2\n", "ref_live = pd.Series(10 + np.sin(np.linspace(0, 6 * np.pi, ndays_live)) + np.random.normal(0, 0.1, ndays_live), index=dates_live)\n" ], "id": "initial_id", "outputs": [], "execution_count": 1 }, { "metadata": {}, "cell_type": "markdown", "source": [ "## 2. Create a model and add wells\n", "We add the initial data to the wells and create a model." ], "id": "dd0b2a7cac832771" }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-24T14:33:25.342206Z", "start_time": "2025-09-24T14:33:25.336822Z" } }, "cell_type": "code", "source": [ "well_obs = gr.Well(name=\"Obs well\", is_reference=False, timeseries=obs_init)\n", "well_ref = gr.Well(name=\"Ref well\", is_reference=True, timeseries=ref_init)\n", "model = gr.Model(name=\"Live data model\")\n", "model.add_well([well_obs, well_ref])" ], "id": "a4098af2394c2dac", "outputs": [], "execution_count": 2 }, { "metadata": {}, "cell_type": "markdown", "source": "We can now fit the model to the initial data.", "id": "545f74ae599925d7" }, { "metadata": { "ExecuteTime": { "end_time": "2025-09-24T14:33:25.921567Z", "start_time": "2025-09-24T14:33:25.461946Z" } }, "cell_type": "code", "source": "model.fit(well_obs, well_ref, offset=\"0D\")", "id": "9217882b5e56ae7a", "outputs": [ { "data": { "text/plain": [ "FitResultData(ref_well='Reference well', obs_well='Observation well', rmse=0.2242, r²=0.9144, n=180)" ], "text/html": [ "\n", "
| Statistic | \n", "Value | \n", "Description | \n", "
|---|---|---|
| RMSE | \n", "0.2242 | \n", "Root Mean Square Error | \n", "
| R² | \n", "0.9144 | \n", "Coefficient of Determination | \n", "
| R-value | \n", "0.9563 | \n", "Correlation Coefficient | \n", "
| Slope | \n", "1.0300 | \n", "Linear Regression Slope | \n", "
| Intercept | \n", "-5.2788 | \n", "Linear Regression Intercept | \n", "
| P-value | \n", "0.0000 | \n", "Statistical Significance | \n", "
| N | \n", "180 | \n", "Number of Data Points | \n", "
| Std Error | \n", "0.2254 | \n", "Standard Error | \n", "
| Confidence | \n", "95.0% | \n", "Confidence Level | \n", "
\n",
" Calibration Period: 2020-01-01 00:00:00 to 2020-06-28 00:00:00
\n",
" Time Offset: 0D
\n",
" Aggregation Method: mean\n",
"