1 License

Code copyright the author (2022)

License:

To cite:

Code:

3 Data

This analysis uses the UK NG ESO generation mix data.

The data contains average (mean) MW generation per half hour by source including interconnectors and storage.

As far as we can work out this data does not include distributed (i.e. non-grid connected) generation such as small scale wind, solar, hydro, biomass etc which is connected to the LV network. This means the ESO data is likely to underestimate total generation and potentially underestimate the proportion of total generation that is renewable. It is possible that this could be fixed using embedded wind & solar generation data from the demand update file.

The data also includes a half-hourly carbon intensity value in g CO2/kWh sourced from https://www.carbonintensity.org.uk/.

rmdParams$olderThan <- 7

If the data we have previously downloaded is more than 7` days old, re-download.

gbGenMixUrl <- "https://data.nationalgrideso.com/backend/dataset/88313ae5-94e4-4ddc-a790-593554d8c6b9/resource/f93d1835-75bc-43e5-84ad-12472b180a98/download/df_fuel_ckan.csv"

orig_DT <- load_gbGenMix(url = gbGenMixUrl, 
                      dataPath = repoParams$ukGridDataLoc,
                      olderThan = rmdParams$olderThan)
## No local data file...re-downloading.
orig_DT[, dv_dateTime := lubridate::as_datetime(DATETIME)] # proper date time
message("Original data range from: ", min(orig_DT$dv_dateTime))
## Original data range from: 2009-01-01
message("...to: ", max(orig_DT$dv_dateTime))
## ...to: 2023-06-13 07:00:00
# add derived variables used later ----
orig_DT[, dv_year := lubridate::year(dv_dateTime)]
orig_DT[, dv_date := lubridate::as_date(dv_dateTime)]
orig_DT[, dv_hour := lubridate::hour(dv_dateTime)]
orig_DT[, dv_hms := hms::as_hms(dv_dateTime)]
# half-hours are the start of the half hours (we think)

message("Remove incomplete years to avoid weird things in plots.")
## Remove incomplete years to avoid weird things in plots.
gbGenMix_dt <- orig_DT[dv_year < 2023]

message("Filtered data range from: ", min(gbGenMix_dt$dv_dateTime))
## Filtered data range from: 2009-01-01
message("...to: ", max(gbGenMix_dt$dv_dateTime))
## ...to: 2022-12-31 23:30:00
gbGenMix_dt <- gridCarbon::add_peakPeriod(gbGenMix_dt, 
                                      dateTime = "dv_dateTime")

# check coding
# table(gbGenMix_dt$dv_hour, gbGenMix_dt$dv_peak, useNA = "always")

rmdParams$plotCap <- paste0("Data: NG ESO Generation Mix ",
                   min(gbGenMix_dt$dv_date), " - ",
                   max(gbGenMix_dt$dv_date),
                            "\nPlot: @dataknut \nCode: https://github.com/dataknut/gridCarbon")

The data covers more years than we need - we’ll start at 2012 too.

4 Recreating DrSimEvans’ plot

This looks like daily data.

  • Solar + wind (% of gen) vs coal + gas (& of gen))
# add together the % and totals we want (half-hourly)
gbGenMix_dt[, dv_coal_gas_pc := COAL_perc + GAS_perc]
gbGenMix_dt[, dv_solar_wind_pc := SOLAR_perc + WIND_perc]
gbGenMix_dt[, dv_coal_gas := COAL + GAS]
gbGenMix_dt[, dv_solar_wind := SOLAR + WIND]

# keep the vars we want for clarity
temp <- gbGenMix_dt[, .(dv_dateTime, dv_coal_gas, dv_solar_wind,
                    dv_coal_gas_pc, dv_solar_wind_pc, GENERATION)]

temp[, dv_date := lubridate::date(dv_dateTime)]

# aggregate to daily data for plotting
plotDT <- temp[,
               .(mean_dv_solar_wind_pc = mean(dv_solar_wind_pc),
                 mean_dv_coal_gas_pc = mean(dv_coal_gas_pc),
                 total_dv_coal_gas = sum(dv_coal_gas),
                 total_dv_solar_wind = sum(dv_solar_wind),
                 total_GENERATION = sum(GENERATION),
                 nObs = .N), # to check for days with < 48 half hours
               keyby = .(dv_date)
               ]
plotDT[, dv_year := lubridate::year(dv_date)] # for plots
plotDT[, total_dv_coal_gas_pc := total_dv_coal_gas/total_GENERATION] # daily %
plotDT[, total_dv_solar_wind_pc := total_dv_solar_wind/total_GENERATION]

message("Check for days with less than 48 hours - this will be truncated data")
## Check for days with less than 48 hours - this will be truncated data
table(plotDT$nObs)
## 
##   48 
## 5113

Figure 4.1 shows the mean half-hourly % generation by each type per day. This is slightly convoluted - it is the mean of the sum of the 48 daily half-hourly XXX_perc values in the original data where XXX is the generation type. Unfold the code above for clarity.

The smoothed curves are estimated for each year. The lines terminate at the maximum value for the year. I’m still trying to decide if they tell us anything useful.

ggplot2::ggplot(plotDT[dv_year > 2011], aes(x = mean_dv_solar_wind_pc, 
                            y = mean_dv_coal_gas_pc,
                            colour = as.factor(dv_year),
                            alpha = dv_year)) +
  geom_point() +
  geom_smooth() +
  scale_colour_viridis_d(name = "Year") +
  guides(alpha = "none") +
  labs(x = "Solar & wind (mean % of half-hourly generation per day)",
       y = "Coal & gas (mean % of half-hourly generation per day)",
       caption = rmdParams$plotCap)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Mean half-hourly % generation by each type per day

Figure 4.1: Mean half-hourly % generation by each type per day

# save it
ggplot2::ggsave(filename = "meanGBrenewablesVsfossilHalfHourPC.png", 
                path = here::here("rmd","plots"),
                height = 5)
## Saving 7 x 5 in image
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Figure 4.2 shows the percentage of daily generation by type. This is less convoluted as it is the sum of generation per day for the two categories (solar + wind vs gas + coal) as a % of total daily generation.

Again the smoothed curve is estimated for each year.

ggplot2::ggplot(plotDT[dv_year > 2011], aes(x = 100 * total_dv_solar_wind_pc, 
                            y = 100 * total_dv_coal_gas_pc,
                            colour = as.factor(dv_year),
                            alpha = dv_year)) +
  geom_point() +
  geom_smooth() +
  scale_colour_viridis_d(name = "Year") +
  guides(alpha = "none") +
  labs(x = "Solar & wind (% of total daily generation)",
       y = "Coal & gas (% of total daily generation)",
       caption = rmdParams$plotCap)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Percentage of daily generation by type

Figure 4.2: Percentage of daily generation by type

ggplot2::ggsave(filename = "dailyGBpcGenMix.png", 
                path = here::here("rmd","plots"),
                height = 5)
## Saving 7 x 5 in image
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

4.1 Half-hourly versions of the plot

Just cos we can… helpfully split into ‘peak’ and ‘off peak’ periods.

Peak period definitions:

  • Morning 07:00 - 09:00
  • Daytime 09:00 - 16:00
  • Evening 16:00 - 21:00
  • Night - all other times

Again the smoothed curve is estimated for each year (and demand period).

ggplot2::ggplot(gbGenMix_dt[dv_year > 2011], aes(x = dv_solar_wind_pc, 
                            y = dv_coal_gas_pc,
                            alpha = dv_year,
                            colour = as.factor(dv_year))) +
  geom_point() +
  facet_wrap(. ~ dv_peakPeriod) +
  geom_smooth() +
  scale_colour_viridis_d(name = "Year") +
  guides(alpha = "none") +
  labs(x = "Solar & wind (% of half-hourly generation)",
       y = "Coal & gas (% of half-hourly generation)",
       caption = rmdParams$plotCap)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
Percentage of half-hourly generation by type

Figure 4.3: Percentage of half-hourly generation by type

ggplot2::ggsave(filename = "halfHourlyPCgenByPeakPeriod.png", 
                path = here::here("rmd","plots"),
                height = 5)
## Saving 7 x 5 in image
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

7 Renewables and overall generation

Do we see a relationship between renewables generating and peak demand? This will be mediated by the way the electricity market works.

We may find wind curtailment (not visible here) at low demand periods where nuclear can’t be shut off.

First, what is the general average shape of carbon intensity and renewable generation?

Figure 7.1 shows that although the mean half-hourly carbon intensity had fallen over time (with the effect of solar in summer particularly noticeable), the morning and evening peaks are still relatively more carbon intense as demand overtakes the available renewable supply.

plotDT <- gbGenMix_dt[dv_year > 2011, .(mean_ci = mean(CARBON_INTENSITY),
                          mean_renewables_MW = mean(RENEWABLE),
                          mean_renewables_pc = mean(RENEWABLE_perc)),
                          keyby = .(dv_year, dv_hms, dv_season)]

ggplot2::ggplot(plotDT, aes(x = dv_hms, y = mean_ci, 
                            alpha = dv_year,
                            colour = dv_year,
                            group = dv_year)) +
  geom_line() +
  scale_alpha_continuous(name="Year") +
  scale_color_continuous(name = "Year",
                         low = "grey", 
                         high = "#3CBAC6") + # UoS from Marine palette
  theme(axis.text.x = element_text(angle = 45, hjust=1)) +
  facet_wrap(. ~ dv_season) +
  labs(x = "Time of day",
       y = "Mean half-hourly carbon intensity",
       caption = rmdParams$plotCap)
Mean hakf-hourly carbon intensity by year and season

Figure 7.1: Mean hakf-hourly carbon intensity by year and season

ggplot2::ggplot(plotDT, aes(x = dv_hms, y = mean_renewables_MW, 
                            colour = dv_year, 
                            alpha = dv_year,
                            group = dv_year)) +
  geom_line() +
  scale_alpha_continuous(name = "Year") +
  scale_color_continuous(name = "Year",
                         low = "grey", 
                         high = "#3CBAC6") + # UoS from Marine palette
  facet_grid(dv_season ~ .) +
    labs(x = "Time of day",
       y = "Mean renewables (MW)",
       caption = rmdParams$plotCap)
Mean renewable generation by year and season

Figure 7.2: Mean renewable generation by year and season

ggplot2::ggplot(plotDT, aes(x = dv_hms, y = mean_renewables_pc, 
                            colour = dv_year, 
                            alpha = dv_year,
                            group = dv_year)) +
  geom_line() +
  scale_alpha_continuous(name = "Year") +
  scale_color_continuous(name = "Year",
                         low = "grey", 
                         high = "#3CBAC6") + # UoS from Marine palette
  facet_grid(dv_season ~ .) +
    labs(x = "Time of day",
       y = "Mean renewables (MW)",
       caption = rmdParams$plotCap)
Mean renewable generation by year and season

Figure 7.3: Mean renewable generation by year and season

ggplot2::ggplot(gbGenMix_dt, aes(x = RENEWABLE, y = GENERATION)) +
  geom_point() +
  facet_wrap(. ~ dv_year) +
  theme(axis.text.x = element_text(angle = 45, hjust=1))

7.4 shows the rise of solar…

plotDT <- gbGenMix_dt[, .(mean_renewables = mean(RENEWABLE),
                 mean_generation = mean(GENERATION)),
             keyby = .(dv_year, dv_hms, dv_peakPeriod)]

ggplot2::ggplot(plotDT[dv_year > 2016], aes(x = dv_hms, 
                                         colour = dv_peakPeriod,
                                         alpha = dv_year,
                                         group = dv_year)) +
  geom_line(aes(y = mean_renewables)) +
  scale_alpha_continuous(name = "Year") +
  scale_color_discrete(name = "Peak period") +
  labs(x = "Time of day",
       y = "Mean renewables (MW)",
       caption = rmdParams$plotCap)
Mean renewables by time of day

Figure 7.4: Mean renewables by time of day

YMMV on 7.5

plotDT <- gbGenMix_dt[, .(mean_renewables = mean(RENEWABLE),
                 mean_generation = mean(GENERATION)),
             keyby = .(dv_year, dv_hms, dv_peakPeriod, dv_season)]

ggplot2::ggplot(plotDT[dv_year > 2016], aes(x = mean_generation/1000 , y = mean_renewables/1000,
                                         colour = dv_peakPeriod)) +
  geom_point() +
  scale_color_discrete(name = "Period") +
  facet_grid(dv_season ~ dv_year) +
  labs(x = "Mean total generation (GW)",
       y = "Mean renewables (GW)",
       caption = rmdParams$plotCap)
Mean renewables vs Mean total generation

Figure 7.5: Mean renewables vs Mean total generation

8 Summary

That’s it.

You might want to look at recent academic research on this topic:

  • (Staffell 2017)
  • (Staffell and Pfenninger 2018)

9 Annex

9.1 Data descriptors

9.1.1 NGESO gen mix data

skimr::skim(gbGenMix_dt)
Table 9.1: Data summary
Name gbGenMix_dt
Number of rows 245424
Number of columns 46
Key NULL
_______________________
Column type frequency:
Date 1
difftime 2
factor 2
numeric 39
POSIXct 2
________________________
Group variables None

Variable type: Date

skim_variable n_missing complete_rate min max median n_unique
dv_date 0 1 2009-01-01 2022-12-31 2016-01-01 5113

Variable type: difftime

skim_variable n_missing complete_rate min max median n_unique
dv_hms 0 1 0 secs 84600 secs 42300 secs 48
hms 0 1 0 secs 84600 secs 42300 secs 48

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
dv_peakPeriod 0 1 FALSE 5 Ear: 71582, Day: 71582, Eve: 40904, Lat: 40904
dv_season 0 1 FALSE 4 Spr: 61824, Sum: 61824, Aut: 61152, Win: 60624

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
GAS 0 1 12677.01 5278.48 1556.0 8534.00 12830.0 16758.00 27472.0 ▅▆▇▅▁
COAL 0 1 6705.09 6648.97 0.0 587.00 4560.0 12180.00 26044.0 ▇▂▃▂▁
NUCLEAR 0 1 6739.81 1255.73 2488.0 5802.00 6910.0 7760.00 9342.0 ▁▃▆▇▃
WIND 0 1 4128.83 3955.07 1.0 1069.00 2832.0 5970.00 20912.0 ▇▃▁▁▁
HYDRO 0 1 396.01 245.23 0.0 192.00 365.0 563.00 1403.0 ▇▇▅▁▁
IMPORTS 0 1 2083.18 1195.17 0.0 1190.00 2138.0 2990.00 6668.0 ▆▇▇▁▁
BIOMASS 0 1 713.02 1014.14 0.0 0.00 0.0 1630.00 3262.0 ▇▁▂▂▁
OTHER 0 1 476.70 632.33 0.0 42.00 143.0 754.00 2470.0 ▇▂▁▁▁
SOLAR 0 1 760.66 1594.62 0.0 0.00 0.0 604.00 9892.0 ▇▁▁▁▁
STORAGE 0 1 291.24 358.14 0.0 0.00 214.0 434.00 2660.0 ▇▂▁▁▁
GENERATION 0 1 34971.56 7285.09 18365.0 29290.00 34813.0 40048.00 59605.0 ▃▇▇▃▁
CARBON_INTENSITY 0 1 326.56 139.60 34.0 208.00 319.0 454.00 644.0 ▃▇▅▇▂
LOW_CARBON 0 1 12738.33 4680.01 4626.0 9119.75 11525.0 15561.00 32578.0 ▇▇▃▁▁
ZERO_CARBON 0 1 12025.32 4173.98 4244.0 8891.00 10953.0 14525.00 30616.0 ▆▇▃▁▁
RENEWABLE 0 1 5285.50 4513.98 3.0 1604.00 3995.0 7791.00 25389.0 ▇▃▂▁▁
FOSSIL 0 1 19382.10 8879.23 1700.0 12677.00 18411.0 25393.00 49096.0 ▃▇▆▂▁
GAS_perc 0 1 35.82 12.52 4.6 26.40 36.7 45.50 72.7 ▂▆▇▅▁
COAL_perc 0 1 17.77 16.39 0.0 1.90 14.3 33.20 60.6 ▇▂▃▃▁
NUCLEAR_perc 0 1 19.99 5.24 8.1 16.10 19.3 23.10 42.3 ▂▇▅▁▁
WIND_perc 0 1 12.47 12.32 0.0 3.00 8.3 18.00 66.6 ▇▂▁▁▁
HYDRO_perc 0 1 1.11 0.64 0.0 0.60 1.0 1.50 4.1 ▇▇▃▁▁
IMPORTS_perc 0 1 6.34 3.92 0.0 3.40 6.4 9.10 26.8 ▇▇▂▁▁
BIOMASS_perc 0 1 2.21 3.18 0.0 0.00 0.0 5.00 16.0 ▇▂▂▁▁
OTHER_perc 0 1 1.42 1.92 0.0 0.10 0.5 2.10 10.3 ▇▂▁▁▁
SOLAR_perc 0 1 2.13 4.55 0.0 0.00 0.0 1.60 32.2 ▇▁▁▁▁
STORAGE_perc 0 1 0.74 0.88 0.0 0.00 0.6 1.10 7.9 ▇▁▁▁▁
GENERATION_perc 0 1 100.00 0.00 100.0 100.00 100.0 100.00 100.0 ▁▁▇▁▁
LOW_CARBON_perc 0 1 37.92 15.44 10.7 25.80 35.0 47.20 91.5 ▆▇▅▂▁
ZERO_CARBON_perc 0 1 35.71 13.80 10.7 25.10 33.0 43.70 87.2 ▅▇▃▂▁
RENEWABLE_perc 0 1 15.72 13.65 0.0 4.60 11.7 23.10 71.1 ▇▃▂▁▁
FOSSIL_perc 0 1 53.58 17.38 5.3 41.60 54.7 67.70 88.0 ▁▃▇▇▅
dv_year 0 1 2015.50 4.03 2009.0 2012.00 2016.0 2019.00 2022.0 ▇▇▆▇▇
dv_hour 0 1 11.50 6.92 0.0 5.75 11.5 17.25 23.0 ▇▇▆▇▇
dv_coal_gas_pc 0 1 53.58 17.38 5.2 41.60 54.7 67.70 88.0 ▁▃▇▇▅
dv_solar_wind_pc 0 1 14.60 13.51 0.0 3.60 10.5 21.90 70.5 ▇▃▂▁▁
dv_coal_gas 0 1 19382.10 8879.23 1700.0 12677.00 18411.0 25393.00 49096.0 ▃▇▆▂▁
dv_solar_wind 0 1 4889.49 4464.04 1.0 1251.00 3555.0 7326.00 24991.0 ▇▃▂▁▁
Year 0 1 2015.50 4.03 2009.0 2012.00 2016.0 2019.00 2022.0 ▇▇▆▇▇
dv_month 0 1 6.52 3.45 1.0 4.00 7.0 10.00 12.0 ▇▅▅▅▇

Variable type: POSIXct

skim_variable n_missing complete_rate min max median n_unique
DATETIME 0 1 2009-01-01 2022-12-31 23:30:00 2016-01-01 11:45:00 245424
dv_dateTime 0 1 2009-01-01 2022-12-31 23:30:00 2016-01-01 11:45:00 245424

9.1.2 Check definitions

It is not clear from https://data.nationalgrideso.com/carbon-intensity1/historic-generation-mix/r/historic_gb_generation_mix how the following are defined:

  • LOW_CARBON
  • ZERO_CARBON
  • RENEWABLE
  • FOSSIL
test2021 <- gbGenMix_dt[dv_year == 2021]

#test2021[, ba_LOW_CARBON := ]

9.2 R environment

Packages etc:

  • base R (R Core Team 2016)
  • bookdown (Xie 2016a)
  • data.table (Dowle et al. 2015)
  • ggplot2 (Wickham 2009)
  • here (Müller 2017)
  • hms (Müller 2018)
  • knitr (Xie 2016b)
  • lubridate (Grolemund and Wickham 2011)
  • rmarkdown (Allaire et al. 2018)

References

Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, and Winston Chang. 2018. Rmarkdown: Dynamic Documents for r. https://CRAN.R-project.org/package=rmarkdown.
Dowle, M, A Srinivasan, T Short, S Lianoglou with contributions from R Saporta, and E Antonyan. 2015. Data.table: Extension of Data.frame. https://CRAN.R-project.org/package=data.table.
Grolemund, Garrett, and Hadley Wickham. 2011. “Dates and Times Made Easy with lubridate.” Journal of Statistical Software 40 (3): 1–25. http://www.jstatsoft.org/v40/i03/.
Müller, Kirill. 2017. Here: A Simpler Way to Find Your Files. https://CRAN.R-project.org/package=here.
———. 2018. Hms: Pretty Time of Day. https://CRAN.R-project.org/package=hms.
R Core Team. 2016. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Staffell, Iain. 2017. “Measuring the Progress and Impacts of Decarbonising British Electricity.” Energy Policy 102 (March): 463–75. https://doi.org/10.1016/j.enpol.2016.12.037.
Staffell, Iain, and Stefan Pfenninger. 2018. “The Increasing Impact of Weather on Electricity Supply and Demand.” Energy 145 (February): 65–78. https://doi.org/10.1016/j.energy.2017.12.051.
Wickham, Hadley. 2009. Ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. http://ggplot2.org.
Xie, Yihui. 2016a. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.
———. 2016b. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://CRAN.R-project.org/package=knitr.