Skip to content

Commit

Permalink
Add example for duckdb dump
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed May 25, 2024
1 parent 5bf288b commit 6cb849d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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)
2 changes: 2 additions & 0 deletions tests/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_examples():
from examples.provider.dwd.mosmix import dwd_mosmix_forecasts
from examples.provider.dwd.observation import (
dwd_obs_climate_summary_describe_fields,
dwd_obs_climate_summary_duckdb_dump,
dwd_obs_climate_summary_zarr_dump,
dwd_obs_plot_german_weather_stations,
dwd_obs_plot_hohenpeissenberg_warming_stripes,
Expand All @@ -21,6 +22,7 @@ def test_examples():
assert dwd_mosmix_forecasts.main() is None
assert dwd_obs_climate_summary_describe_fields.main() is None
assert dwd_obs_climate_summary_zarr_dump.main() is None
assert dwd_obs_climate_summary_duckdb_dump.main() is None
assert dwd_obs_plot_german_weather_stations.main() is None
assert dwd_obs_plot_hohenpeissenberg_warming_stripes.main() is None
assert dwd_obs_plot_temperature_timeseries.main() is None
Expand Down

0 comments on commit 6cb849d

Please sign in to comment.