1.1 Getting Data: Historic Solar Radiation
In this example we are going to fetch GHI and Clearsky GHI for 5 days in the past for the Sydney Opera House.
In [1]:
Copied!
from solcast import historic
from solcast import historic
To test the API you can use unmetered locations, in the sdk:
In [2]:
Copied!
from solcast.unmetered_locations import UNMETERED_LOCATIONS
sydney = UNMETERED_LOCATIONS['Sydney Opera House']
from solcast.unmetered_locations import UNMETERED_LOCATIONS
sydney = UNMETERED_LOCATIONS['Sydney Opera House']
We are going to use the historic.radiation_and_weather API:
In [3]:
Copied!
help(historic.radiation_and_weather)
help(historic.radiation_and_weather)
Help on function radiation_and_weather in module solcast.historic:
radiation_and_weather(latitude: float, longitude: float, start: str, end: str = None, duration: str = None, **kwargs) -> solcast.api.Response
Get historical irradiance and weather estimated actuals for up to 31 days of data
at a time for a requested location, derived from satellite (clouds and irradiance
over non-polar continental areas) and numerical weather models (other data).
Data is available from 2007-01-01T00:00Z up to real time estimated actuals.
Args:
latitude: in decimal degrees, between -90 and 90, north is positive
longitude: in decimal degrees, between -180 and 180, east is positive
start: datetime-like, first day of the requested period
end: optional, dateime-like, last day of the requested period
duration: optional, ISO_8601 compliant duration for the historic data.
Must be within 31 days of the start_date.
See https://docs.solcast.com.au/ for full list of parameters.
In [5]:
Copied!
res = historic.radiation_and_weather(
latitude=sydney['latitude'],
longitude=sydney['longitude'],
output_parameters='clearsky_ghi,ghi',
start='2022-06-01T14:45:00.000Z',
duration='P5D',
period='PT5M'
)
res = historic.radiation_and_weather(
latitude=sydney['latitude'],
longitude=sydney['longitude'],
output_parameters='clearsky_ghi,ghi',
start='2022-06-01T14:45:00.000Z',
duration='P5D',
period='PT5M'
)
we can also use the same function with the end parameter instead of the duration, the results will be equivalent:
In [6]:
Copied!
res2 = historic.radiation_and_weather(
latitude=sydney['latitude'],
longitude=sydney['longitude'],
output_parameters='clearsky_ghi,ghi',
start='2022-06-01T14:45:00.000Z',
end='2022-06-06T14:45:00.000Z',
period='PT5M'
)
assert (res.to_pandas() == res2.to_pandas()).all().all()
res2 = historic.radiation_and_weather(
latitude=sydney['latitude'],
longitude=sydney['longitude'],
output_parameters='clearsky_ghi,ghi',
start='2022-06-01T14:45:00.000Z',
end='2022-06-06T14:45:00.000Z',
period='PT5M'
)
assert (res.to_pandas() == res2.to_pandas()).all().all()
Let's transform the result in a DataFrame with the res.to_pandas() and plot the time series with matplotlib.
Since we are retrieving data for Sydney, we can cast the times to the local timezone too:
In [10]:
Copied!
df = res.to_pandas()
df.index = df.index.tz_convert('Australia/Sydney')
df.plot()
df = res.to_pandas()
df.index = df.index.tz_convert('Australia/Sydney')
df.plot()
Out[10]:
<Axes: xlabel='period_end'>
In [ ]:
Copied!