-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
examples/provider/dwd/observation/dwd_obs_climate_summary_duckdb_dump.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2018-2021, earthobservations developers. | ||
# Distributed under the MIT License. See LICENSE for more info. | ||
import os | ||
from pathlib import Path | ||
|
||
import duckdb | ||
from tqdm import tqdm | ||
|
||
from wetterdienst.provider.dwd.observation import DwdObservationRequest | ||
|
||
ROOT = Path(__file__).parent.parent | ||
|
||
|
||
def create_dwd_climate_summary_duckdb_dump(path, test): | ||
request = DwdObservationRequest( | ||
"kl", | ||
"daily", | ||
"historical", | ||
).filter_by_rank(latlon=(47.5, 7.5), rank=10) | ||
connection = f"duckdb:////{path}" | ||
request.to_target(f"{connection}?table=stations") | ||
for result in tqdm(request.values.query(), total=request.df.shape[0]): | ||
result.to_target(f"{connection}?table=values") | ||
if test: | ||
break | ||
|
||
|
||
def main(filepath, test): | ||
# this takes something like 15 min and will require roughly 1 gb on disk | ||
create_dwd_climate_summary_duckdb_dump(filepath, test=test) | ||
con = duckdb.connect(str(filepath)) | ||
df_stations = con.execute("SELECT * FROM stations;").pl() | ||
print(df_stations) | ||
df_values = con.execute("SELECT * FROM values").pl() | ||
print(df_values) | ||
|
||
|
||
if __name__ == "__main__": | ||
filepath = ROOT / "dwd_obs_daily_climate_summary.duckdb" | ||
test = "PYTEST_CURRENT_TEST" in os.environ | ||
main(filepath, test=test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters