weatherdb 1.1.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- docker/Dockerfile +30 -0
- docker/docker-compose.yaml +58 -0
- docker/docker-compose_test.yaml +24 -0
- docker/start-docker-test.sh +6 -0
- docs/requirements.txt +10 -0
- docs/source/Changelog.md +2 -0
- docs/source/License.rst +7 -0
- docs/source/Methode.md +161 -0
- docs/source/_static/custom.css +8 -0
- docs/source/_static/favicon.ico +0 -0
- docs/source/_static/logo.png +0 -0
- docs/source/api/api.rst +15 -0
- docs/source/api/cli.rst +8 -0
- docs/source/api/weatherDB.broker.rst +10 -0
- docs/source/api/weatherDB.config.rst +7 -0
- docs/source/api/weatherDB.db.rst +23 -0
- docs/source/api/weatherDB.rst +22 -0
- docs/source/api/weatherDB.station.rst +56 -0
- docs/source/api/weatherDB.stations.rst +46 -0
- docs/source/api/weatherDB.utils.rst +22 -0
- docs/source/conf.py +137 -0
- docs/source/index.rst +33 -0
- docs/source/setup/Configuration.md +127 -0
- docs/source/setup/Hosting.md +9 -0
- docs/source/setup/Install.md +49 -0
- docs/source/setup/Quickstart.md +183 -0
- docs/source/setup/setup.rst +12 -0
- weatherdb/__init__.py +24 -0
- weatherdb/_version.py +1 -0
- weatherdb/alembic/README.md +8 -0
- weatherdb/alembic/alembic.ini +80 -0
- weatherdb/alembic/config.py +9 -0
- weatherdb/alembic/env.py +100 -0
- weatherdb/alembic/script.py.mako +26 -0
- weatherdb/alembic/versions/V1.0.0_initial_database_creation.py +898 -0
- weatherdb/alembic/versions/V1.0.2_more_charachters_for_settings+term_station_ma_raster.py +88 -0
- weatherdb/alembic/versions/V1.0.5_fix-ma-raster-values.py +152 -0
- weatherdb/alembic/versions/V1.0.6_update-views.py +22 -0
- weatherdb/broker.py +667 -0
- weatherdb/cli.py +214 -0
- weatherdb/config/ConfigParser.py +663 -0
- weatherdb/config/__init__.py +5 -0
- weatherdb/config/config_default.ini +162 -0
- weatherdb/db/__init__.py +3 -0
- weatherdb/db/connections.py +374 -0
- weatherdb/db/fixtures/RichterParameters.json +34 -0
- weatherdb/db/models.py +402 -0
- weatherdb/db/queries/get_quotient.py +155 -0
- weatherdb/db/views.py +165 -0
- weatherdb/station/GroupStation.py +710 -0
- weatherdb/station/StationBases.py +3108 -0
- weatherdb/station/StationET.py +111 -0
- weatherdb/station/StationP.py +807 -0
- weatherdb/station/StationPD.py +98 -0
- weatherdb/station/StationT.py +164 -0
- weatherdb/station/__init__.py +13 -0
- weatherdb/station/constants.py +21 -0
- weatherdb/stations/GroupStations.py +519 -0
- weatherdb/stations/StationsBase.py +1021 -0
- weatherdb/stations/StationsBaseTET.py +30 -0
- weatherdb/stations/StationsET.py +17 -0
- weatherdb/stations/StationsP.py +128 -0
- weatherdb/stations/StationsPD.py +24 -0
- weatherdb/stations/StationsT.py +21 -0
- weatherdb/stations/__init__.py +11 -0
- weatherdb/utils/TimestampPeriod.py +369 -0
- weatherdb/utils/__init__.py +3 -0
- weatherdb/utils/dwd.py +350 -0
- weatherdb/utils/geometry.py +69 -0
- weatherdb/utils/get_data.py +285 -0
- weatherdb/utils/logging.py +126 -0
- weatherdb-1.1.0.dist-info/LICENSE +674 -0
- weatherdb-1.1.0.dist-info/METADATA +765 -0
- weatherdb-1.1.0.dist-info/RECORD +77 -0
- weatherdb-1.1.0.dist-info/WHEEL +5 -0
- weatherdb-1.1.0.dist-info/entry_points.txt +2 -0
- weatherdb-1.1.0.dist-info/top_level.txt +3 -0
docs/source/conf.py
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
2
|
+
|
3
|
+
import sys
|
4
|
+
from pathlib import Path
|
5
|
+
|
6
|
+
# -- Path setup --------------------------------------------------------------
|
7
|
+
|
8
|
+
src_path = Path(__file__).parent
|
9
|
+
base_path = src_path.parents[1]
|
10
|
+
sys.path.insert(0, base_path.resolve().as_posix())
|
11
|
+
|
12
|
+
import weatherdb
|
13
|
+
|
14
|
+
# -- Project information -----------------------------------------------------
|
15
|
+
|
16
|
+
project = 'WeatherDB'
|
17
|
+
copyright = weatherdb.__copyright__
|
18
|
+
author = weatherdb.__author__
|
19
|
+
author_email = weatherdb.__email__
|
20
|
+
|
21
|
+
# The full version, including alpha/beta/rc tags
|
22
|
+
release = weatherdb.__version__
|
23
|
+
|
24
|
+
|
25
|
+
# -- General configuration ---------------------------------------------------
|
26
|
+
|
27
|
+
# Add any Sphinx extension module names here, as strings. They can be
|
28
|
+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
29
|
+
# ones.
|
30
|
+
extensions = [
|
31
|
+
'sphinx.ext.napoleon',
|
32
|
+
'sphinx_rtd_theme',
|
33
|
+
'sphinx.ext.autodoc',
|
34
|
+
'nbsphinx',
|
35
|
+
'myst_parser',
|
36
|
+
'sphinx.ext.viewcode',
|
37
|
+
'autoclasstoc',
|
38
|
+
'sphinx.ext.autosummary',
|
39
|
+
'sphinx_click',
|
40
|
+
"sphinx.ext.autosectionlabel",
|
41
|
+
'sphinx_copybutton',
|
42
|
+
'sphinx_design',
|
43
|
+
'sphinx.ext.intersphinx',
|
44
|
+
"sphinx_new_tab_link",
|
45
|
+
"sphinx.ext.mathjax"
|
46
|
+
]
|
47
|
+
|
48
|
+
# Add any paths that contain templates here, relative to this directory.
|
49
|
+
templates_path = ['_templates']
|
50
|
+
|
51
|
+
# List of patterns, relative to source directory, that match files and
|
52
|
+
# directories to ignore when looking for source files.
|
53
|
+
# This pattern also affects html_static_path and html_extra_path.
|
54
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'sync.ffs_db']
|
55
|
+
|
56
|
+
source_suffix = [".rst", ".md"]
|
57
|
+
|
58
|
+
source_parsers = {
|
59
|
+
'.md': "markdown"
|
60
|
+
}
|
61
|
+
|
62
|
+
myst_enable_extensions = [
|
63
|
+
"dollarmath",
|
64
|
+
"colon_fence",
|
65
|
+
"attrs_inline"
|
66
|
+
]
|
67
|
+
|
68
|
+
# Autodoc options
|
69
|
+
autodoc_default_options = {
|
70
|
+
'member-order': 'bysource',
|
71
|
+
'undoc-members': True,
|
72
|
+
'show-inheritance': True,
|
73
|
+
'inherited-members':True,
|
74
|
+
'collapse_navigation': False,
|
75
|
+
}
|
76
|
+
autodoc_default_flags=["show-inheritance"]
|
77
|
+
autoclass_content= "both"
|
78
|
+
autodoc_inherit_docstrings= True
|
79
|
+
|
80
|
+
autoclasstoc_sections = [
|
81
|
+
'public-methods',
|
82
|
+
]
|
83
|
+
|
84
|
+
# Autosummary options
|
85
|
+
autosummary_generate = True
|
86
|
+
autosummary_generate_overwrite = True
|
87
|
+
|
88
|
+
# intersphinx
|
89
|
+
intersphinx_mapping = {
|
90
|
+
'python': ('https://docs.python.org/3', None),
|
91
|
+
'sqlalchemy': ('https://docs.sqlalchemy.org/en/20/', None),
|
92
|
+
'pandas': ('https://pandas.pydata.org/docs/', None),}
|
93
|
+
|
94
|
+
# -- Options for HTML output -------------------------------------------------
|
95
|
+
|
96
|
+
# The theme to use for HTML and HTML Help pages. See the documentation for
|
97
|
+
# a list of builtin themes.
|
98
|
+
html_theme = "sphinx_rtd_theme"
|
99
|
+
|
100
|
+
html_theme_options = {
|
101
|
+
'version_selector': True,
|
102
|
+
'prev_next_buttons_location': 'bottom',
|
103
|
+
'style_external_links': True,
|
104
|
+
# TOC options
|
105
|
+
'collapse_navigation': True,
|
106
|
+
'sticky_navigation': True,
|
107
|
+
'navigation_depth': -1,
|
108
|
+
}
|
109
|
+
|
110
|
+
html_css_files = [
|
111
|
+
'custom.css',
|
112
|
+
]
|
113
|
+
html_logo = "_static/logo.png"
|
114
|
+
html_favicon = "_static/favicon.ico"
|
115
|
+
|
116
|
+
html_context = {
|
117
|
+
# display gitlab
|
118
|
+
"display_gitlab": True,
|
119
|
+
"gitlab_host": "https://gitlab.uni-freiburg.de",
|
120
|
+
"gitlab_user": "hydrology",
|
121
|
+
"gitlab_repo": "weatherDB",
|
122
|
+
"gitlab_version": "master",
|
123
|
+
"conf_py_path": "/docs/source/", # Path in the checkout to the docs root
|
124
|
+
}
|
125
|
+
|
126
|
+
# Add any paths that contain custom static files (such as style sheets) here,
|
127
|
+
# relative to this directory. They are copied after the builtin static files,
|
128
|
+
# so a file named "default.css" will overwrite the builtin "default.css".
|
129
|
+
html_static_path = ['_static']
|
130
|
+
|
131
|
+
|
132
|
+
# -- Options for PDF Output --------------------------------------------------
|
133
|
+
latex_engine = "pdflatex"
|
134
|
+
latex_theme = "manual"
|
135
|
+
|
136
|
+
|
137
|
+
# run with command: sphinx-build -b html .\source .\html
|
docs/source/index.rst
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#####################################
|
2
|
+
Welcome to WeatherDB's documentation!
|
3
|
+
#####################################
|
4
|
+
|
5
|
+
|
6
|
+
The WeatherDB module offers an API to interact with the automatically filled WeatherDB Database.
|
7
|
+
|
8
|
+
There are 4 different main sub modules with their corresponding classes you might need to use.
|
9
|
+
|
10
|
+
- :py:data:`weatherdb.config`:
|
11
|
+
This submodule has only one main object :py:class:`config <weatherdb.config.ConfigParser>`. This object is used to configure the module, like e.g. saving the database connection.
|
12
|
+
- :py:mod:`weatherdb.station`:
|
13
|
+
Has a class for every type of station. E.g. :py:class:`StationP <weatherdb.station.StationP>` for precipitation.
|
14
|
+
One object represents one Station with one parameter.
|
15
|
+
This object can get used to get the corresponding timeserie.
|
16
|
+
There is also a :py:class:`GroupStation <weatherdb.station.GroupStation>` class that groups the three parameters precipitation, temperature and potential evapotranspiration together for one station. If one parameter is not available for a specific station this one won't get grouped.
|
17
|
+
- :py:mod:`weatherdb.stations`:
|
18
|
+
Is a grouping class for all the stations of one measurement parameter. E.g. :py:class:`StationsP <weatherdb.stations.StationsP>`.
|
19
|
+
Can get used to do actions on all the stations.
|
20
|
+
- :py:mod:`weatherdb.broker`:
|
21
|
+
This submodule has only one class :py:class:`Broker <weatherdb.broker.Broker>`. This one is used to do actions on all the stations together. Mainly only used for updating the Database.
|
22
|
+
|
23
|
+
To get started follow th installation guide and the setup guide first. After that you can use the quickstart guide to get a first impression of the module.
|
24
|
+
|
25
|
+
.. toctree::
|
26
|
+
:maxdepth: 6
|
27
|
+
:hidden:
|
28
|
+
|
29
|
+
Setup <setup/setup>
|
30
|
+
Method <Methode.md>
|
31
|
+
API reference <api/api>
|
32
|
+
Change-log <Changelog.md>
|
33
|
+
License <License>
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Configuration
|
2
|
+
|
3
|
+
The WeatherDB module has several configurations you can make. Those are stored in a INI-File.
|
4
|
+
|
5
|
+
## create user configuration
|
6
|
+
|
7
|
+
To configure your WeatherDB module, you need to create a user configuration file somewhere on your system. To do so:
|
8
|
+
|
9
|
+
::::{tab-set}
|
10
|
+
:sync-group: category
|
11
|
+
|
12
|
+
:::{tab-item} Python
|
13
|
+
:sync: python
|
14
|
+
|
15
|
+
```{code-block} python
|
16
|
+
import weatherdb as wdb
|
17
|
+
wdb.config.create_user_config()
|
18
|
+
```
|
19
|
+
:::
|
20
|
+
|
21
|
+
:::{tab-item} Bash
|
22
|
+
:sync: bash
|
23
|
+
|
24
|
+
```{code-block} bash
|
25
|
+
weatherdb create-user-config
|
26
|
+
```
|
27
|
+
:::
|
28
|
+
|
29
|
+
::::
|
30
|
+
|
31
|
+
This now created a INI-File with all possible configurations, but all values are commented out and you will see the default value.
|
32
|
+
After creating the file, you can edit the configuration file with any Texteditor and WeatherDB will use those configurations on your next import.
|
33
|
+
|
34
|
+
## Setup database
|
35
|
+
|
36
|
+
To get started you need to setup your PostGreSQL database the WeatherDB module should use.
|
37
|
+
|
38
|
+
There are two usage scenarios:
|
39
|
+
1. your working with an existing WeatherDB-database someone else did setup.
|
40
|
+
Then continue with this guide
|
41
|
+
2. you want to create your own WeatherDB database instance.
|
42
|
+
Then first follow the [hosting instructions](<Hosting.md>).
|
43
|
+
|
44
|
+
(setup-main-con)=
|
45
|
+
### setup main connection
|
46
|
+
|
47
|
+
To setup you database connection open the previously created user configuration file find the `[database:main]`{l=ini} section and uncomment the options and fill them out with your credentials:
|
48
|
+
|
49
|
+
```ini
|
50
|
+
[database:main]
|
51
|
+
; setup a database connection
|
52
|
+
; The password should not be stored in the config file, as it is a security risk.
|
53
|
+
; the module will ask for the password on first execution and store it in the keyring.
|
54
|
+
HOST = localhost
|
55
|
+
PORT = 5432
|
56
|
+
DATABASE = weatherdb
|
57
|
+
USER = weatherdb
|
58
|
+
```
|
59
|
+
|
60
|
+
To set your password you will just have to use the module for the first time and will then get prompted to enter the password. This password is then securely stored in your keyring.
|
61
|
+
|
62
|
+
:::{warning}
|
63
|
+
Don't add a setting for your password in the ini file as this would be a security risk.
|
64
|
+
:::
|
65
|
+
|
66
|
+
:::{tip}
|
67
|
+
If you use the database at the hydrology department of Freiburg, please go to the [apps.hydro.intra.uni-freiburg.de/weatherdb](https://apps.hydro.intra.uni-freiburg.de/weatherdb). There you can create yourself an account and download your login credentials from your profile page ("API Password").
|
68
|
+
:::
|
69
|
+
|
70
|
+
#### example
|
71
|
+
|
72
|
+
For example for the user *philip*, who's using the UNI Freiburg internal database *weatherdb* on host *fuhys017.public.ads.uni-freiburg.de* with port *5432* this part will look like:
|
73
|
+
|
74
|
+
```ini
|
75
|
+
[database:main]
|
76
|
+
; setup a database connection
|
77
|
+
; The password should not be stored in the config file, as it is a security risk.
|
78
|
+
; the module will ask for the password on first execution and store it in the keyring.
|
79
|
+
HOST = fuhys017.public.ads.uni-freiburg.de
|
80
|
+
PORT = 5432
|
81
|
+
DATABASE = weatherdb
|
82
|
+
USER = philip
|
83
|
+
```
|
84
|
+
|
85
|
+
### multiple connections
|
86
|
+
|
87
|
+
The WeatherDB configuration also allows you to work with multiple database connections. This works similarly as with the [main database](#setup-main-connection), but you don't use the `[connection:main]`{l=ini} section of the configuration file, but add a custom connection subsection by giving it any name of your choice `[connection:my_con_name]`{l=ini}.
|
88
|
+
|
89
|
+
Then you have to tell WeatherDB to use this connection:
|
90
|
+
|
91
|
+
```python
|
92
|
+
import weatherdb as wdb
|
93
|
+
|
94
|
+
wdb.config.set("database", "connection", "my_con_name")
|
95
|
+
```
|
96
|
+
|
97
|
+
Alternatively you can also set this custom database connection to be used as the default connection. To do so look for the `[connection:main]`{l=ini} section in the user configuration file and change the `connection=`{l=ini} value to your **my_con_name**:
|
98
|
+
|
99
|
+
|
100
|
+
```ini
|
101
|
+
[database]
|
102
|
+
; These are the main database settings
|
103
|
+
; The database is created with the cli command create-db-schema or the weatherdb.Broker().create_db_schema() method
|
104
|
+
; you can define multiple database connections by adding a new section like [database.connection_name], where you can define your connection name
|
105
|
+
; The connection setting defines which connection is used if not specified
|
106
|
+
connection = my_con_name
|
107
|
+
```
|
108
|
+
|
109
|
+
:::{admonition} Example
|
110
|
+
:class: tip
|
111
|
+
|
112
|
+
```ini
|
113
|
+
[database]
|
114
|
+
connection = my_con_name
|
115
|
+
|
116
|
+
[database:my_con_name]
|
117
|
+
HOST = fuhys017.public.ads.uni-freiburg.de
|
118
|
+
PORT = 5432
|
119
|
+
DATABASE = weatherdb
|
120
|
+
USER = ada
|
121
|
+
```
|
122
|
+
:::
|
123
|
+
|
124
|
+
|
125
|
+
:::{attention}
|
126
|
+
make sure to replace **my_con_name** with your chosen name in every statement.
|
127
|
+
:::
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Installation
|
2
|
+
|
3
|
+
## Install WeatherDB module
|
4
|
+
|
5
|
+
To install the package use PIP to install the Github repository:
|
6
|
+
|
7
|
+
```batch
|
8
|
+
pip install weatherdb
|
9
|
+
```
|
10
|
+
|
11
|
+
If you also want to install the optional dependencies use:
|
12
|
+
|
13
|
+
```batch
|
14
|
+
pip install weatherdb[optionals]
|
15
|
+
```
|
16
|
+
|
17
|
+
Or to upgrade use:
|
18
|
+
|
19
|
+
```batch
|
20
|
+
pip install weatherdb --upgrade
|
21
|
+
```
|
22
|
+
|
23
|
+
After installing the package you need to [configure the module](<project:Configuration.md>).
|
24
|
+
|
25
|
+
## How-to install python
|
26
|
+
|
27
|
+
If you never used python before, this section is for you.
|
28
|
+
|
29
|
+
To use this package you obviously need Python with several packages installed.
|
30
|
+
|
31
|
+
One way to install python is by installing [Anaconda](https://www.anaconda.com/products/distribution).
|
32
|
+
|
33
|
+
After the installation you should create yourself a virtual environment. This is basically a folder with all your packages installed and some definition files to set the appropriate environment variables...
|
34
|
+
To do so use (in Anaconda Terminal):
|
35
|
+
|
36
|
+
```batch
|
37
|
+
conda create --name your_environment_name python=3.8
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
Afterwards you need to activate your environment and then install the requirements:
|
42
|
+
|
43
|
+
```batch
|
44
|
+
conda activate your_environment_name
|
45
|
+
conda install shapely numpy geopandas pandas sqlalchemy
|
46
|
+
conda install -c conda-forge rasterio psycopg2 pip
|
47
|
+
pip install progressbar2
|
48
|
+
```
|
49
|
+
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# Quick-start
|
2
|
+
|
3
|
+
After installing and setting up the user configuration file with your database credentials you are ready to use the package.
|
4
|
+
This page should show you the basic usage of the package.
|
5
|
+
|
6
|
+
The package is divided in 2 main submodules:
|
7
|
+
- **weatherdb.station:**<br>
|
8
|
+
This module has a class for every type of station. E.g. StationP (or StationP).
|
9
|
+
One object represents one Station with one parameter.
|
10
|
+
This object can get used to get the corresponding timeserie.
|
11
|
+
There is also a StationGroup class that groups the three parameters precipitation, temperature and evapotranspiration together for one station.
|
12
|
+
- **weatherdb.stations:**<br>
|
13
|
+
This module has grouping classes for all the stations of one parameter. E.G. StationsP (or StationsP) groups all the Precipitation Stations available.
|
14
|
+
Those classes can get used to do actions on all the stations.
|
15
|
+
|
16
|
+
The basics of those modules are explained here, but every class and method has way more parameters to get exactly what you want. PLease use the API-reference for more information.
|
17
|
+
|
18
|
+
## download
|
19
|
+
### single station
|
20
|
+
|
21
|
+
If you want to download data for a single station, you have to create an object of the respective class, by gibing the station id you are interested in. This station object can then get used to download the data from the database.
|
22
|
+
|
23
|
+
If you want e.g. to download all the 10 minute, filled and Richter corrected precipitation data for the DWD station in Freiburg(station ID = 1443), then you can go like:
|
24
|
+
|
25
|
+
```
|
26
|
+
from weatherdb import StationP
|
27
|
+
stat_p = StationP(1443)
|
28
|
+
df = stat_p.get_corr()
|
29
|
+
```
|
30
|
+
|
31
|
+
If you are only interested in a small timespan, provide the period parameter with the upper and lower time limit. If e.g. you want the data for the years 2000-2010 do:
|
32
|
+
```
|
33
|
+
df = stat_p.get_corr(period=("2000-01-01", "2010-12-31"))
|
34
|
+
```
|
35
|
+
|
36
|
+
If you are not interested in the filled and Richter-corrected data, but want e.g. the raw data, add the kind parameter to your query. Like e.g.:
|
37
|
+
```
|
38
|
+
df = stat_p.get_raw()
|
39
|
+
```
|
40
|
+
Or use the more general function with the wanted kind parameter.
|
41
|
+
```
|
42
|
+
df = stat_p.get_df(kinds=["raw"])
|
43
|
+
```
|
44
|
+
There are 3-5 different kinds of timeseries available per station object depending on the class.
|
45
|
+
So there is:
|
46
|
+
- "raw" : the raw measurements as on the DWD server
|
47
|
+
- "qc" : The quality checked data
|
48
|
+
- "filled" : The filled timeseries
|
49
|
+
- "filled_by" : The station ID of the station from which the data was taken to fill the measurements
|
50
|
+
- "corr" : The Richter corrected timeserie.
|
51
|
+
|
52
|
+
If you want more than just one kind of timeseries, e.g. the filled timeseries, together with the id from which station the respective field got filled with use:
|
53
|
+
```
|
54
|
+
df = stat_p.get_df(kinds=["filled", "filled_by"])
|
55
|
+
```
|
56
|
+
|
57
|
+
If you only need daily values, you can hand in the agg_to parameter. This will also make your query faster, because not as much data has to get transmitted over the network.
|
58
|
+
```
|
59
|
+
df = stat_p.get_df(agg_to="day")
|
60
|
+
```
|
61
|
+
|
62
|
+
Similar to the precipitation, you can also work with the Temperature and potential Evapotranspiration data:
|
63
|
+
```
|
64
|
+
from weatherdb import StationT, StationET
|
65
|
+
stat_t = StationT(1443)
|
66
|
+
stat_et = StationET(1443)
|
67
|
+
period = ("2000-01-01", "2010-12-31")
|
68
|
+
df_t = stat_t.get_df(
|
69
|
+
period=period,
|
70
|
+
kinds=["raw", "filled"])
|
71
|
+
df_et = stat_t.get_df(
|
72
|
+
period=period,
|
73
|
+
kinds=["raw", "filled"])
|
74
|
+
```
|
75
|
+
|
76
|
+
So to download the 3 parameters N, T and ET from one station you could create the 3 single station objects and then have 3 different timeseries. But the better solution is to use the GroupStation class. This class groups all the available parameters for one location. Here is an example, how you could use it to get a Dataframe with the filled data:
|
77
|
+
```
|
78
|
+
from weatherdb import GroupStation
|
79
|
+
stat = GroupStation(1443)
|
80
|
+
df = stat.get_df(
|
81
|
+
period=("2000-01-01", "2010-12-31"),
|
82
|
+
kind="filled",
|
83
|
+
agg_to="day")
|
84
|
+
```
|
85
|
+
|
86
|
+
### multiple stations
|
87
|
+
If you want to download the data for multiple stations. Like e.g. the station in Freiburg (1443) and the station on the Feldberg (1346) it is recommended to use the classes in the stations module.
|
88
|
+
|
89
|
+
To use the stations-module, you first have to create an object and then hand the station ids you are interested in when downloading it:
|
90
|
+
```
|
91
|
+
from weatherdb import StationsP
|
92
|
+
stats_n = StationsP()
|
93
|
+
df = stats_n.get_df(
|
94
|
+
stids=[1443, 1346],
|
95
|
+
period=("2000-01-01", "2010-12-31"),
|
96
|
+
kind="filled")
|
97
|
+
```
|
98
|
+
|
99
|
+
## create timeseries files
|
100
|
+
You can also use the module to quickly create the csv-timeseries needed by RoGeR. Either for one station:
|
101
|
+
|
102
|
+
```
|
103
|
+
from weatherdb import GroupStation
|
104
|
+
stat = GroupStation(1443)
|
105
|
+
df = stat.create_roger_ts(
|
106
|
+
dir="path/to/the/directory/where/to/save")
|
107
|
+
```
|
108
|
+
|
109
|
+
or for multiple stations, you can use the GroupStations. This will create a subdirectory for ever station. It is also possible to save in a zip file, by simply giving the path to a zip file. (will get created):
|
110
|
+
|
111
|
+
```
|
112
|
+
from weatherdb import GroupStations
|
113
|
+
stats = GroupStations()
|
114
|
+
df = stats.create_roger_ts(
|
115
|
+
stids=[1443, 1346],
|
116
|
+
dir="path/to/the/directory/where/to/save")
|
117
|
+
```
|
118
|
+
If you don't want to use the RoGeR format for the timestamp you can use the `.create_ts()` method. This method also offers you way more possibilities to define the output, like e.g. adding the share of NAs in the aggregation step or adding the filled_by column.
|
119
|
+
|
120
|
+
```
|
121
|
+
from weatherdb import GroupStations
|
122
|
+
stats = GroupStations()
|
123
|
+
df = stats.create_ts(
|
124
|
+
stids=[1443, 1346],
|
125
|
+
dir="path/to/the/directory/where/to/save")
|
126
|
+
|
127
|
+
# or for one station
|
128
|
+
from weatherdb import GroupStation
|
129
|
+
stat = GroupStation(1443)
|
130
|
+
df = stat.create_ts(
|
131
|
+
dir="path/to/the/directory/where/to/save")
|
132
|
+
```
|
133
|
+
|
134
|
+
## get meta information
|
135
|
+
If you need more information about the stations you can get the meta data for a single station:
|
136
|
+
|
137
|
+
```
|
138
|
+
from weatherdb import StationP
|
139
|
+
stat = StationP(1443)
|
140
|
+
meta_dict = stat.get_meta()
|
141
|
+
```
|
142
|
+
|
143
|
+
or for multiple stations, you can use the Stations class and get a GeoDataFrame as output with all the stations information.
|
144
|
+
|
145
|
+
```
|
146
|
+
from weatherdb import StationsP
|
147
|
+
stats = StationsP(
|
148
|
+
stids=[1443, 1346])
|
149
|
+
df = stats.get_meta()
|
150
|
+
```
|
151
|
+
|
152
|
+
Furthermore you can also get all the information for every parameter of one station by using the GroupStation class:
|
153
|
+
```
|
154
|
+
from weatherdb import GroupStation
|
155
|
+
gstat = GroupStation(1443)
|
156
|
+
df = gstat.get_meta()
|
157
|
+
```
|
158
|
+
|
159
|
+
To get an explanation about the available meta information you can use the get_meta_explanation method:
|
160
|
+
```
|
161
|
+
from weatherdb import StationP, StationsP
|
162
|
+
stat = StationP(1443)
|
163
|
+
explain_df = stat.get_meta_explanation()
|
164
|
+
# or
|
165
|
+
stats = StationsP()
|
166
|
+
explain_df = stats.get_meta_explanation()
|
167
|
+
```
|
168
|
+
|
169
|
+
If you are only interested in some information you can use the infos parameter like:
|
170
|
+
```
|
171
|
+
from weatherdb import StationP
|
172
|
+
stat = StationP(1443)
|
173
|
+
filled_period_1443 = stat.get_meta(infos=["filled_from", "filled_until"])
|
174
|
+
```
|
175
|
+
but to get the filled period you can also use the get_period method, like:
|
176
|
+
```
|
177
|
+
from weatherdb import StationP
|
178
|
+
stat = StationP(1443)
|
179
|
+
filled_period_1443 = stat.get_period_meta(kind="filled")
|
180
|
+
```
|
181
|
+
|
182
|
+
This should give you an first idea on how to use the package. Feel free to try out and read the API reference section to get more information.
|
183
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
setup
|
2
|
+
=====
|
3
|
+
|
4
|
+
This chapter will give you an introduction on how to install and get started with this module.
|
5
|
+
|
6
|
+
.. toctree::
|
7
|
+
:maxdepth: 2
|
8
|
+
|
9
|
+
Installation <Install.md>
|
10
|
+
Configuration <Configuration.md>
|
11
|
+
Quick-start <Quickstart.md>
|
12
|
+
Hosting <Hosting.md>
|
weatherdb/__init__.py
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
__author__ = "Max Schmit"
|
2
|
+
__email__ = "max.schmit@hydrology.uni-freiburg.de"
|
3
|
+
__copyright__ = "Copyright 2024, Max Schmit"
|
4
|
+
|
5
|
+
try:
|
6
|
+
from ._version import __version__
|
7
|
+
except ImportError:
|
8
|
+
__version__ = "0.0.0" # not set when running from source
|
9
|
+
|
10
|
+
from .utils.logging import remove_old_logs, setup_logging_handlers
|
11
|
+
from . import station, stations, broker
|
12
|
+
from .station import StationP, StationPD, StationT, StationET, GroupStation
|
13
|
+
from .stations import StationsP, StationsPD, StationsT, StationsET, GroupStations
|
14
|
+
from .config import config
|
15
|
+
from .broker import Broker
|
16
|
+
|
17
|
+
|
18
|
+
remove_old_logs()
|
19
|
+
setup_logging_handlers()
|
20
|
+
|
21
|
+
__all__ = ["StationP", "StationPD", "StationT", "StationET", "GroupStation",
|
22
|
+
"StationsP", "StationsPD", "StationsT", "StationsET", "GroupStations",
|
23
|
+
"Broker",
|
24
|
+
"station", "stations", "broker", "config"]
|
weatherdb/_version.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "1.1.0"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# database migrations
|
2
|
+
|
3
|
+
To migrate the database alembic is used. Alembic is a lightweight database migration tool for SQLAlchemy. It is used to generate and apply migrations to the database. The migrations are generated for each version of the WeatherDB module.
|
4
|
+
|
5
|
+
To use alembic, you have to point to the `alembic.ini` file in the `weatherdb/alembic` directory, like:
|
6
|
+
```bash
|
7
|
+
alembic -c weatherdb_module_path/alembic/alembic.ini {command}
|
8
|
+
```
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# A generic, single database configuration.
|
2
|
+
|
3
|
+
[alembic]
|
4
|
+
# path to migration scripts
|
5
|
+
script_location = %(here)s
|
6
|
+
|
7
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
8
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
9
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
10
|
+
# for all available tokens
|
11
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
12
|
+
|
13
|
+
# sys.path path, will be prepended to sys.path if present.
|
14
|
+
# defaults to the current working directory.
|
15
|
+
prepend_sys_path = %(here)s/../../
|
16
|
+
|
17
|
+
# timezone to use when rendering the date within the migration file
|
18
|
+
# as well as the filename.
|
19
|
+
# If specified, requires the python-dateutil library that can be
|
20
|
+
# installed by adding `alembic[tz]` to the pip requirements
|
21
|
+
# string value is passed to dateutil.tz.gettz()
|
22
|
+
# leave blank for localtime
|
23
|
+
# timezone =
|
24
|
+
|
25
|
+
# max length of characters to apply to the
|
26
|
+
# "slug" field
|
27
|
+
# truncate_slug_length = 40
|
28
|
+
|
29
|
+
# set to 'true' to run the environment during
|
30
|
+
# the 'revision' command, regardless of autogenerate
|
31
|
+
# revision_environment = false
|
32
|
+
|
33
|
+
# set to 'true' to allow .pyc and .pyo files without
|
34
|
+
# a source .py file to be detected as revisions in the
|
35
|
+
# versions/ directory
|
36
|
+
# sourceless = false
|
37
|
+
|
38
|
+
# version location specification; This defaults
|
39
|
+
# to alembic/versions. When using multiple version
|
40
|
+
# directories, initial revisions must be specified with --version-path.
|
41
|
+
# The path separator used here should be the separator specified by "version_path_separator" below.
|
42
|
+
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
|
43
|
+
|
44
|
+
# version path separator; As mentioned above, this is the character used to split
|
45
|
+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
46
|
+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
47
|
+
# Valid values for version_path_separator are:
|
48
|
+
#
|
49
|
+
# version_path_separator = :
|
50
|
+
# version_path_separator = ;
|
51
|
+
# version_path_separator = space
|
52
|
+
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
53
|
+
|
54
|
+
# set to 'true' to search source files recursively
|
55
|
+
# in each "version_locations" directory
|
56
|
+
# new in Alembic version 1.10
|
57
|
+
# recursive_version_locations = false
|
58
|
+
|
59
|
+
# the output encoding used when revision files
|
60
|
+
# are written from script.py.mako
|
61
|
+
# output_encoding = utf-8
|
62
|
+
|
63
|
+
exclude_tables = spatial_ref_sys,layer,topology
|
64
|
+
|
65
|
+
[post_write_hooks]
|
66
|
+
# post_write_hooks defines scripts or Python functions that are run
|
67
|
+
# on newly generated revision scripts. See the documentation for further
|
68
|
+
# detail and examples
|
69
|
+
|
70
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
71
|
+
# hooks = black
|
72
|
+
# black.type = console_scripts
|
73
|
+
# black.entrypoint = black
|
74
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
75
|
+
|
76
|
+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
|
77
|
+
# hooks = ruff
|
78
|
+
# ruff.type = exec
|
79
|
+
# ruff.executable = %(here)s/.venv/bin/ruff
|
80
|
+
# ruff.options = --fix REVISION_SCRIPT_FILENAME
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from alembic.config import Config
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
from ..config import config
|
5
|
+
from ..db.connections import db_engine
|
6
|
+
|
7
|
+
config = Config(
|
8
|
+
Path(config.get("main", "module_path"))/"alembic"/"alembic.ini",
|
9
|
+
attributes={"engine": db_engine.get_engine()})
|