Skip to contents

The spatial mirror of interpolating on a sampled calendar, usable up front: declares only region, drops trade routes that cross the subset boundary (with a message), and – when boundary_prices supplies a price for a dropped route – replaces it with an import/export stub at the kept endpoint. When the model carries a geoscale, it is filtered in step (recording coverage; see geoscales::geoscale_coverage()).

Usage

subset_model_regions(
  object,
  region,
  boundary_prices = NULL,
  split_weight = NULL,
  keep = NULL,
  drop = NULL,
  dryrun = FALSE,
  verbose = isVerbose()
)

Arguments

object

a model.

region

character vector of regions to keep (must be a subset of the model's declared regions).

boundary_prices

optional data.frame pricing the boundary stubs of dropped routes, with columns src, dst, price, and optionally trade (object name; NA = any), year, timeslice (both NA = all), and cap.up (explicit stub bound overriding the derivation from the route's ava.* rows). Routes without a price row are dropped without a stub.

split_weight

the weight a value declared at a split region group is divided by, keyed on an object name or a class and optionally on a column: list(SUP_COA = c(ava.up = "area"), demand = "population"), or the flat form c("SUP_COA:ava.up" = "area"). One weight for everything that asks is split_weight = "area", or list(all = "area"), and a key for one object or class still wins over it. A weight is a column the geoscale declares (see geoscales::geoscale_weights()) or a named numeric of shares over the kept regions. There is no default: dividing a demand or a fleet by area shares a city with a desert.

keep, drop

keys, in the same grammar, whose values are settled without a weight – held whole in every part, or left out of the cut.

dryrun

return the pre-flight report instead of cutting: what the cut splits, which values still need a decision, which are carried, the caveats and the ways on. is_separable() is its verdict alone.

verbose

print per-object messages.

Value

the restricted model, or the pre-flight report when dryrun = TRUE.

Details

Much of this is also reachable without the verb, by passing a geoscales::filter_geoscale() subset to interpolate_model() – but not all of it: that route does not yet keep a declaration made above the region level (see below), so on a multi-level model the two do not agree. Use the verb where any object is declared on a coarser code than the model's regions.

Declarations above the region level

A model may declare an object at a coarser geoscale cell than its regions: a commodity with @geoframe = "zone" is balanced per zone, and its supply, imports and trade routes are then declared on zone codes rather than region codes. Against a subset such a code is in one of three states.

  • Covered – every region under it survives. It is kept exactly as it is, since it describes the ground the subset holds, and the message names it.

  • Outside – none survives. It is dropped, like any other out-of-sample object.

  • Split – some survive. Each value declared there is resolved column by column: a rate, a price or an invariant is carried unchanged, while a quantity asks for the weight to divide it by (split_weight), to be held whole (keep), or to be left out (drop). Until every quantity is settled the call stops with the pre-flight report, which names the objects, the columns and the ways on – extend region to the whole group, aggregate_model_regions() to that level and subset there, or declare those objects on the finer regions.

A split group that no object is declared at is not a problem and passes silently: a geoscale whose groups the subset happens to cut is normal. No class is exempt from the classification. weather passes it because a coarse profile is an intensive series, which is carried unchanged; a coarse invcost or fixom passes it for the same reason but stays a caveat, since it is charged once at the cell – the sub-model bears the whole cost rather than its share, and the remedy is to declare the cost on the endpoints.

See also

Examples

repo <- newRepository(
  "mini",
  newCommodity("COA", unit = "MMBtu"),
  newCommodity("ELC", unit = "MWh", timeframe = "ANNUAL"),
  newSupply("SUP_COA", commodity = "COA", supply = data.frame(cost = 1)),
  newTechnology("ECOA", input = list(comm = "COA"), output = list(comm = "ELC"),
                cap2act = 1, invcost = list(invcost = 100),
                olife = list(olife = 30)),
  newDemand("DEM", commodity = "ELC",
            demand = data.frame(region = c("W1", "W2"), year = 2020, demand = 10))
)
mod <- newModel("MINI", data = repo, calendar = calendars$annual,
                region = c("W1", "W2"), horizon = horizons$Y2020_2060_by_5)

# keep one region; demand, capacity and routes outside it are dropped
sub <- subset_model_regions(mod, "W1")
get_region(sub)
#> [1] "W1"