def fetch( start=datetime(2020, 1, 1), end=datetime.now(), lat=33.5020, # Closest to UAB lon=-86.8064): start += timedelta(hours=6) # UTC offset end += timedelta(hours=6) end.replace(microsecond=0, second=0) stations = Stations(lat=lat, lon=lon) station = stations.fetch(1) data = Hourly(station, start, end) data = data.normalize() data = data.interpolate() df = data.fetch() out = {} last_row = None for row in df.itertuples(): if last_row: out.update(interpolate_minutes(last_row, row)) last_row = row current_time = last_row.time - timedelta(hours=6) while current_time <= end - timedelta(hours=6): out[create_datetime_ID(current_time)] = { "time": current_time, "temp": last_row.temp } current_time += timedelta(minutes=1) return out
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"])
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()
from meteostat import Stations, Daily from datetime import datetime import matplotlib.pyplot as plt # Hourly stations = Stations(lat=49.2497, lon=-123.1193) station = stations.fetch(1) data = Daily(station, start=datetime(2018, 1, 1), end=datetime(2018, 12, 31)) data = data.fetch() data.plot(x='time', y=['tavg', 'tmin', 'tmax'], kind='line') plt.show()
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 # Get weather stations by WMO ID stations = Stations() stations = stations.id('meteostat', ('D1424', '10729', '10803', '10513')) stations = stations.fetch() # Get names of weather stations names = stations['name'].to_list() # Time period start = datetime(2000, 1, 1) end = datetime(2019, 12, 31) # Get daily data data = Daily(stations, start, end) data = data.aggregate(freq='1Y').fetch() # Plot chart fig, ax = plt.subplots(figsize=(8, 6)) data.unstack('station')['tmax'].plot(legend=True,
def get_nearest_station(latitude: float, longitude: float) -> str: # Get closest weather station to the match location stations = Stations().nearby(latitude, longitude) station = stations.fetch(1) LOGGER.info("Using nearest station: %s" % station) return station.index.array[0]