Skip to content

Commit d55457f

Browse files
authored
Merge pull request #43 from billy-solcast/historic-updates
Update to historic.md file
2 parents 4680d00 + 1f54fb6 commit d55457f

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

docs/historic.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The `Historic` module has 3 methods:
1010
| `rooftop_pv_power` | [list of API parameters](https://docs.solcast.com.au/#504e6e52-992f-4ac2-a4dc-d7ab312f992a){.md-button} |
1111
| `advanced_pv_power` | [list of API parameters](https://docs.solcast.com.au/#1db1132e-8d49-4f25-939f-34883e5336c4){.md-button} |
1212

13-
### Example
13+
## Example of single-period request
1414

1515
```python
1616
from solcast import historic
@@ -34,31 +34,52 @@ res.to_pandas().head()
3434
| 2022-06-01 08:30:00+00:00 | 12 | 0 | 0 |
3535

3636

37-
## Example of multi period request for the year of 2023 from Jan 01
38-
### The below code is using an unmetered location. If using a metered location, it will consume 12 request.
37+
## Example of 12 month combined multi-period requests
38+
The below code is using an unmetered location. If using a metered location, it will consume 12 requests.
39+
For more information see the [API Docs](https://solcast.github.io/solcast-api-python-sdk/notebooks/1.3%20Getting%20Data%20-%20Make%20Concurrent%20Requests/).
3940

4041
```python
41-
from solcast import historic
42+
import time
4243
import pandas as pd
43-
from solcast.unmetered_locations import UNMETERED_LOCATIONS
4444
from solcast import historic
45+
from solcast.unmetered_locations import UNMETERED_LOCATIONS
4546

46-
site = UNMETERED_LOCATIONS["Stonehenge"]
47-
latitude, longitude = site["latitude"], site["longitude"]
48-
47+
sydney = UNMETERED_LOCATIONS['Sydney Opera House']
4948
data = []
5049
start_date = '2023-01-01'
5150
start_dates = pd.date_range(start=start_date, periods=12, freq='MS')
5251

53-
for start in start_dates:
54-
start_str = start.strftime('%Y-%m-%dT00:00:00.000Z')
55-
end_date = (start + pd.offsets.MonthEnd(1)).strftime('%Y-%m-%dT23:59:59.000Z')
52+
for start_day in start_dates:
53+
end_day = (start_day + pd.offsets.MonthEnd(1)).strftime('%Y-%m-%dT23:59:59.000Z')
5654

57-
res = historic.radiation_and_weather(latitude=latitude, longitude=longitude, start=start_str, end=end_date)
58-
if res.success:
55+
try:
56+
res = historic.radiation_and_weather(
57+
latitude=sydney['latitude'],
58+
longitude=sydney['longitude'],
59+
start=start_day,
60+
end=end_day,
61+
)
5962
data.append(res.to_pandas())
60-
else:
61-
print(res.exception)
63+
except Exception as e:
64+
print(f"Request failed for start date {start_day}: {e}")
65+
66+
# Delay between requests to avoid hitting the default historic rate limit
67+
time.sleep(1)
6268

63-
output = pd.concat(data)
64-
```
69+
data = pd.concat(data)
70+
data
71+
```
72+
73+
| period_end | air_temp | dni | ghi |
74+
|:--------------------------|-----------:|------:|------:|
75+
| 2023-01-01 00:30:00+00:00 | 22 | 819 | 917 |
76+
| 2023-01-01 01:00:00+00:00 | 23 | 924 | 996 |
77+
| 2023-01-01 01:30:00+00:00 | 23 | 935 | 1028 |
78+
| 2023-01-01 02:00:00+00:00 | 23 | 761 | 977 |
79+
| 2023-01-01 02:30:00+00:00 | 23 | 702 | 953 |
80+
... ... ... ...
81+
| 2023-12-31 22:00:00+00:00 | 21 | 329 | 435 |
82+
| 2023-12-31 22:30:00+00:00 | 21 | 0 | 273 |
83+
| 2023-12-31 23:00:00+00:00 | 21 | 0 | 330 |
84+
| 2023-12-31 23:30:00+00:00 | 22 | 0 | 349 |
85+
| 2024-01-01 00:00:00+00:00 | 22 | 0 | 324 |

0 commit comments

Comments
 (0)