Calendars are defined by the structure of timeframes and time-timeslices
with shares of time in a year. The structure is represented by a
timetable data.frame with levels of timeframes in the named columns,
and names of individual time-timeslices in every timeframe.
The number of rows in timetable is equal to the total number
of time-timeslices on the lowest level.
Every timeframe is a set of timeslices ("timeslices") - a named fragment
of time with a year-share. Timeframes have nested structure.
A parent may have any number of children, so a level can be irregular
(months of 28-31 days above the days of the year). Each timeslice is named
by the shortest trailing part of its path of labels that is unique (a day
numbered through the year keeps its own label under a month; an hour needs
its day).
The timetable argument is accepted in two layouts, and the calendar
stores the first:
timeslice names: each timeframe column holds the name of the timeslice of the row at that timeframe (
MONTH = "m01",HOUR = "m01_h00"), and the finest timeframe column names the rows. This is whatmake_timetable()returns and what@timetableholds.labels: each timeframe column holds the label of the row inside its parent (
MONTH = "m01",HOUR = "h00", repeated under every month), with an optionaltimeslicecolumn naming the timeslices of the lowest level. The timeslice names are composed from the labels and thetimeslicecolumn is dropped.
Arguments
- name
character. Name of the calendar object. Use to distingush between different structures and subsets of time-timeslices. The name is used to propose default folder names for the model/scenario scripts to separate solutions of the same scenario with different calendar objects.
- desc
character. Description of the calendar object, for own references.
- timetable
data.frame. Data frame with one row per time-timeslice of the lowest level and one named column per timeframe, coarsest first. Every timeframe is a set of time-timeslices ("timeslices") - a named fragment of time with a year-share. Timeframes have nested structure where every timeslice serves as a parent for the lower level of time-timeslices (children). Each timeframe column holds the name of the timeslice the row belongs to at that timeframe, the names listed in
timeframes(MONTH = "m01",HOUR = "m01_h00"); the column of the lowest timeframe names the rows. Three numbers follow.shareis the length of one unit of the row's timeframe as a fraction of the year: one hour for a time-timeslice counted in hours, the time-timeslice's own length for a month, a season, a day.widthis how long the time-timeslice is on the time axis, in those units; optional, 1 by default, any value above zero.weightis how many times the time-timeslice repeats in the year, which is also the multiplicity of a sample; optional, 1 by default (1 /year_fractionfor a calendar that enumerates part of the year); zero leaves the time-timeslice out. The hours a row stands for aresharexwidthxweightx 8760, andsharexwidthover the rows of positive weight sums toyear_fraction. A table with the labels of each timeframe in its columns (HOUR = "h00") and an optionaltimeslicecolumn is accepted on input and converted.- year_fraction
numeric. The fraction of a year covered by the calendar, e.g. 1 for annual calendar (default), 0.5 for semi-annual, 0.25 for quarterly, etc. Currently must be specified manually for subset calendars to validate the sum of the shares.
- year_start
list.
list(month = , day = )giving the first day of the model year; defaults to January 1. A non-January anchor makes model yearyspan[year_start(y), year_start(y + 1)), andyis the STARTING Gregorian year – Indian "FY 2021-22" is model year 2021 – which is the conventiontimescales::calendar_build()uses. The anchor is carried and reported only: it sets the default milestone labels (seeyear_label()) and does NOT yet drive timeslice-to-timestamp alignment oryear_fraction.- utc_offset_minutes
integer. Constant offset of local time from UTC, in minutes; defaults to 0 (UTC). E.g. 330 for IST (UTC+5:30). Carried for provenance alongside
year_start; Olson time zones and DST are not supported.- default_timeframe
character. The name of the default level of the time-timeslices used in the model. If not specified, the lowest level of the timeframes is used as the default timeframe.
- misc
list. Any additional data or information to store in the object.
- tokens
optional named list or character vector giving the
timescalestoken of timeframes, e.g.c(MONTH = "m12", HOUR = "h24"). By default the token of each timeframe is read off its labels: the token whose vocabulary equals them, else the smallest one that contains them. Worth giving for a sample, whose labels fit several vocabularies.- units
optional named list or numeric vector: the length of one unit of a timeframe in hours, e.g.
list(HOUR = 1, MONTH = 1). See the section Units and HOUR.- ...
ignored
Share, width and weight
Three numbers describe a row of the timetable.
share: the length of ONE UNIT of the timeslice's timeframe, as a fraction of the year. For a timeslice counted in hours it is one hour, 1/8760; for a month, a season, a day it is that timeslice's own length.width: how long the timeslice is on the time axis, in those units. 1 by default; any value above zero.weight: how many times the timeslice repeats in the year, which is also the multiplicity of a sample. 1 by default (1 /year_fractionfor a calendar that enumerates part of the year). Zero leaves the timeslice out; a negative weight is refused.
The hours a timeslice stands for are share x width x weight x 8760,
and one step of the model is share x width: that product is what the
model takes as the length of the timeslice (pTimesliceShare), with the
weight beside it (pTimesliceWeight). Over the timeslices of positive
weight share x width x weight sums to 1.
A month is share = 744/8760, width = 1, or share = 1/8760, width = 744
with units = list(MONTH = 1): the two are the same timeslice for the
model. When weight is absent it is 1 / year_fraction; declared weights
that do not annualise are scaled, with a warning. A calendar whose
timetable holds timeslices of zero weight is used as the sample that keeps
the others (see sample_calendar()): data declared on the timeslices left
out is accepted and ignored.
Units and HOUR
units gives the length of one unit of a timeframe in hours. The share of
every timeslice of a finest timeframe that is listed must be that unit; a
share that is not is an error naming the timeslices. A timeframe named
HOUR always has the unit of one hour: the share of each of its
timeslices is one hour of the year, 1/8760 (1/8784 in a year of 366 days),
in a full hourly calendar, in a sample of one and in an averaged calendar
alike. Its width may be above 1: a block of hours is an HOUR timeslice
several hours wide. The hours of an average day are declared with the
one-hour share and the days they stand for in weight, a block of hours
with its hours in width as well:
data.frame(SEASON = "WIN", HOUR = "h00", share = 1/8760, weight = 90),
data.frame(SEASON = "WIN", HOUR = "DAY", share = 1/8760, width = 11, weight = 90).
make_timetable() divides the year among the timeslices it is given, so
it does not build such a table; a timeframe named HOUR whose timeslices
it would give a longer share is refused. An hour of the day is read off an
HOUR timeslice only where it is 1 wide.
- ANNUAL
character, annual, the top level of timeframes
- TIMEFRAME2
character, (optional) first subannual level of timeframes
- TIMEFRAME3
character, (optional) second subannual level of timeframes
- ...
character, (optional) further subannual levels of timeframes
- timeslice
character, (optional, labels layout only) names of the timeslices of the lowest level of timeframes, used when they name every row uniquely. If not specified, they are composed with the formula:
{TIMESLICE2}_{TIMESLICE3}...- share
numeric, the length of one unit of the row's timeframe as a fraction of the year
- weight
numeric, (optional) the number of times the row repeats in the year; zero leaves it out
- width
numeric, (optional) the length of the row in units of its timeframe, 1 by default
