lookup_timestep_sequence() returns an ordered vector of timesteps, possibly
crossing over the year boundary.
Usage
lookup_timestep_sequence(
x,
season = NULL,
start = NULL,
end = NULL,
direction = NULL,
season_buffer = 1,
n_steps = NULL
)Arguments
- x
A BirdFlow object
- season
a season name, season alias, or "all". See
lookup_season_timesteps()for options.- start
The starting point in time specified as a timestep, character date, or date object.
- end
The ending point in time as a date or timestep.
- direction
Either "forward" or "backward" defaults to
"forward"if not processing dates. If using date inputdirectionis optional and is only used to verify the direction implicit in the dates.- season_buffer
Only used with
seasoninput.season_bufferis passed tolookup_season_timesteps()and defaults to 1; it is the number of timesteps to extend the season by at each end.- n_steps
Alternative to
endThe end will ben_stepsaway fromstartindirection; and the resulting sequence will haven_steptransitions andn_steps + 1timesteps.
Details
lookup_timestep_sequence() is unlikely to be called directly but it's
arguments will likely be passed from other functions like predict() and
route().
Whether called directly or via another function lookup_timestep_sequence()
is a flexible function that allows several ways of defining the sequence.
Dates. Input character dates (e.g. "2023-06-21") or date objects to both
startandend. The direction will be determined from the dates sodirectionis optional. Ifdirectionis used an error will be thrown if it doesn't conform with the direction implicit in the dates.Timesteps. Use numeric
startandendto indicate a starting and ending timestep. Since many models are circulardirectionis used to determine whether to go forward or backwards fromstarttoend;directionwill default to forward.Season. Input a season name (or alias) into
season."all"can also be used to indicate all timesteps, in which case with cyclical models the last timestep will match the first. Ifseasonis used (and isn't"all)season_buffferindicates the number of timesteps to extend the season by. The default of 1 means that the sequence will start 1 timestep (week) before and end 1 timestep after the dates for the season returned by[species_info()].directionis followed and defaults to forward.Start and offset. Use
startwith a timestep or date input andn_stepsto create a sequence that starts atstartand then proceedsn_stepsindirectionwhich default to "forward". The returned object will haven_steps + 1timesteps in the sequence.Default If
seasonandstartare both NULL (or omitted) the default is to return all timesteps in the model, equivalent toseason = "all".
Examples
bf <- BirdFlowModels::rewbla
# 1. Dates - order of dates determines direction
lookup_timestep_sequence(bf, start = "2023-12-1", end = "2024-01-20")
#> [1] 48 49 50 51 52 1 2 3
lookup_timestep_sequence(bf, start = "2024-01-20", end = "2023-12-1")
#> [1] 3 2 1 52 51 50 49 48
# 2. Timesteps - direction defaults to "forward"
lookup_timestep_sequence(bf, start = 50, end = 3)
#> [1] 50 51 52 1 2 3
lookup_timestep_sequence(bf, start = 50, end = 3, direction = "backward")
#> [1] 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26
#> [26] 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3
# 3. Season - direction defaults to "forward", season_buffer defaults to 1
lookup_timestep_sequence(bf, "prebreeding_migration")
#> [1] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
lookup_timestep_sequence(bf, "prebreeding_migration", season_buffer = 0,
direction = "backward")
#> [1] 17 16 15 14 13 12 11 10 9 8 7 6 5
# 4. start & n_steps (start can be date or timestep)
lookup_timestep_sequence(bf, start = "2022-04-11", n_steps = 5)
#> [1] 15 16 17 18 19 20
lookup_timestep_sequence(bf, start = 10, n_steps = 5)
#> [1] 10 11 12 13 14 15
# 5. No time arguments, equivalent to season = "all"
lookup_timestep_sequence(bf)
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#> [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#> [51] 51 52 1
lookup_timestep_sequence(bf, season = "all", direction = "backward")
#> [1] 1 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29
#> [26] 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4
#> [51] 3 2 1
