Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lars Dalby
almass
Commits
ff4d04c4
Commit
ff4d04c4
authored
Jan 07, 2019
by
LDalby
Browse files
Auto detect number of seasons. Compile with the new run.
parent
93f723de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Grendel/scenarios/numbers_report.Rmd
View file @
ff4d04c4
...
...
@@ -21,7 +21,7 @@ library(fs)
library(colorblindr)
library(glue)
date_stamp <- "2019-01-0
4
"
date_stamp <- "2019-01-0
5
"
```
Document compiled: `r Sys.time()`
...
...
@@ -40,6 +40,8 @@ path(current, jobs, grain_dist_file) %>%
fst::read_fst() %>%
as_tibble() -> grain_dists
n_seasons <- max(grain_dists$season)
goose_numbers_file <- glue("{jobs}_scenario-goose-numbers_{date_stamp}.fst")
path(current, jobs, goose_numbers_file) %>%
fst::read_fst() %>%
...
...
@@ -60,7 +62,6 @@ goose_numbers %>%
group_by(day, species, grain_dist) %>%
summarise(numbers = mean(numbers)) -> default_numbers
# Summarize field forage data ----
# Mean numbers per day
goose_numbers %>%
select(grain_dist, param, value, season, day, pinkfoot, barnacle, greylag) %>%
...
...
@@ -77,116 +78,21 @@ left_join(numbers_per_day, .,
by = c("grain_dist", "day", "species"),
suffix = c("", "_default")) %>%
mutate(standarized = numbers/numbers_default) -> numbers_per_day
```
goose_sp <- "pinkfoot"
goose_sp <- "greylag_daily_avg"
```{r daily-avg-plot, echo=FALSE}
numbers_per_day %>%
filter(param == "GOOSE_BN_STARTNO_SCALER",
species ==
goose_sp
) %>%
species ==
"pinkfoot"
) %>%
ggplot(aes(day, standarized)) +
geom_line(aes(color = factor(value))) +
scale_color_brewer(palette = "Set3", name = "Barnacle scaler") +
hrbrthemes::theme_ipsum_rc(axis_title_size = 12) +
labs(title = "Daily average numbers",
subtitle = "Pinkfeet numbers as a function of barnacle numbers",
caption = "Numbers are average of
3
consecutive seasons",
caption =
glue(
"Numbers are average of
{n_seasons}
consecutive seasons"
)
,
y = "proportion of default numbers") +
facet_grid(~grain_dist)
# Works to down to here
goose_numbers %>%
select(replicate, grain_dist, param, value, season, pinkfoot, barnacle, greylag) %>%
group_by(replicate, grain_dist, param, value, season) %>%
summarise(pinkfoot = sum(pinkfoot, na.rm = TRUE),
barnacle = sum(barnacle, na.rm = TRUE),
greylag = sum(greylag, na.rm = TRUE)) %>%
group_by(grain_dist, param, value, season) %>%
summarise(pinkfoot = mean(pinkfoot, na.rm = TRUE),
barnacle = mean(barnacle, na.rm = TRUE),
greylag = mean(greylag, na.rm = TRUE)) %>%
gather(key = species, value = numbers, -grain_dist, -param, -value, -season) -> numbers_per_season
numbers_per_season %>%
filter(param == "GOOSE_BN_STARTNO_SCALER") %>%
ggplot(aes(value, numbers/1e6)) +
geom_point(alpha = 0.5) +
geom_smooth() +
facet_grid(species ~ grain_dist, scales = "free_y") +
hrbrthemes::theme_ipsum_rc(axis_title_size = 12) +
labs(title = "Goose days as a function of barnacle goose input numbers",
y = expression("Goose days" %*% 1e-6),
x = "Baseline input number scaler") +
scale_x_continuous(breaks = c(2,4,6,8,10))
```
```{r}
default_numbers_file <- glue("{jobs}_scenario-goose-numbers_{date_stamp}.fst")
path_desktop("goose", date_stamp, jobs, default_numbers_file) %>%
fst::read_fst() %>%
as_tibble() %>%
mutate(pinkfoot = pf_families + pf_non_breeders,
greylag = gl_families + gl_non_breeders,
barnacle = bn_families + bn_non_breeders,
day = day - 365L*season) -> goose_numbers
left_join(goose_numbers, grain_dists, by = c("param", "value", "season")) -> goose_numbers
goose_numbers %>%
mutate(day = day - 365L*season) %>%
select(grain_dist, param, value, season, day, pinkfoot, barnacle, greylag) %>%
group_by(grain_dist, param, value, season, day) %>%
summarise_at(.vars = vars(pinkfoot, barnacle, greylag),
.funs = funs(daily = sum)) %>%
group_by(grain_dist, param, value, day) %>%
summarise_at(.vars = vars(ends_with("daily")),
.funs = funs(avg = mean, min, max)) %>%
ungroup() %>%
gather(key = species, value = numbers, -grain_dist, -param, -value, -day) %>%
filter(numbers > 0) -> numbers_per_day
goose_numbers %>%
filter(value == 1) %>%
select(grain_dist, day, pinkfoot, greylag, barnacle) %>%
gather(key = species, value = numbers, -day, -grain_dist) %>%
filter(numbers > 0) %>%
group_by(day, species, grain_dist) %>%
summarise(default_numbers = round(mean(numbers))) -> default_numbers
goose_numbers %>%
select(season, param, value, grain_dist, day, pinkfoot, greylag, barnacle) %>%
gather(key = species, value = numbers, -day, -season, -param, -value, -grain_dist) %>%
filter(numbers > 0) %>%
left_join(default_numbers, by = c("day", "species", "grain_dist")) %>%
mutate(standarized = numbers/default_numbers) -> foo
goose_sp <- "pinkfoot"
goose_sp <- "greylag_daily_avg"
foo %>%
filter(param == "GOOSE_BN_STARTNO_SCALER",
species == goose_sp) %>%
ggplot(aes(day, standarized)) +
geom_line(aes(color = factor(value))) +
scale_color_brewer(palette = "Set3", name = "Barnacle scaler") +
hrbrthemes::theme_ipsum_rc(axis_title_size = 12) +
labs(title = "Daily average numbers",
subtitle = "Pinkfeet numbers as a function of barnacle numbers",
caption = "Numbers are average of 3 consecutive seasons",
y = "proportion of default numbers") +
facet_grid(~grain_dist)
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment