Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 1, 2024
1 parent 9d3a760 commit 2e148fa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions quartz_solar_forecast/weather/open_meteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,18 @@ def get_hourly_weather(
except requests.exceptions.Timeout:
raise TimeoutError(f"Request to OpenMeteo API timed out. URl - {url}")

data = response[0].Hourly()

df = pd.DataFrame(data)
hourly = response[0].Hourly()
hourly_data = {"time": pd.date_range(
start=pd.to_datetime(hourly.Time(), unit="s", utc=False),
end=pd.to_datetime(hourly.TimeEnd(), unit="s", utc=False),
freq=pd.Timedelta(seconds=hourly.Interval()),
inclusive="left"
)}

for i, variable in enumerate(variables):
hourly_data[variable] = hourly.Variables(i).ValuesAsNumpy()

df = pd.DataFrame(hourly_data)
df["time"] = pd.to_datetime(df["time"])

# rename time column to date
Expand Down

0 comments on commit 2e148fa

Please sign in to comment.