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 inputdirection
is optional and is only used to verify the direction implicit in the dates.- season_buffer
Only used with
season
input.season_buffer
is 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
end
The end will ben_steps
away fromstart
indirection
; and the resulting sequence will haven_step
transitions andn_steps + 1
timesteps.
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
start
andend
. The direction will be determined from the dates sodirection
is optional. Ifdirection
is used an error will be thrown if it doesn't conform with the direction implicit in the dates.Timesteps. Use numeric
start
andend
to indicate a starting and ending timestep. Since many models are circulardirection
is used to determine whether to go forward or backwards fromstart
toend
;direction
will 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. Ifseason
is used (and isn't"all
)season_bufffer
indicates 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()]
.direction
is followed and defaults to forward.Start and offset. Use
start
with a timestep or date input andn_steps
to create a sequence that starts atstart
and then proceedsn_steps
indirection
which default to "forward". The returned object will haven_steps + 1
timesteps in the sequence.Default If
season
andstart
are 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