Skip to content

Commit

Permalink
Merge pull request #37 from billy-solcast/TECH-182-python-sdk-users-w…
Browse files Browse the repository at this point in the history
…ant-an-example-with-historic-monthly-data

Tech 182 python sdk users want an example with historic monthly data
  • Loading branch information
alex-solcast authored Jul 4, 2024
2 parents bcd5042 + 04bbd63 commit 6cb4eea
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/historic.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,34 @@ res.to_pandas().head()
| 2022-06-01 07:00:00+00:00 | 13 | 62 | 12 |
| 2022-06-01 07:30:00+00:00 | 13 | 0 | 0 |
| 2022-06-01 08:00:00+00:00 | 12 | 0 | 0 |
| 2022-06-01 08:30:00+00:00 | 12 | 0 | 0 |
| 2022-06-01 08:30:00+00:00 | 12 | 0 | 0 |


## Example of multi period request for the year of 2023 from Jan 01
### The below code is using an unmetered location. If using a metered location, it will consume 12 request.

```python
from solcast import historic
import pandas as pd
from solcast.unmetered_locations import UNMETERED_LOCATIONS
from solcast import historic

site = UNMETERED_LOCATIONS["Stonehenge"]
latitude, longitude = site["latitude"], site["longitude"]

data = []
start_date = '2023-01-01'
start_dates = pd.date_range(start=start_date, periods=12, freq='MS')

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

res = historic.radiation_and_weather(latitude=latitude, longitude=longitude, start=start_str, end=end_date)
if res.success:
data.append(res.to_pandas())
else:
print(res.exception)

output = pd.concat(data)
```

0 comments on commit 6cb4eea

Please sign in to comment.