Hi,
A few people have asked about accessing EPW file via API and I thought I’d also share here. We’ve recently added a new API endpoint (https://api.oikolab.com/epw) to get AMY or TMY EPW file via API by specifying lat/lon or location name and the year of interest. Here’s a sample Python code:
import requests
api_key = 'your_api_key_here'
r = requests.get('https://api.oikolab.com/epw',
params={'lat': 42.1, 'lon': -71.2, 'year': 2012},
headers={'api-key': api_key},)
with open('amy_filename.epw','wb') as f:
f.write(r.content)
If the ‘year’ value is omitted from the request it will generate a TMY file based on last 15 years of data. Note that you can also provide ‘location’ value instead of lat/lon, in which case we’ll do a lat/lon lookup for the place name (we do a reverse-geocode lookup when lat/lon values are provided).
A couple of tweaks were added to make this a bit more usable:
- Both AMY and TMY will use 250 units, which will allow up to 6 free AMY EPW files per month under the free tier. The TMY files were previously generated using the same weather data API using 15 years worth of data so a few users were surprised to see that it used so many more units so we’ve been meaning to fix that for a while.
- Since this isn’t a fast changing data, we’ve also added a cache check so that if you repeatedly call the EPW API within say 8~12 hours and cached data is still available, we’ll return the cached data which will be a) much faster and b) will only take 1 unit per call instead of chargin 250 units for the data again.
Hopefully this will address some issues when people have a hard time finding the relevant EPW file. Note that the EPW files are generated on the fly so it take ~10 seconds for AMY file and ~25 seconds for TMY file but hopefully this won’t be too much of an inconvenience. The EPW files are generated from ERA5 dataset from ECMWF, with some reference discussions here.
Any questions/feedback, please feel free to ask. Of course, everything noted above still applies if you download it via the app, available at https://weatherdownloader.oikolab.com/.
Thanks!
Joseph