ontario-energy-mix
Tracing Natural Gas's rising share of Ontario's electricity mix since 2015
Why this project
Ontario's electricity mix has been quietly reshaped since 2015, and Natural Gas's growing role is something I'd seen debated anecdotally without ever seeing the numbers laid out end-to-end. Having spent years assessing energy systems in the field, I wanted to apply the same rigour to a grid-scale question: is Gas becoming a permanent structural fixture of the grid, or just a temporary bridge fuel while Nuclear capacity came back online?
Ontario's Nuclear Refurbishment Program (2020–2023) gave me a natural before/after window to test that question, and the demand climb starting in 2024 gave me a second, independent one. I wanted an analysis that held up under both.
How it was built
Data comes from IESO's public reports — monthly generation by fuel type and monthly demand — pulled directly via a Python ingestion script using requests and xml.etree.ElementTree. The whole pipeline runs in Docker: a containerized SQL Server 2022 instance is built from scratch by Docker Compose, with T-SQL scripts creating the schema, loading the CSVs, and running data-integrity checks before any analysis touches the data.
Once the data was validated, the heavy lifting — 12-month rolling averages, year-over-year fuel share, and peak-demand segmentation — was done in T-SQL using window functions and CTEs. Results were pulled into a Jupyter notebook for the final analysis and visualised with Plotly and Seaborn.
Key findings
- Demand entered a sharp structural climb starting in 2024, breaking years of relative stability
- Gas absorbed essentially all of this growth — total generation rose 1,138 GWh from Jan 2024 to May 2026, while Gas output alone rose 1,232 GWh
- Gas covered most of the output lost during the 2020–2023 Nuclear Refurbishment Program, when Nuclear output fell 1,387 GWh against a total system drop of just 251 GWh
- Gas's share of generation rises sharply with demand stress — from 7.8% in low-demand months to as much as 18.0% in the five most extreme peak months
This will ultimately be a line explaining the chart briefly. Something to replace the title on the chart itself and give some context.
Code highlight
Calculating each fuel type's annual share of generation (T-SQL)
WITH yearly_data AS (
SELECT
YEAR(month) AS year,
fuel,
SUM(output_gwh) AS fuel_output,
-- window-of-aggregate: inner SUM gives per-fuel annual totals,
-- outer SUM window adds them back up across all fuels in the
-- same year, giving the yearly total without a subquery
SUM(SUM(output_gwh)) OVER(PARTITION BY YEAR(month)) AS yearly_output
FROM generation
GROUP BY YEAR(month), fuel
)
SELECT
year,
fuel,
ROUND(fuel_output * 100.0 / yearly_output, 2) AS pct_of_total_generation
FROM yearly_data
ORDER BY year, fuel