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.
Files changed (77) hide show
  1. docker/Dockerfile +30 -0
  2. docker/docker-compose.yaml +58 -0
  3. docker/docker-compose_test.yaml +24 -0
  4. docker/start-docker-test.sh +6 -0
  5. docs/requirements.txt +10 -0
  6. docs/source/Changelog.md +2 -0
  7. docs/source/License.rst +7 -0
  8. docs/source/Methode.md +161 -0
  9. docs/source/_static/custom.css +8 -0
  10. docs/source/_static/favicon.ico +0 -0
  11. docs/source/_static/logo.png +0 -0
  12. docs/source/api/api.rst +15 -0
  13. docs/source/api/cli.rst +8 -0
  14. docs/source/api/weatherDB.broker.rst +10 -0
  15. docs/source/api/weatherDB.config.rst +7 -0
  16. docs/source/api/weatherDB.db.rst +23 -0
  17. docs/source/api/weatherDB.rst +22 -0
  18. docs/source/api/weatherDB.station.rst +56 -0
  19. docs/source/api/weatherDB.stations.rst +46 -0
  20. docs/source/api/weatherDB.utils.rst +22 -0
  21. docs/source/conf.py +137 -0
  22. docs/source/index.rst +33 -0
  23. docs/source/setup/Configuration.md +127 -0
  24. docs/source/setup/Hosting.md +9 -0
  25. docs/source/setup/Install.md +49 -0
  26. docs/source/setup/Quickstart.md +183 -0
  27. docs/source/setup/setup.rst +12 -0
  28. weatherdb/__init__.py +24 -0
  29. weatherdb/_version.py +1 -0
  30. weatherdb/alembic/README.md +8 -0
  31. weatherdb/alembic/alembic.ini +80 -0
  32. weatherdb/alembic/config.py +9 -0
  33. weatherdb/alembic/env.py +100 -0
  34. weatherdb/alembic/script.py.mako +26 -0
  35. weatherdb/alembic/versions/V1.0.0_initial_database_creation.py +898 -0
  36. weatherdb/alembic/versions/V1.0.2_more_charachters_for_settings+term_station_ma_raster.py +88 -0
  37. weatherdb/alembic/versions/V1.0.5_fix-ma-raster-values.py +152 -0
  38. weatherdb/alembic/versions/V1.0.6_update-views.py +22 -0
  39. weatherdb/broker.py +667 -0
  40. weatherdb/cli.py +214 -0
  41. weatherdb/config/ConfigParser.py +663 -0
  42. weatherdb/config/__init__.py +5 -0
  43. weatherdb/config/config_default.ini +162 -0
  44. weatherdb/db/__init__.py +3 -0
  45. weatherdb/db/connections.py +374 -0
  46. weatherdb/db/fixtures/RichterParameters.json +34 -0
  47. weatherdb/db/models.py +402 -0
  48. weatherdb/db/queries/get_quotient.py +155 -0
  49. weatherdb/db/views.py +165 -0
  50. weatherdb/station/GroupStation.py +710 -0
  51. weatherdb/station/StationBases.py +3108 -0
  52. weatherdb/station/StationET.py +111 -0
  53. weatherdb/station/StationP.py +807 -0
  54. weatherdb/station/StationPD.py +98 -0
  55. weatherdb/station/StationT.py +164 -0
  56. weatherdb/station/__init__.py +13 -0
  57. weatherdb/station/constants.py +21 -0
  58. weatherdb/stations/GroupStations.py +519 -0
  59. weatherdb/stations/StationsBase.py +1021 -0
  60. weatherdb/stations/StationsBaseTET.py +30 -0
  61. weatherdb/stations/StationsET.py +17 -0
  62. weatherdb/stations/StationsP.py +128 -0
  63. weatherdb/stations/StationsPD.py +24 -0
  64. weatherdb/stations/StationsT.py +21 -0
  65. weatherdb/stations/__init__.py +11 -0
  66. weatherdb/utils/TimestampPeriod.py +369 -0
  67. weatherdb/utils/__init__.py +3 -0
  68. weatherdb/utils/dwd.py +350 -0
  69. weatherdb/utils/geometry.py +69 -0
  70. weatherdb/utils/get_data.py +285 -0
  71. weatherdb/utils/logging.py +126 -0
  72. weatherdb-1.1.0.dist-info/LICENSE +674 -0
  73. weatherdb-1.1.0.dist-info/METADATA +765 -0
  74. weatherdb-1.1.0.dist-info/RECORD +77 -0
  75. weatherdb-1.1.0.dist-info/WHEEL +5 -0
  76. weatherdb-1.1.0.dist-info/entry_points.txt +2 -0
  77. weatherdb-1.1.0.dist-info/top_level.txt +3 -0
weatherdb/cli.py ADDED
@@ -0,0 +1,214 @@
1
+ import click
2
+ import sys
3
+ from pathlib import Path
4
+ from textwrap import dedent
5
+
6
+
7
+ sys.path.insert(0, Path(__file__).resolve().parent.parent.as_posix())
8
+ import weatherdb
9
+
10
+ # main cli group
11
+ # ---------------------------------------
12
+
13
+ @click.group(help="This is the Command line interface of the WeatherDB package.",
14
+ chain=True,
15
+ context_settings=dict(
16
+ show_default=True
17
+ )
18
+ )
19
+ @click.option('--do-logging/--no-logging',
20
+ is_flag=True, default=True, show_default=True,
21
+ help="Should the logging be done to the console?")
22
+ @click.option('--connection', '-c',
23
+ type=str, default=None, show_default=False,
24
+ help="The connection to use. Default is the value from the configuration file.")
25
+ @click.option('--verbose', '-v', # defined here but used in safe_cli
26
+ is_flag=True, default=False, show_default=True,
27
+ help="Should the verbose mode be activated? -> This will print complete tracebacks on errors.")
28
+ def cli(do_logging, connection, verbose):
29
+ if do_logging:
30
+ click.echo("logging to console is set on")
31
+ handlers = weatherdb.config.get_list("logging", "handler")
32
+ if "console" not in handlers:
33
+ handlers.append("console")
34
+ weatherdb.config.set("logging", "handler", handlers)
35
+
36
+ if connection is not None:
37
+ print(f"setting the connection to {connection}")
38
+ weatherdb.config.set("database", "connection", connection)
39
+
40
+
41
+ def safe_entry():
42
+ try:
43
+ cli()
44
+ except Exception as e:
45
+ if ("-v" in sys.argv) or ("--verbose" in sys.argv):
46
+ raise e
47
+ notes = "\n" + '\n'.join(e.__notes__) if hasattr(e, '__notes__') else ''
48
+ click.echo(f"\033[31;1;4mAn error occurred: {e}{notes}\033[0m", err=True)
49
+ sys.exit(1)
50
+
51
+ # cli statements to initialize the module
52
+ # ---------------------------------------
53
+
54
+ @cli.command(short_help="Create the database schema for the first time.")
55
+ @click.option('--owner', '-o',
56
+ type=str, default=None,
57
+ help=dedent("""
58
+ The user that should get the ownership of the created tables and schemas.
59
+ As default is the current user will be the owner."""))
60
+ def create_db_schema(owner):
61
+ click.echo("starting to create database schema")
62
+ broker = weatherdb.broker.Broker()
63
+ broker.create_db_schema(owner=owner)
64
+
65
+
66
+ @cli.command(short_help="Use Alembic directly to update or downgrade the database schema. Have a look at the official alembic documentation for more information.")
67
+ @click.option('--revision', '-r',
68
+ type=str, default="head", show_default=True,
69
+ help="The revision ID (WeatherDB Version e.g. 'V1.0.2') to upgrade/downgrade to.")
70
+ def upgrade_db_schema(revision):
71
+ click.echo("starting to upgrade database schema")
72
+ broker = weatherdb.broker.Broker()
73
+ broker.upgrade_db_schema(revision=revision)
74
+
75
+
76
+ @cli.command(short_help="Create User configuration file.")
77
+ @click.option('--file', '-f',
78
+ type=click.Path(), default="ask", show_default=True,
79
+ help="The file to save the user configuration to.")
80
+ @click.option('--on-exists', '-e',
81
+ type=str, default="ask", show_default=True,
82
+ help="What to do if the file already exists. Options are 'ask', 'overwrite', 'define' or 'error'.")
83
+ def create_user_config(file, on_exists):
84
+ weatherdb.config.create_user_config(user_config_file=file, on_exists=on_exists)
85
+
86
+
87
+ @cli.command(short_help="Download the needed multi-annual raster data from zenodo to the data folder.")
88
+ @click.option('--overwrite', '-o',
89
+ type=bool, default=None, show_default=True,
90
+ help="Should the multi annual rasters be downloaded even if they already exist?")
91
+ @click.option('--which', '-w',
92
+ type=str, default=["all"], show_default=True,
93
+ multiple=True,
94
+ help="Which raster to download. Options are 'dwd', 'hyras', 'regnie' or 'all'.")
95
+ @click.option("--update-user-config", "-u",
96
+ type=bool, default=False, show_default=True, is_flag=True,
97
+ help="Should the user configuration be updated with the path to the downloaded rasters?")
98
+ def download_ma_rasters(which, overwrite, update_user_config):
99
+ """Get the multi annual rasters on which bases the regionalisation is done.
100
+
101
+ The refined multi annual datasets, that are downloaded are published on Zenodo:
102
+ Schmit, M.; Weiler, M. (2023). German weather services (DWD) multi annual meteorological rasters for the climate period 1991-2020 refined to 25m grid (1.0.0) [Data set]. Zenodo. https://doi.org/10.5281/zenodo.10066045
103
+ """
104
+ click.echo("starting downloading multi annual raster data")
105
+ from weatherdb.utils.get_data import download_ma_rasters
106
+ download_ma_rasters(overwrite=overwrite)
107
+
108
+
109
+ @cli.command(short_help="Download the needed digital elevation model raster data from Copernicus to the data folder.")
110
+ @click.option('--overwrite/--no-overwrite', '-o/-no-o',
111
+ type=bool, is_flag=True, default=None, show_default=False,
112
+ help="Should the digital elevation model raster be downloaded even if it already exists?")
113
+ @click.option('--extent', '-e',
114
+ type=tuple, default=(5.3, 46.1, 15.6, 55.4), show_default=True,
115
+ help="The extent in WGS84 of the DEM data to download. The default is the boundary of germany + ~40km.")
116
+ @click.option("--update-user-config", "-u",
117
+ type=bool, default=False, show_default=True, is_flag=True,
118
+ help="Should the user configuration be updated with the path to the downloaded DEM?")
119
+ def download_dem(overwrite, extent):
120
+ """Download the newest DEM data from the Copernicus Sentinel dataset.
121
+
122
+ Only the GLO-30 DEM, wich has a 30m resolution, is downloaded as it is freely available.
123
+ If you register as a scientific researcher also the EEA-10, with 10 m resolution, is available.
124
+ You will have to download the data yourself and define it in the configuration file.
125
+
126
+ After downloading the data, the files are merged and saved as a single tif file in the data directory in a subfolder called 'dems'.
127
+ To use the DEM data in the WeatherDB, you will have to define the path to the tif file in the configuration file.
128
+
129
+ Source:
130
+ Copernicus DEM - Global and European Digital Elevation Model. Digital Surface Model (DSM) provided in 3 different resolutions (90m, 30m, 10m) with varying geographical extent (EEA: European and GLO: global) and varying format (INSPIRE, DGED, DTED). DOI:10.5270/ESA-c5d3d65.
131
+ """
132
+ click.echo("Starting downloading digital elevation model from Copernicus")
133
+ from weatherdb.utils.get_data import download_dem
134
+ download_dem(overwrite=overwrite, extent=extent)
135
+
136
+
137
+ # cli statements to update the database
138
+ # ---------------------------------------
139
+ @cli.command(short_help="Update the complete database. Get the newest data from DWD and treat it.")
140
+ def update_db():
141
+ click.echo("starting updating the database")
142
+ broker = weatherdb.broker.Broker()
143
+ broker.update_db()
144
+
145
+
146
+ @cli.command(short_help="Update the meta data in the database. Get the newest meta data from DWD.")
147
+ def update_meta():
148
+ click.echo("updating the meta data")
149
+ broker = weatherdb.broker.Broker()
150
+ broker.update_meta()
151
+
152
+
153
+ @cli.command(short_help="Update the Richter classes of the precipitation stations in the database.")
154
+ def update_richter_class():
155
+ click.echo("starting updating the regionalisation")
156
+ weatherdb.StationsP().update_richter_class()
157
+
158
+
159
+ @cli.command(short_help="Update the multi annual raster values in the database.")
160
+ def update_ma_raster():
161
+ click.echo("starting updating the multi annual raster data")
162
+ broker = weatherdb.broker.Broker()
163
+ broker.update_ma_raster()
164
+
165
+
166
+ @cli.command(short_help="Update the raw data of the complete database.")
167
+ def update_raw():
168
+ click.echo("starting updating the raw data")
169
+ broker = weatherdb.broker.Broker()
170
+ broker.update_raw()
171
+
172
+
173
+ @cli.command(short_help="Do the quality check of the complete database.")
174
+ def quality_check():
175
+ click.echo("starting quality check")
176
+ broker = weatherdb.broker.Broker()
177
+ broker.quality_check()
178
+
179
+
180
+ @cli.command(short_help="Do the filling of the complete database.")
181
+ def fillup():
182
+ click.echo("starting filling up")
183
+ broker = weatherdb.broker.Broker()
184
+ broker.fillup()
185
+
186
+
187
+ @cli.command(short_help="Do the richter correction of the complete database.")
188
+ def richter_correct():
189
+ click.echo("starting richter correction")
190
+ broker = weatherdb.broker.Broker()
191
+ broker.richter_correct()
192
+
193
+
194
+ # cli admin stuff
195
+ # ---------------------------------------
196
+
197
+ @cli.command(short_help="Set the db version to the current WeatherDB version to prevent recalculation of the whole database. (!!!Only use this if you're sure that the database did all the necessary updates!!!)")
198
+ def set_db_version():
199
+ click.echo(dedent(
200
+ """Are you sure you want to set the db version to the current WeatherDB version?
201
+ This will prevent the recalculation of the whole database if there was an update and could resolve in old values in the database."""))
202
+ if click.confirm("Are you sure you want to continue?"):
203
+ click.echo("starting setting db version")
204
+ broker = weatherdb.broker.Broker()
205
+ broker.set_db_version()
206
+ else:
207
+ click.echo("aborting setting db version")
208
+
209
+
210
+ # cli
211
+ # ---------------------------------------
212
+ if __name__=="__main__":
213
+ safe_entry()
214
+