Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ RoxygenNote: 7.3.3
Suggests:
knitr,
rmarkdown,
testthat,
vdiffr
testthat
Imports:
circlize,
curl,
Expand All @@ -30,7 +29,6 @@ Imports:
grid,
gridExtra,
lazyeval,
magrittr,
proj4,
purrr,
RColorBrewer,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ export(scan_prm)
export(str_split_twice)
export(theme_atlantis)
export(write_diet)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
2 changes: 1 addition & 1 deletion R/calculate-consumed-biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ calculate_consumed_biomass <- function(eat, grazing, dm, vol, bio_conv) {
atoutput = atoutput * bio_conv
) |>
# Step2: Combine with diet contribution. We need a full join to make sure no data is lost!
dplyr::full_join(dm, by = c("species" = "pred", "time", "agecl")) %>%
dplyr::full_join(dm, by = c("species" = "pred", "time", "agecl")) |>
# Restrict timesteps to netcdf data! Last timestep is weird in Dietcheck.txt.
dplyr::filter(time %in% ts_eat) |>
dplyr::rename(pred = species)
Expand Down
2 changes: 1 addition & 1 deletion R/calculate-spatial-overlap.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ schoener <- function(predgrp, ageclass, biomass, avail) {
df_avail,
df_pred,
by = c("pred" = "species", "pred_stanza" = "species_stanza")
) %>%
) |>
dplyr::inner_join(
biomass_clean,
by = c(
Expand Down
9 changes: 0 additions & 9 deletions R/check-growth.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ check_growth <- function(data, yearly = FALSE) {
df
}

# Divide output with initial value!
# ref <- data[data$time == min(data$time), ]
# ref$time <- NULL
# names(ref)[names(ref) == "atoutput"] <- "atoutput_ref"
# result <- data %>%
# dplyr::left_join(ref) %>%
# dplyr::mutate(atoutput = atoutput / atoutput_ref)
# result$atoutput[result$atoutput_ref == 0] <- 0
# outcomment in case lm procedure is used! This is a bit messy.
result <- data

# Split dataframe into species and age specific subdataframes!
Expand Down
4 changes: 2 additions & 2 deletions R/combine-ages.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ combine_ages <- function(data, grp_col, agemat, value_col = "atoutput") {
data_stanza$stanza <- ifelse(data_stanza$agecl < data_stanza$age_mat, 1, 2)
data_stanza$stanza[is.na(data_stanza$stanza)] <- 1 # Not sure if this is correct!

result <- data_stanza %>%
result <- data_stanza |>
agg_data(
col = value_col,
groups = names(.)[!names(.) %in% c(value_col, "agecl")],
groups = setdiff(colnames(data_stanza), c(value_col, "agecl")),
out = value_col,
fun = sum
)
Expand Down
6 changes: 3 additions & 3 deletions R/combine-groups.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ combine_groups <- function(
# Arrange by group_col and group by groups to select the 1:combinthethresh
# group in group_col for each grouping combination.
if (length(groups) > 0) {
comb_grps <- comb_grps %>%
as.data.frame() %>%
comb_grps <- comb_grps |>
as.data.frame() |>
group_data(groups = groups)
}
imp_species <- comb_grps |>
Expand All @@ -47,7 +47,7 @@ combine_groups <- function(
# Only combine groups if necessary!
low_contrib[, group_col] <- "Rest"

new_data <- dplyr::inner_join(data, imp_species) %>%
new_data <- dplyr::inner_join(data, imp_species) |>
rbind(low_contrib)

# This should never happen...
Expand Down
4 changes: 2 additions & 2 deletions R/load-init-age.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ load_init_weight <- function(init, fgs, bboxes) {
fgs = fgs,
select_variable = "ResN",
bboxes = bboxes
) %>%
) |>
dplyr::filter(!is.na(atoutput)) |>
dplyr::select(atoutput, species, agecl) |>
dplyr::rename(rn = atoutput) |>
Expand All @@ -247,7 +247,7 @@ load_init_weight <- function(init, fgs, bboxes) {
fgs = fgs,
select_variable = "StructN",
bboxes = bboxes
) %>%
) |>
dplyr::filter(!is.na(atoutput)) |>
dplyr::select(atoutput, species, agecl) |>
dplyr::rename(sn = atoutput) |>
Expand Down
9 changes: 4 additions & 5 deletions R/load-mort.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ load_mort <- function(mortFile, prm_run, fgs, convert_names = F) {
mort <- load_txt(file = mortFile, id_col = c("Time"))

# separate species code.mortalityType into two columns
mort <- mort %>%
tidyr::separate(.data$code, into = c("code", "source"), sep = "\\.") %>%
mort <- mort |>
tidyr::separate(.data$code, into = c("code", "source"), sep = "\\.") |>
tibble::as_tibble()

# First time step only has 0s as entry!
Expand All @@ -43,12 +43,11 @@ load_mort <- function(mortFile, prm_run, fgs, convert_names = F) {
# Convert species codes to longnames!
if (convert_names) {
data_fgs <- load_fgs(fgs = fgs)
mort <- mort %>%
mort <- mort |>
dplyr::left_join(
.,
data_fgs[, c("Code", "LongName")],
by = c("code" = "Code")
) %>%
) |>
dplyr::rename(species = .data$LongName)
}

Expand Down
7 changes: 3 additions & 4 deletions R/load-spec-mort.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ load_spec_mort <- function(
df_txt = df,
into = c("code", "agecl", "empty_col", "mort"),
removeZeros = removeZeros
) %>%
) |>
tibble::as_tibble()

# Convert species codes to longnames!
if (convert_names) {
data_fgs <- load_fgs(fgs = fgs)
mort <- mort %>%
mort <- mort |>
dplyr::left_join(
.,
data_fgs[, c("Code", "LongName")],
by = c("code" = "Code")
) %>%
) |>
dplyr::rename(species = .data$LongName)
}

Expand Down
2 changes: 1 addition & 1 deletion R/plot-spatial-box.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ plot_spatial_box <- function(
}

# Step2: Apply predator and stanza specific plot function
dfs_spatial <- select_time(perc_bio, timesteps = timesteps) %>%
dfs_spatial <- select_time(perc_bio, timesteps = timesteps) |>
split_dfs(cols = c("species", "species_stanza"))
plots_spatial <- lapply(
dfs_spatial,
Expand Down
8 changes: 4 additions & 4 deletions R/sc-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ sc_init <- function(

# Comment in to extract numbers from output!
# nums <- load_nc(dir = dir, nc = nc, bps = bps, select_variable = "Nums",
# fgs = fgs, select_groups = groups_age, bboxes = bboxes) %>%
# fgs = fgs, select_groups = groups_age, bboxes = bboxes) |>
# dplyr::filter(time == 0)
nums <- load_init_age(
init = init,
fgs = fgs,
select_variable = "Nums",
bboxes = bboxes
) %>%
) |>
dplyr::inner_join(surface, by = c("polygon", "layer")) # not needed in case numbers are already only in surface in init file

# Add stanzas for all age-based groups!
Expand Down Expand Up @@ -211,7 +211,7 @@ sc_init <- function(

# Comment in to get data from output file
# preydens_invert <- load_nc(dir = dir, nc = nc, bps = bps, fgs = fgs, select_groups = groups_rest,
# select_variable = "N", bboxes = bboxes) %>%
# select_variable = "N", bboxes = bboxes) |>
# dplyr::filter(time == 0)
preydens_invert <- load_init_nonage(
init = init,
Expand Down Expand Up @@ -239,7 +239,7 @@ sc_init <- function(
dplyr::rename(prey = species, preydens = atoutput)

# Extract availability matrix and combine with assimilation types
ass_type <- fgs_data %>%
ass_type <- fgs_data |>
dplyr::select(Code, dplyr::any_of(c("GroupType", "InvertType")))

names(ass_type) <- c("prey", "grp")
Expand Down
File renamed without changes.
11 changes: 0 additions & 11 deletions man/pipe.Rd

This file was deleted.

4 changes: 2 additions & 2 deletions tests/testthat/test-combine-groups.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
context("combine_groups tests")

wuwu <- combine_groups(ref_dm, group_col = "pred", combine_thresh = 2)
wawa <- wuwu %>%
dplyr::group_by(prey, agecl) %>%
wawa <- wuwu |>
dplyr::group_by(prey, agecl) |>
dplyr::summarise(count = dplyr::n_distinct(pred))

# no grouping variable!
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-load-init-age.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ dl <- load_init_stanza(init = init, fgs = fgs, bboxes = bboxes)

dm <- load_init_weight(init = init, fgs = fgs, bboxes = bboxes)

data <- de %>%
dplyr::filter(!is.na(atoutput)) %>%
dplyr::group_by(species, agecl) %>%
data <- de |>
dplyr::filter(!is.na(atoutput)) |>
dplyr::group_by(species, agecl) |>
dplyr::summarise(out = unique(atoutput))

test_that("test output numbers", {
Expand Down
24 changes: 12 additions & 12 deletions vignettes/model-calibration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ to the list of dataframes at the end of the preprocess vignette and change `mode
library("atlantistools")
library("ggplot2")
library("gridExtra")
library("magrittr")

fig_height2 <- 11
gen_labels <- list(x = "Time [years]", y = "Biomass [t]")
Expand Down Expand Up @@ -112,7 +111,7 @@ update_labels(plot, gen_labels)

## Biomass benchmark 2
```{r}
plot <- plot_line(result$biomass) %>% update_labels(labels = gen_labels)
plot <- plot_line(result$biomass) |> update_labels(labels = gen_labels)
plot_add_range(plot, ex_bio)
```

Expand All @@ -127,12 +126,13 @@ custom_grid(plot, grid_x = "polygon", grid_y = "variable")

# Physics
```{r, results = 'asis', fig.width = 30, fig.height = 12}
physics <- result$physics %>%
flip_layers() %>%
split(., .$variable)
physics <- result$physics |>
flip_layers() |>
dplyr::group_split(variable)

plots <- lapply(physics, plot_line, wrap = NULL) %>%
lapply(., custom_grid, grid_x = "polygon", grid_y = "layer")
plots <- physics |>
lapply(plot_line, wrap = NULL) |>
lapply(custom_grid, grid_x = "polygon", grid_y = "layer")

for (i in seq_along(plots)) {
cat(paste0("## ", names(plots)[i]), sep = "\n")
Expand All @@ -145,24 +145,24 @@ for (i in seq_along(plots)) {

## Fluxes 1
```{r, fig.width = 30, fig.height = 12}
plot <- flip_layers(result$flux) %>%
plot <- flip_layers(result$flux) |>
plot_line(wrap = NULL, col = "variable")
custom_grid(plot, grid_x = "polygon", grid_y = "layer")
```


## Fluxes 2
```{r, fig.width = 30, fig.height = 12}
plot <- flip_layers(result$sink) %>%
plot <- flip_layers(result$sink) |>
plot_line(wrap = NULL, col = "variable")
custom_grid(plot, grid_x = "polygon", grid_y = "layer")
```

## Relative change of water column height compared to nominal_dz
```{r}
check_dz <- result$dz %>%
dplyr::left_join(result$nominal_dz, by = c("polygon", "layer")) %>%
dplyr::mutate(check_dz = atoutput.x / atoutput.y) %>%
check_dz <- result$dz |>
dplyr::left_join(result$nominal_dz, by = c("polygon", "layer")) |>
dplyr::mutate(check_dz = atoutput.x / atoutput.y) |>
dplyr::filter(!is.na(check_dz)) # remove sediment layer

plot <- plot_line(check_dz, x = "time", y = "check_dz", wrap = "polygon", col = "layer")
Expand Down
4 changes: 2 additions & 2 deletions vignettes/model-comparison.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ to the list of dataframes at the end of the preprocess vignette and change `mode
library("atlantistools")
library("ggplot2")
library("gridExtra")
library("magrittr")

gen_labels <- list(x = "Time [years]", y = "Biomass [t]")

# You should be able to build the vignette either by clicking on "Knit PDF" in RStudio or with
Expand Down Expand Up @@ -61,7 +61,7 @@ update_labels(plot, gen_labels)

# Biomass timeseries
```{r}
plot_line(result$biomass, col = "run", ncol = 4) %>% update_labels(gen_labels)
plot_line(result$biomass, col = "run", ncol = 4) |> update_labels(gen_labels)
```


Expand Down
Loading
Loading