data.fetch_data.fetch_weather_data(
cov_start,
cov_end,
latitude= 51.5136 ,
longitude= 7.4653 ,
timezone= 'UTC' ,
freq= 'h' ,
fallback_on_failure= True ,
cache_home= None ,
fill_missing= False ,
)
Fetch weather data for the dataset period plus forecast horizon.
Creates a weather DataFrame using the Open-Meteo API with optional caching. Caching is controlled solely by the cache_home argument: when a path is provided the service reads from / writes to a parquet cache file inside that directory; when None (the default) no caching is performed.
Parameters
cov_start
str
Start date for covariate data.
required
cov_end
str
End date for covariate data.
required
latitude
float
Latitude of the location for weather data. Default is 51.5136 (Dortmund).
51.5136
longitude
float
Longitude of the location for weather data. Default is 7.4653 (Dortmund).
7.4653
timezone
str
Timezone for the weather data.
'UTC'
freq
str
Frequency of the weather data.
'h'
fallback_on_failure
bool
Whether to use fallback data in case of failure.
True
cache_home
Optional [Union [str , Path ]]
Optional path to cache directory. When provided, fetched weather data is cached in <cache_home>/weather_cache.parquet. When None (default), no caching is performed.
None
fill_missing
bool
Whether to forward- and back-fill remaining NaN gaps (default False). Forwarded to WeatherService.get_dataframe; see its docstring.
False
Returns
pd .DataFrame
pd.DataFrame: DataFrame containing weather information.
Examples
from spotforecast2_safe.data.fetch_data import fetch_weather_data
weather_df = fetch_weather_data(
cov_start= '2023-01-01T00:00' ,
cov_end= '2023-01-11T00:00' ,
latitude= 51.5136 ,
longitude= 7.4653 ,
timezone= 'UTC' ,
freq= 'h' ,
fallback_on_failure= True ,
cache_home= '~/.spotforecast2_cache' )
weather_df.head()
datetime
2023-01-01 00:00:00+00:00
16.6
43
0.0
0.0
0.0
3
1010.4
998.2
97
0
100
6
35.2
228
63.7
2023-01-01 01:00:00+00:00
16.6
42
0.0
0.0
0.0
3
1010.3
998.1
100
0
99
87
32.6
229
64.8
2023-01-01 02:00:00+00:00
15.9
43
0.0
0.0
0.0
3
1011.0
998.8
100
0
99
100
29.1
222
60.1
2023-01-01 03:00:00+00:00
15.1
46
0.0
0.0
0.0
3
1011.3
999.0
100
0
100
99
28.4
218
54.0
2023-01-01 04:00:00+00:00
14.6
50
0.0
0.0
0.0
3
1011.7
999.4
100
5
100
94
28.4
219
55.1