Skip to content

Instantly share code, notes, and snippets.

@RoseSecurity
Created January 5, 2024 14:12
Show Gist options
  • Save RoseSecurity/4ba2cbfdd439c1bc53dc7e5e7198eb50 to your computer and use it in GitHub Desktop.
Save RoseSecurity/4ba2cbfdd439c1bc53dc7e5e7198eb50 to your computer and use it in GitHub Desktop.
A utility for visualizing ERCOT wind production across north, south, west, and system-wide resources.
#!/usr/bin/env python3
import urllib.request
from datetime import datetime, timedelta
import json
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
# Reference: https://apiexplorer.ercot.com/api-details#api=pubapi-apim-api&operation=getData_14
def get_wind_production_data():
"""Wind Power Production - Actual 5-Minute Averaged Values - Accesses Ercot Wind Production API. Data is represented in 5 minute intervals about the following sites: System Wide, South Houston, West, North
"""
try:
# ISO 8601 format
interval_ending_to = datetime.now().replace(microsecond=0).isoformat()
interval_ending_from = (datetime.now().replace(
microsecond=0) - timedelta(days=1)).isoformat()
url = f"https://api.ercot.com/api/public-reports/np4-733-cd/wpp_actual_5min_avg_values?intervalEndingFrom={interval_ending_from}&intervalEndingTo={interval_ending_to}"
headers = {
'Cache-Control': 'no-cache',
}
request = urllib.request.Request(url, headers=headers)
request.get_method = lambda: 'GET'
with urllib.request.urlopen(request) as response:
wind_raw_response = response.read().decode('utf-8')
wind_data_json_response = json.loads(wind_raw_response)
wind_data = wind_data_json_response.get('data')
# Extract data for plotting
dates = [datetime.strptime(data_point[0], '%Y-%m-%dT%H:%M:%S')
for data_point in wind_data]
system_wide_values = [data_point[1] for data_point in wind_data]
south_houston_values = [data_point[2] for data_point in wind_data]
west_values = [data_point[3] for data_point in wind_data]
north_values = [data_point[4] for data_point in wind_data]
# Plotting
plt.plot(dates, system_wide_values,
label='System Wide', marker='o', linestyle='-')
plt.plot(dates, south_houston_values,
label='South Houston', marker='o', linestyle='-')
plt.plot(dates, west_values, label='West', marker='o', linestyle='-')
plt.plot(dates, north_values, label='North', marker='o', linestyle='-')
plt.title('ERCOT Wind Power Production')
plt.xlabel('Timestamp')
plt.ylabel('Wind Speed')
plt.xticks(rotation=45)
# Format dates on the x-axis
date_format = DateFormatter("%Y-%m-%d %H:%M:%S")
plt.gca().xaxis.set_major_formatter(date_format)
plt.legend()
plt.tight_layout()
plt.show()
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
get_wind_production_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment