stock_areas {gadget3} | R Documentation |
Gadget3 stock area dimensions
Description
Add area dimensions to g3_stock classes
Usage
g3_areas(area_names)
g3s_livesonareas(inner_stock, areas)
g3s_areagroup(inner_stock, areagroups)
Arguments
area_names |
A character vector of area names to use in the model |
inner_stock |
A |
areas |
A vector of numeric areas that the stock is part of |
areagroups |
A list mapping names to vectors of numeric areas the stock is part of |
Details
g3s_livesonareas
breaks up a stock by area.
Within a model, areas are only referred to by integer, however if these are named
then that name will be used for report output.
Each area will be defined as a variable in your model as area_x
,
allowing you to use names in formulas, e.g. run_f = quote( area == area_x )
.
g3_areas
is a helper to map a set of names to an integer
Inside a model each area will only be referred to by integer.
g3s_areagroup
allows areas to be combined, this is mostly used internally
by g3l_catchdistribution
.
Value
g3_areas
A named integer vector, assigning each of area_names a number.
g3s_livesonareas
A g3_stock
with an additional 'area' dimension.
When iterating over the stock, iterate over each area in turn, area will be set to the current integer area.
When intersecting with another stock, only do anything if area is also part of our list of areas.
g3s_areagroup
A g3_stock
with an additional 'area' dimension.
When iterating over the stock, iterate over each areagroup in turn, area will be set to the first area in the group.
When intersecting with another stock, only do anything if area is part of one of the groups.
Examples
# Make a lookup so we can refer to areas by name
area_names <- g3_areas(c('a', 'b', 'c', 'd', 'e'))
stopifnot(area_names == c(a=1, b=2, c=3, d=4, e=5))
# Define a stock with 3 lengthgroups and 3 areas
stock <- g3_stock('name', c(1, 10, 100)) %>%
g3s_livesonareas(area_names[c('a', 'b', 'c')])
# Area variables will be defined, so you can refer to them in formulas:
g3a_migrate(stock, g3_parameterized("migrate_spring"),
run_f = ~area == area_b && cur_step == 2)
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
# Define a stock that groups areas into "north" and "south"
stock <- g3_stock('name', c(1, 10, 100)) %>%
g3s_areagroup(list(
north = area_names[c('a', 'b', 'c')],
south = area_names[c('d', 'e')]))
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)