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
def meteostat(lat_degr,long_degr,alt_avrg,start_time,end_time): #Retrieve nearest weather station stations = Stations() stations = stations.nearby(lat_degr, long_degr) station = stations.fetch(1) #Use Point to agregate nearby weather stations data for better accuracy weather_point = Point(lat_degr, long_degr,alt_avrg) weather_data = Hourly(weather_point, start_time - timedelta(0,7200), end_time + timedelta(0,7200)) weather_data = weather_data.fetch() #Use weather data from nearest station if Point returns an empty dataset if weather_data.empty: weather_data = Hourly(station, start_time - timedelta(0,7200), end_time + timedelta(0,7200)) weather_data = weather_data.fetch() return weather_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"])
Example: Simple chart 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 datetime import datetime import matplotlib.pyplot as plt from meteostat import Stations, Daily # Time period start = datetime(2018, 1, 1) end = datetime(2018, 12, 31) # Get a weather station stations = Stations() stations = stations.nearby(49.2497, -123.1193) stations = stations.inventory('daily', (start, end)) station = stations.fetch(1) # Get daily data data = Daily(station, start, end) data = data.fetch() # Plot chart data.plot(y=['tavg', 'tmin', 'tmax']) plt.show()
# Downloading weather data ############################################################################### start = datetime(2021, 1, 1) end = datetime(2021, 12, 31) container = [] retrived = [] retrivedIndex = [] notRetrived = [] notRetrivedIndex = [] for k, val in enumerate(uniqueLocations): stations = Stations() stations = stations.nearby(val[0], val[1]) station = stations.fetch(1) data = Daily(station, start, end) data = data.fetch() if len(data) > 0: data['week'] = data.index.isocalendar().week ndst = data.groupby('week').mean() localdf = ndst[['tavg', 'prcp', 'pres']] disc = localdf.isna().sum().sum() if disc > 40: notRetrived.append(val) notRetrivedIndex.append(k)