Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD...

20
Chris Campbell – Senior Consultant [email protected] Keeping the Lights On Chris Campbell, PhD

Transcript of Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD...

Page 1: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Keeping the Lights On

Chris Campbell, PhD

Page 2: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

• Owns English & Welsh electricity networks• System Operator for UK grid

National Grid

Page 3: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

National Grid

• Manage flows of electricity to homes and businesses on a real time

• Balance the network, ensuring supply and demand are matched second by second

• Not generation

Page 4: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Electricity Market

• Generation provided by electricity market • Policies and framework support the market

Jack Gavigan

Page 5: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Supply/Demand

• Unexpected issues on network

• Demand higher than forecast (residual error)

Page 6: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Supply/Demand

• Request margin (spare capacity above demand)

Page 7: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Strategic Pricing Code Review

• Policy to reimburse flexible energy suppliers• Data driven capacity requests based on supply

forecasting• R analysis prototype

Page 8: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Challenges

• Frequent forecasts• Multiple data sources feed into Oracle database

(demand, availability, wind)• Consumed live

Page 9: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Solutions

Page 10: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

R Task Design

f(x)

Enter

Query

Check Data

Write Results

Page 11: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Live Analysis

• Automated execution• cron

Page 12: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Check Data - S4 Classes

• Specify structure – data required for analysis• Validate contents – apply business rules

Page 13: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

S4 Classes

setClass(Class = "DemandData",slots = c(

Timestamp = "POSIXct",Demand = "numeric"),

prototype = prototype(Timestamp = as.POSIXct(NA),Demand = NA_real_))

Page 14: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

demand <- new(Class = "DemandData", Timestamp = Sys.time() + 1:3 * 1800)

demand# An object of class "DemandData"# Slot "Timestamp":# [1] "2016-05-17 20:21:49 BST"# ...# Slot "Demand":# [1] NA

S4 Classes

Page 15: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

slot(object = demand, name = "Demand") <- 1:3

demand# An object of class "DemandData"# Slot "Timestamp":# [1] "2016-05-17 20:21:49 BST"# ...# Slot "Demand":# [1] 1 2 3

S4 Classes

Page 16: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

validDemand <- function(object) {dmd <- slot(object = object,

name = "Demand")if (any(dmd < 0)) {

stop("Demand less than zero") }

}setValidity(Class = "DemandData",

method = validDemand)

Check Data

Page 17: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

validObject(demand)# [1] TRUE

Check Data

Page 18: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

High Integrity Reporting

• Data check fails• Write informative message to file

Chris Hirata/Kawika Singson

Page 19: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

High Integrity Reporting

• Analysis consumed by downstream processes –capacity pricing

• Reporting allows R code to run unmonitored –data error rapidly traceable

Page 20: Keeping the Lights On - R . Manchester...2016/05/17  · Keeping the Lights On Chris Campbell, PhD Chris Campbell – Senior Consultant ccampbell@mango-solutions.com • Owns English

Chris Campbell – Senior [email protected]

Summary

• Analysts with domain-specific expertise generate analytic code

• S4 Class allows data definition and validation• R Code deployed into high integrity system