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
""" Example: Interpolation 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 Hourly # Time period start = datetime(2018, 8, 1) end = datetime(2018, 8, 4, 23, 59) # Get hourly data data = Hourly('10730', start, end) data = data.normalize() data = data.interpolate(6) data = data.fetch() # Plot chart data.plot(y='temp') plt.show()
from meteostat import Stations, Hourly from datetime import datetime import matplotlib.pyplot as plt # Hourly station = ['10637'] data = Hourly(station, start=datetime(2020, 8, 1), end=datetime(2020, 8, 4, 23, 59)) data = data.normalize() data = data.interpolate().fetch() data.plot(x='time', y=['temp'], kind='line') plt.show()