forked from earthobservations/wetterdienst
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql.py
54 lines (38 loc) · 1.01 KB
/
sql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
=====
About
=====
Acquire measurement information from DWD and filter using SQL.
=====
Setup
=====
::
pip install wetterdienst[sql]
"""
import logging
from wetterdienst import DWDStationRequest, DataPackage
from wetterdienst import Parameter, PeriodType, TimeResolution
log = logging.getLogger()
def sql_example():
request = DWDStationRequest(
station_ids=[1048],
parameter=[Parameter.TEMPERATURE_AIR],
time_resolution=TimeResolution.HOURLY,
start_date="2019-01-01",
end_date="2020-01-01",
tidy_data=True,
humanize_column_names=True,
prefer_local=True,
write_file=True,
)
sql = "SELECT * FROM data WHERE element='temperature_air_200' AND value < -7.0;"
log.info(f"Invoking SQL query '{sql}'")
data = DataPackage(request=request)
data.lowercase_fieldnames()
df = data.filter_by_sql(sql)
print(df)
def main():
logging.basicConfig(level=logging.INFO)
sql_example()
if __name__ == "__main__":
main()