def _weather_data_extraction(lat, lon): start = datetime(2015, 1, 1) end = datetime(2021, 1, 16) stations = Stations() stations = stations.nearby(lat, lon) stations = stations.inventory('daily', (start, end)) station = stations.fetch(1) data = Daily(station, start, end) data = data.fetch() return data
""" Example: Closest weather station by coordinates Meteorological data provided by Meteostat (https://dev.meteostat.net) under the terms of the Creative Commons Attribution-NonCommercial 4.0 International Public License. The code is licensed under the MIT license. """ from meteostat import Stations # Get weather station stations = Stations() stations = stations.nearby(50, 8) stations = stations.inventory('hourly', True) station = stations.fetch(1).to_dict('records')[0] # Print name print('Closest weather station at coordinates 50, 8:', station["name"])
from datetime import datetime import matplotlib.pyplot as plt from meteostat import Stations, Daily # Configuration Daily.max_threads = 5 # Time period start = datetime(1980, 1, 1) end = datetime(2019, 12, 31) # Get random weather stations in the US stations = Stations() stations = stations.region('US') stations = stations.inventory('daily', (start, end)) stations = stations.fetch(limit=20, sample=True) # Get daily data data = Daily(stations, start, end) # Normalize & aggregate data = data.normalize().aggregate('1Y', spatial=True).fetch() # Chart title TITLE = 'Average US Annual Temperature from 1980 to 2019' # Plot chart data.plot(y=['tavg'], title=TITLE) plt.show()