Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MIKE+Py_scripts_ENTfrachtEN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Kerger
MIKE+Py_scripts_ENTfrachtEN
Commits
b68b2642
Commit
b68b2642
authored
1 month ago
by
Sebastian Kerger
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
37c0f2c1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Water quality calibration/param_spec_unit_factor.ipynb
+109
-0
109 additions, 0 deletions
Water quality calibration/param_spec_unit_factor.ipynb
with
109 additions
and
0 deletions
Water quality calibration/param_spec_unit_factor.ipynb
0 → 100644
+
109
−
0
View file @
b68b2642
{
"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
}
%% Cell type:markdown id: tags:
# For the parameters specified in param_specs, fetches current values from the project sqlite db
Compares values with default to help with finding unit conversion factors
%% Cell type:code id: tags:
```
python3
import sqlite3
import pandas as pd
```
%% Cell type:code id: tags:
```
python3
# define the path of the parameter_config.xlsx
param_specs = pd.read_excel(R"path\parameter_config.xlsx")
param_specs
```
%% Cell type:code id: tags:
```
python3
# connect to sqlite of model
conn = sqlite3.connect(
R"path\example_model.sqlite"
)
cur = conn.cursor()
for i in param_specs.index:
tab = param_specs.loc[i, "Table"]
col = param_specs.loc[i, "Column"]
muid = param_specs.loc[i, "Muid"]
try:
dbrs = cur.execute(
f'SELECT {col.lower()} FROM {tab.lower()} WHERE muid="{muid}"'
).fetchall()[0][0]
print(dbrs)
except Exception as e:
print(e)
dbrs = str(e)
assert dbrs != None
param_specs.loc[i, "DBDefault"] = dbrs
conn.close()
```
%% Cell type:code id: tags:
```
python3
param_specs
```
%% Cell type:code id: tags:
```
python3
param_specs["UnitFactor"]=param_specs["DBDefault"]/param_specs["_UnitDefault"]
```
%% Cell type:code id: tags:
```
python3
param_specs["UnitFactor"]
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment