1.2 Getting Data: TMY in your local timezone
We are going to retrieve some air temperature TMY data from the Solcast API and plot it.
In [1]:
Copied!
from solcast import tmy
from solcast import tmy
To test the API you can use unmetered locations, in the SDK:
In [2]:
Copied!
from solcast.unmetered_locations import UNMETERED_LOCATIONS
site = UNMETERED_LOCATIONS["Giza Pyramid Complex"]
site
from solcast.unmetered_locations import UNMETERED_LOCATIONS
site = UNMETERED_LOCATIONS["Giza Pyramid Complex"]
site
Out[2]:
{'latitude': 29.977296, 'longitude': 31.132496, 'resource_id': '8d10-f530-af85-5cbb'}
Let's retreive the TMY data for the Giza Pyramids in Cairo. The API lets you specify the timezone in the request by adding a time_zone
parameter:
In [3]:
Copied!
res = tmy.radiation_and_weather(
latitude=site["latitude"],
longitude=site["longitude"],
output_parameters=["ghi", "air_temp"],
time_zone=2 # in January there are 2h between the Cairo timezone and UTC
)
res = tmy.radiation_and_weather(
latitude=site["latitude"],
longitude=site["longitude"],
output_parameters=["ghi", "air_temp"],
time_zone=2 # in January there are 2h between the Cairo timezone and UTC
)
The Response
object in the SDK lets you easliy transform the data received from the API to a Pandas DataFrame. Make sure that Pandas is installed if you want to use this functionality:
In [9]:
Copied!
df = res.to_pandas()
df.head()
df = res.to_pandas()
df.head()
Out[9]:
ghi | air_temp | |
---|---|---|
period_end | ||
2059-01-01 01:00:00+02:00 | 0 | 11 |
2059-01-01 02:00:00+02:00 | 0 | 11 |
2059-01-01 03:00:00+02:00 | 0 | 10 |
2059-01-01 04:00:00+02:00 | 0 | 10 |
2059-01-01 05:00:00+02:00 | 0 | 10 |
For visualization purposes we can create a copy shifted to UTC:
In [6]:
Copied!
import matplotlib.pyplot as plt
df.plot()
import matplotlib.pyplot as plt
df.plot()
Out[6]:
<Axes: xlabel='period_end'>
In [8]:
Copied!
df[:50].plot()
df[:50].plot()
Out[8]:
<Axes: xlabel='period_end'>
In [ ]:
Copied!