{ "cells": [ { "cell_type": "markdown", "id": "449c8dcb", "metadata": {}, "source": [ "# How to account for snow in a model?" ] }, { "cell_type": "markdown", "id": "44441ef9", "metadata": {}, "source": [ "This example is taken from the Gardenia tutorial {cite:p}`2013:thiery_didacticiel`.\n", "\n", "This example aims at simulating river flow of the Durance River at Embrun. The\n", "Durance River basin, with a drainage area equal to 2170 km², is located in the\n", "Hautes-Alpes French department. This basin has a strong snow component. The\n", "strongest monthly mean river flow occurs in June due to the snow melting.\n", "\n", "The following data are available:\n", "\n", "- Daily rainfall from 1971 to 2009 in mm/day\n", "- Daily potential evapotranspiration from 1971 to 2009 in mm/day\n", "- Daily river flow of the Durance at Embrun from 1974 to 2009 in m3/s.\n", "- Daily air temperature from 1971 to 2009 in °C.\n", "\n", "A simulation starts from 1974-01-01 until 2009-12-31, date of the rainfall data\n", "last record. A warmup period from 1971-01-01 to 1973-12-31 \n", "initialize the model.\n", "\n", "For more information about physical parameters related to snow, see {ref}`snow-reservoir`." ] }, { "cell_type": "markdown", "id": "3634cbdd", "metadata": {}, "source": [ "## TOML configuration file\n", "\n", "```{literalinclude} model.toml\n", ":language: toml\n", "```" ] }, { "cell_type": "markdown", "id": "24f4679f", "metadata": {}, "source": [ "## Optimization" ] }, { "cell_type": "code", "execution_count": null, "id": "f19fd0c2", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "import rameau as rm\n", "\n", "# Load model from a toml file\n", "model = rm.Model.from_toml(f\"model.toml\")\n", "\n", "# Run an optimization with parameters defined in the toml file\n", "sim = model.run_optimization()" ] }, { "cell_type": "code", "execution_count": null, "id": "078d20ab", "metadata": {}, "outputs": [], "source": [ "# Get the riverflow simulation\n", "riv_sim = sim.get_output(\"riverflow\")\n", "\n", "# Get the riverflow observation\n", "riv_obs = model.get_input(\"riverobs\")\n", "\n", "# Plot river flow\n", "df = pd.DataFrame(\n", " {\n", " \"Obs\":riv_obs.iloc[:, -1],\n", " \"Sim\":riv_sim.iloc[:, -1],\n", " }\n", ")\n", "df.loc[\"1973-01-01\":\"1991-01-01\", :].plot(\n", " grid=True,\n", " title=\"Simulated and observed riverflow (Durance at Embrun)\",\n", " ylabel=\"m2/s\",\n", " style=[\"-\", \"+\"]\n", ")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "b3ec5837", "metadata": {}, "outputs": [], "source": [ "# Print the riverflow metrics\n", "scores = sim.get_metrics(\"riverflow\")\n", "print(scores)" ] }, { "cell_type": "code", "execution_count": null, "id": "d0c4f739", "metadata": {}, "outputs": [], "source": [ "# Get the simulated snow water equivalent.\n", "riv_sim = sim.get_budget([\"height_snowpack\"])\n", "\n", "riv_sim.loc[\"1974-01-01\":\"1991-01-01\", :].plot(\n", " grid=True,\n", " title=\"Simulated snow water equivalent\",\n", " ylabel=\"mm/jour\",\n", ")\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "dev", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }