From b68b26429bb00cbf5b1ac114a6b769eae6499405 Mon Sep 17 00:00:00 2001 From: Sebastian Kerger <sebastian.kerger@rwth-aachen.de> Date: Mon, 17 Mar 2025 13:58:31 +0100 Subject: [PATCH] Upload New File --- .../param_spec_unit_factor.ipynb | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Water quality calibration/param_spec_unit_factor.ipynb diff --git a/Water quality calibration/param_spec_unit_factor.ipynb b/Water quality calibration/param_spec_unit_factor.ipynb new file mode 100644 index 0000000..1fc0c6b --- /dev/null +++ b/Water quality calibration/param_spec_unit_factor.ipynb @@ -0,0 +1,109 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# For the parameters specified in param_specs, fetches current values from the project sqlite db\n", + "Compares values with default to help with finding unit conversion factors" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import sqlite3\n", + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# define the path of the parameter_config.xlsx\n", + "param_specs = pd.read_excel(R\"path\\parameter_config.xlsx\")\n", + "param_specs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# connect to sqlite of model\n", + "conn = sqlite3.connect(\n", + " R\"path\\example_model.sqlite\"\n", + ")\n", + "cur = conn.cursor()\n", + "for i in param_specs.index:\n", + " tab = param_specs.loc[i, \"Table\"]\n", + " col = param_specs.loc[i, \"Column\"]\n", + " muid = param_specs.loc[i, \"Muid\"]\n", + " try:\n", + " dbrs = cur.execute(\n", + " f'SELECT {col.lower()} FROM {tab.lower()} WHERE muid=\"{muid}\"'\n", + " ).fetchall()[0][0]\n", + " print(dbrs)\n", + " except Exception as e:\n", + " print(e)\n", + " dbrs = str(e)\n", + " assert dbrs != None\n", + " param_specs.loc[i, \"DBDefault\"] = dbrs\n", + "conn.close()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "param_specs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "param_specs[\"UnitFactor\"]=param_specs[\"DBDefault\"]/param_specs[\"_UnitDefault\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "param_specs[\"UnitFactor\"]" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (Spyder)", + "language": "python3", + "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.9.21" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} -- GitLab