Reading a solved scenario: getData() and its filters, aggregation on the way out, mixes, variants and scenario comparison
One call, one table
getData(CO2CAP, name = "vTechOut",
comm = "ELC", year = 2040,
merge = TRUE)
# A tibble: 1,185 × 12 scenario name tech comm region year time…¹ value class <chr> <chr> <chr> <chr> <chr> <int> <chr> <dbl> <chr> 1 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> 2 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> 3 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> 4 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> 5 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> 6 CO2CAP vTechO… EBIO ELC R04 2040 d015_… 0.0634 <NA> …
One row per index: process, commodity, region, year, timeslice. Values in model units, per occurrence of the slice: here GWh in one hour of a sampled day.
The scenarios on this sheet: TOPIA zone Z3, one real day per season, milestones 2030/2040/2050, solved without (BASE) and with the shipped CO2 cap (CO2CAP).
Filters
comm = "ELC" |
values of a set: region, year, tech, comm, timeslice, ... |
tech_ = "^ESOL" |
a trailing _ makes it a regular expression |
name_ = "^vEms" |
parameters and variables by pattern |
parameters = FALSE |
variables only (and variables = FALSE) |
merge = TRUE |
one table; FALSE (default) gives a named list, one per name |
process = TRUE |
tech, stg, trade, sup ... renamed process, so classes stack |
names(getData(CO2CAP, comm = "CO2",
parameters = FALSE))
[1] "vBalance" "vEmsFuelTot" "vOutTot" [4] "vTechEmsFuel"
Without
name: everything that touches CO2.Aggregate on the way out
getData(CO2CAP, name = "vTechOut",
tech = "EBIO", comm = "ELC",
timeframe = "lowest",
geoframe = "coarsest", merge = TRUE)
# A tibble: 3 × 8 scenario name tech comm region year timeslice value <chr> <chr> <chr> <chr> <chr> <int> <chr> <dbl> 1 CO2CAP vTechOut EBIO ELC TOPIA 2030 ANNUAL 1065. 2 CO2CAP vTechOut EBIO ELC TOPIA 2040 ANNUAL 1065. …
timeframe = |
"highest" as stored (default); "lowest" sums to ANNUAL; or a level: "YDAY"
|
geoframe = |
"finest" (default), "coarsest", or a level: "zone"; trade counts only where it crosses the new border |
apply_weights |
× how often the slice occurs in its year: a sampled day stands for ~91 |
apply_period_length |
× years the milestone stands for; flows and costs, never capacity |
Levels (vStorageLevel) are not summed: they take the closing value.
Variants are columns
getData(CO2CAP, name = "vTechCap",
tech_ = "^ESOL", year = 2050,
merge = TRUE) |>
select(base, vintage, cluster,
region, value)
# A tibble: 6 × 5 base vintage cluster region value <chr> <chr> <chr> <chr> <dbl> 1 ESOL 2030 FL R05 3.85 2 ESOL 2030 TH R05 4.30 3 ESOL 2030 TH R06 4.74 4 ESOL 2045 FL R04 1.03 5 ESOL 2045 FL R05 0.763 …
A vintaged or clustered process reports per variant;
base, vintage and cluster say which. variants = FALSE drops them.variantSummary(CO2CAP, name = "vTechCap",
by = "base") |>
filter(year == 2050)
base region year n total mean 1 ESOL R04 2050 1 1.033865 1.033865 2 ESOL R05 2050 3 8.903742 2.967914 3 ESOL R06 2050 2 5.881988 2.940994 …
Totals and spread over the variants of each base.
Several scenarios
getData(list(BASE, CO2CAP),
name = "vEmsFuelTot",
merge = TRUE) |>
summarise(total = sum(value),
.by = c(scenario, year))
# A tibble: 6 × 3 scenario year total <chr> <int> <dbl> 1 BASE 2030 22242. 2 BASE 2040 15932. 3 BASE 2050 8924. 4 CO2CAP 2030 13500 …
A list stacks the scenarios under a
scenario column.compare_scenarios(object, runs, base, tol_rel, top_n, …)Status, objective and every variable against the first scenario.
cmp <- compare_scenarios(list(BASE, CO2CAP))
cmp$overview[, c("scenario", "objective",
"obj_rel")]
scenario objective obj_rel 1 BASE 56614.33 0.00000000 2 CO2CAP 58411.59 0.03174582
cmp$top[1:3, c("variable", "where", "diff")]
variable where 1 vEmsFuelTot comm=CO2 region=R06 year=2030 2 vEmsFuelTot comm=CO2 region=R06 year=2040 3 vEmsFuelTot comm=CO2 region=R04 year=2030 …
The largest differences, located.
autoplot(cmp) and report(cmp) draw them.Mixes, ready to plot
getMix(object, type, comm, region, year, timeslice, by, drop_small, top_n)A tidy generation, capacity, new-capacity or fuel mix -- what
autoplot() draws.getMix(CO2CAP, type = "generation",
region = "R05", year = 2050) |>
select(process, flow, value)
process flow value 1 EBIO generation 1108.5947 2 ECOA generation 657.0000 3 EGAS generation 1314.0000 4 EHYD generation 19053.0000 5 ESOL generation 14820.6079 6 STG_ELC storage-out 3928.1936 7 STG_ELC storage-in -4352.5691 8 demand demand 306.8493 …
Storage charging is negative;
demand closes the balance.Find what is there
get_variable(CO2CAP, "vObjective")
value
<num>
1: 58411.59
One variable as stored: no filters, no labels -- the fastest read.
getData(CO2CAP, name = "pDemand",
region = "R05", merge = TRUE)
# A tibble: 288 × 8 scenario name dem comm region year <chr> <chr> <chr> <chr> <chr> <int> 1 CO2CAP pDemand DEM_ELC ELC R05 2030 …
Parameters come out the same way: what the solver was given.
sets = TRUE, maps = TRUE add the rest.The variables
vEmsFuelTot |
emissions from fuel use | cryt |
vBalance |
commodity balance (surplus) | cryt |
vTotalCost |
total cost by region and year | ry |
vObjective |
objective: total discounted cost | |
vTechNewCap |
new capacity | ry |
vTechCap |
installed capacity | ry |
vTechAct |
activity | ryt |
vTechInp |
input of a commodity | cryt |
vTechOut |
output of a commodity | cryt |
vSupOut |
supply used | cryt |
vDemInp |
demand met | cryt |
vDummyImport |
balance slack (debug) | cryt |
vStorageInp |
charge | cryt |
vStorageOut |
discharge | cryt |
vStorageLevel |
stored energy (a level) | cryt |
vStorageOutCap |
discharge capacity | ry |
vTradeIr |
flow on a route, at the sender | crryt |
vExportRow |
export to the rest of the world | cryt |
vImportRow |
import from the rest of the world | cryt |
vTradeCap |
route capacity | y |
Dimensions: r region, y year, t timeslice, c commodity. Cost variables: vTechInv, vTechEac, vTechFixom, vTechVarom, vSupCost, vTaxCost and their storage and trade twins. Parameters start with p, maps with m.
Recipes
getData(CO2CAP, name = "vTechOut",
comm = "ELC", apply_weights = TRUE,
merge = TRUE) |>
mutate(tech = coalesce(base, tech)) |>
summarise(GWh = sum(value),
.by = c(tech, year)) |>
arrange(year, desc(GWh))
# A tibble: 21 × 3 tech year GWh <chr> <int> <dbl> 1 ENUC 2030 32855. 2 ESOL 2030 21349. 3 EHYD 2030 19053 …
Annual generation by technology: per-slice values × slice weight, summed; variants rolled up to their
base.out <- getData(CO2CAP, name = "vTechOut",
tech_ = "^EWIN", year = 2050,
timeframe = "lowest", merge = TRUE)
cap <- getData(CO2CAP, name = "vTechCap",
tech_ = "^EWIN", year = 2050,
merge = TRUE)
sum(out$value) / sum(cap$value) / 8760
[1] 0.2837396
The wind capacity factor in 2050: output over capacity ×
cap2act (8760 GWh per GW-year).Inputs, before solving
getData(mod, name = "invcost",
class = "technology",
interpolate = TRUE,
years = c(2030, 2050),
merge = TRUE) |>
select(tech, vintage, year, value)
# A tibble: 36 × 4 tech vintage year value <chr> <chr> <dbl> <dbl> 1 ECOA <NA> 2030 2000 2 ECOA <NA> 2050 2000 3 ECOA <NA> 2030 25 4 ECOA <NA> 2050 25 …
The same call on a model, repository or single object reads the declared data;
interpolate = TRUE fills the years as the model will.Plot it yourself
d <- getMix(CO2CAP, region = "R05",
year = 2050, timeslice = "^d196_") |>
filter(flow != "demand") |>
mutate(hour = as.integer(
sub(".*_h", "", timeslice)))
ggplot(d, aes(hour, value,
fill = process)) +
geom_col(width = 1) +
theme_energyRt()
A July day in R05, 2050: charging and exports below zero. Any tidy result is a ggplot away.
Flows between regions
getData(CO2CAP, name = "vTradeIr",
year = 2050, timeframe = "lowest",
merge = TRUE) |>
select(src, dst, value)
# A tibble: 5 × 3 src dst value <chr> <chr> <dbl> 1 R04 R05 651. 2 R05 R04 901. 3 R04 R06 3946. 4 R06 R04 44.6 5 R05 R06 8259.
One row per direction:
src sends, dst receives, before losses. The rest of the world: vImportRow, vExportRow.Costs
getData(CO2CAP, parameters = FALSE,
name_ = "^vTech(Eac|Fixom|Varom)$",
merge = TRUE) |>
summarise(cost = sum(value),
.by = c(name, year))
# A tibble: 6 × 3 name year cost <chr> <int> <dbl> 1 vTechEac 2030 687. 2 vTechEac 2040 755. 3 vTechEac 2050 986. 4 vTechFixom 2030 1694. 5 vTechFixom 2040 1588. 6 vTechFixom 2050 1560.
Annualised investment, fixed and variable O&M per milestone year, undiscounted;
vObjective is the discounted total.A storage through the day
getData(CO2CAP, name = "vStorageLevel",
region = "R05", year = 2050,
timeslice_ = "^d196_", merge = TRUE) |>
mutate(hour = as.integer(
sub(".*_h", "", timeslice))) |>
ggplot(aes(hour, value,
colour = vintage)) +
geom_step() + theme_energyRt()
A level, so it is never summed over slices: each value is the closing state of its hour.
Save it
gen <- getMix(CO2CAP, type = "generation")
write.csv(gen, "gen.csv", row.names = FALSE)
arrow::write_parquet(gen, "gen.parquet")
Results are plain data frames: any writer takes them. The solved scenario itself is kept by
save_scenario().Shares
clean <- c("ESOL", "EWIN", "EHYD")
getMix(CO2CAP) |>
filter(flow == "generation") |>
summarise(share = sum(value[process
%in% clean]) / sum(value),
.by = year)
year share 1 2030 0.5049227 2 2040 0.5078004 3 2050 0.5534138
Wind, solar and hydro in generation, by year: storage and imports excluded through
flow.Units
convert("GWh", "PJ")
[1] 0.0036
convert(1, "MEUR2020", "MUSD2020")
[1] 1.142196
Results are in the units the model declares -- here GWh and GW. cap2act links capacity to activity; convert() changes units, currencies and price years.
Runs and the base year
run = "mm_highs" |
read another solve of the same scenario; "all" adds a run column |
base_year = TRUE |
adds the separately solved base year, tagged in source
|
digits, drop.zeros, na.rm
|
tidy the output |
newNames, newValues
|
rename sets, relabel their values |
sample_summary(x, name, probs, by, …)Quantiles of a variable across the samples of a
solve_by_sample() ensemble.Pitfalls
- The default
timeframe = "highest"returns every slice; it sums nothing. Ask for"lowest"orapply_weights = TRUEto get annual totals. - A per-slice value is one occurrence: on a sampled calendar, multiply by the weight before summing.
- Summing a capacity over years, or a level over slices, gives a number with no meaning.
- Milestone values are for one year of the period;
apply_period_lengthis for totals over the horizon. -
merge = FALSE(the default) returns a list, even for a single name.
