Skip to contents

Calendars (time within a year), timeframes and samples, and the horizon of milestone years

PDF, A4, one page · energyRt 0.91.5.9015 (dev) · 2026-11-29
Build a calendar
tt <- make_timetable(list(
  SEASON = c("WIN", "SPR", "SUM", "FAL"),
  PART = c("NIGHT", "DAY", "EVENING")))
cal <- newCalendar(timetable = tt,
                   name = "s4p3")
Nested levels, coarse to fine: 4 × 3 = 12 timeslices, equal shares.
tt2 <- make_timetable(list(SEASON = list(
  WIN = list(1/4, PART = list(
    DAY = 9/24, NGT = 12/24, PK = 3/24)),
  SUM = list(3/4, PART = list(
    DAY = 12/24, NGT = 9/24, PK = 3/24)))))
Unequal shares: a number before the level gives each member's share.
names(calendars)  # the shipped catalogue
s4h <- calendars$s4_h24
autoplot(cal)
The s4p3 calendar from season to part of day

Every calendar starts at ANNUAL; each level splits the one above. The finest level is the timeslice the model steps through; coarser ones are timeframes a commodity or a storage cycle can sit at.

Three numbers per timeslice
share one unit of its timeframe, as a share of the year (an HOUR slice: 1/8760)
width how long it is on the time axis, in those units (1 by default)
weight how many times it repeats in the year; 0 leaves it out

Hours it stands for: share × width × weight × 8760. One model step: share × width.

full d365_h24 every hour of the year, weight 1
sampled d365_h24_1dps real hours of kept days; weight scales to the year; the gaps are known
averaged s4_h24 an average day per season; weight = days it stands for
blocks s4_hp3 hours of 11 / 4 / 9 width (day, peak, night), weight = days
Calendar functions
make_timetable(struct, year_fraction, …)
The nested levels and their shares → a timetable.
newCalendar(name, timetable, year_start, default_timeframe, …)
A calendar from a timetable; year_start = list(month = 4, day = 1) for a fiscal year.
sample_calendar(cal, slices, counts, name)
Keep some timeslices of a calendar; the rest get weight 0 and the source is recorded.
h <- calendars$d365_h24
two <- sample_calendar(h,
  grep("^d(015|016)_",
       h@timeframes$HOUR, value = TRUE),
  name = "two_days")
Two consecutive days of the hourly year.
calendar_samples(calendar, level, sample_size, n, seed, …)
Random draws of a level (days, weeks) as an editable table.
The catalogue
annual 1 one timeslice
s4_hp3 12 4 seasons × day, peak, night
s4_h24 96 an average day per season
m12_h24 288 an average day per month
d365_h24_1dps 96 one real day per season
d365_h24_1dpm 288 one real day per month
d365_h24 8760 every hour of the year

calendars$<name>; names(calendars) lists all. Built with the timescales package.

Timeframes in the model
ELC <- newCommodity("ELC",
  timeframe = "HOUR")    # every slice
COA <- newCommodity("COA",
  timeframe = "ANNUAL")  # once a year
  • A commodity is balanced at its timeframe; default the finest.
  • A process runs at the finest timeframe of its commodities; timeframe = overrides.
  • A storage level closes at its cycle ("ANNUAL" by default).
  • A timeframe the calendar lacks is refused at interpolation, naming the ones it has.
The horizon
hor <- newHorizon(period = 2025:2050,
  intervals = c(1, 4, 5, 5, 5, 5))
newHorizon(period, intervals, base_year, …)
Milestone years and the years each stands for; intervals are the period lengths.
The horizon's milestone years and their intervals
names(horizons)       # shipped horizons
newHorizon(intervals = data.frame(
  start = c(2025, 2030),
  mid = c(2025, 2030),
  end = c(2029, 2034)))
Explicit intervals: start, the milestone (mid), end.
Changing a model's time
setCalendar(obj, ...)
A model (or scenario) on another calendar.
recast_model_calendar(object, calendar, …)
Move the model's timeslice data to another calendar: values are rates, re-aggregated.
upgrade_model_calendar(x)
Bring a model saved with an older calendar format up to date.
getYearCalendars(x)
The calendar of each milestone year, where years differ.
year_label(object)
Milestone labels, e.g. FY2025-26 on a fiscal year.
Solving on samples
solve_by_sample(object, name, samples, level, …)
Solve each sample as a variant, then read the spread with sample_summary().
scen <- interpolate_model(mod,
  name = "BASE", fold = TRUE)
fold = TRUE: a weather series equal in every year is stored once -- the largest saving in an hourly model.
Choosing a resolution
  • Structure in flux: s4_hp3 (12) -- solves instantly.
  • Profiles and peaks matter: s4_h24 (96), m12_h24 (288).
  • Storage or ramps: real consecutive hours -- d365_h24_1dps, d365_h24_1dpm.
  • Final runs: d365_h24 (8760); check model_size() first, iterate on a sample.
  • A sampled and an averaged calendar of the same size differ in their data: real days or the mean day.