Skip to content

Commit

Permalink
Merge pull request #24 from pfmc-assessments/style-doc-code
Browse files Browse the repository at this point in the history
Style code and document
  • Loading branch information
chantelwetzel-noaa authored Nov 18, 2024
2 parents a004866 + 611dfe3 commit 5fb3b8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
20 changes: 7 additions & 13 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ Package: nwfscDiscard
Title: Northwest Fisheries Science Center
Version: 2.0
Date: 2018-04-13
Authors@R: c(
person(
given = c("Chantel", "R."),
family = "Wetzel", ,
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7573-8240")
)
)
Description: Northwest Fisheries Science Center WCGOP data processing for use in
West Coast groundfish assessments. All scripts to process the available data are
publicly available but the data are stored in a private location to maintain
confidentiality.
Authors@R:
person(c("Chantel", "R."), "Wetzel", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7573-8240"))
Description: Northwest Fisheries Science Center WCGOP data processing for
use in West Coast groundfish assessments. All scripts to process the
available data are publicly available but the data are stored in a
private location to maintain confidentiality.
License: GPL (>=3)
Depends:
R (>= 4.2)
Expand Down
3 changes: 2 additions & 1 deletion R/bootstrap_discard.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ boostrap_discard <- function(
all_boot_data <- dplyr::left_join(
y = boot_out,
x = cf_data,
by = c("fleet", "year")) |>
by = c("fleet", "year")
) |>
dplyr::filter(n_vessels >= 3) |>
data.frame()

Expand Down
32 changes: 18 additions & 14 deletions R/calc_comps.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ calc_comps <- function(
dplyr::ungroup() |>
dplyr::filter(n_by_year != 0) |>
dplyr::mutate(
prop_numbers = 100 * n/n_by_year,
prop_numbers = 100 * n / n_by_year,
prop_weighted = 100 * weighted / w_by_year
)

Expand All @@ -62,7 +62,7 @@ calc_comps <- function(

comps_out_sexed <- comps_out_unsexed <- all_comps <- NULL
out <- list()
if (any(comps[,"sex"] == "U")) {
if (any(comps[, "sex"] == "U")) {
sub <- comps[comps$sex == "U", ]
keep <- which(apply(sub[, 6:ncol(sub)], 1, sum) != 0)
filter_comps <- sub[keep, ]
Expand All @@ -77,7 +77,8 @@ calc_comps <- function(
vessels = length(unique(drvid)),
ratio = fish / trips,
nsamp = round(dplyr::case_when(
ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls
ratio < 44 ~ trips + 0.138 * fish,
.default = 7.06 * hauls
), 0),
fleet = paste0(unique(gear_groups), "-", unique(fleet_groups))
) |>
Expand Down Expand Up @@ -108,15 +109,17 @@ calc_comps <- function(
vessels = length(unique(drvid)),
ratio = fish / trips,
nsamp = round(dplyr::case_when(
ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls
ratio < 44 ~ trips + 0.138 * fish,
.default = 7.06 * hauls
), 0),
fleet = paste0(unique(gear_groups), "-", unique(fleet_groups))
) |>
data.frame()

comps_sexed <- cbind(
comps_sexed <- cbind(
comps[comps$sex == "F", 6:ncol(comps)],
comps[comps$sex == "M", 6:ncol(comps)])
comps[comps$sex == "M", 6:ncol(comps)]
)
remove <- which(apply(comps_sexed, 1, sum) == 0)
filter_comps <- comps_sexed[-remove, ]

Expand All @@ -134,7 +137,7 @@ calc_comps <- function(
}

if (comp_column == "age") {
if (!is.null(comps_out_unsexed)){
if (!is.null(comps_out_unsexed)) {
comps_out_unsexed <- cbind(
comps_out_unsexed[, 1:5],
"age_error",
Expand All @@ -147,7 +150,7 @@ calc_comps <- function(
colnames(comps_out_unsexed)[6:9] <- c("age_error", "age_low", "age_high", "input_n")
out$unsexed <- comps_out_unsexed
}
if (!is.null(comps_out_sexed)){
if (!is.null(comps_out_sexed)) {
comps_out_sexed <- cbind(
comps_out_sexed[, 1:5],
"age_error",
Expand All @@ -171,24 +174,25 @@ calc_comps <- function(
vessels = length(unique(drvid)),
ratio = fish / trips,
nsamp = round(dplyr::case_when(
ratio < 44 ~ trips + 0.138 * fish, .default = 7.06 * hauls
ratio < 44 ~ trips + 0.138 * fish,
.default = 7.06 * hauls
), 0)
) |>
dplyr::select(-ratio) |>
data.frame()

if (!is.null(dir)) {
if (dim(sample_size)[1] > 0 ) {
if (dim(sample_size)[1] > 0) {
write.csv(sample_size,
file = file.path(dir, paste0("biological_sample_sizes_", comp_column, ".csv")),
row.names = FALSE
file = file.path(dir, paste0("biological_sample_sizes_", comp_column, ".csv")),
row.names = FALSE
)
}

if (!is.null(all_comps)) {
write.csv(all_comps,
file = file.path(dir, paste0("biological_discard_", comp_column, "s.csv")),
row.names = FALSE
file = file.path(dir, paste0("biological_discard_", comp_column, "s.csv")),
row.names = FALSE
)
}
}
Expand Down
9 changes: 6 additions & 3 deletions R/get_biological_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ get_biological_data <- function(
dplyr::mutate(
exp1 = dplyr::case_when(
!is.na(species_number) | !is.na(bio_specimen_count) ~ species_number / bio_specimen_count,
.default = 0),
.default = 0
),
exp_weight = dplyr::case_when(
is.na(exp_sp_wt) ~ (species_weight / hooks_sampled) * total_hooks,
.default = exp_sp_wt),
.default = exp_sp_wt
),
exp2 = dplyr::case_when(
!is.na(species_weight) ~ exp_weight / species_weight,
.default = 0),
.default = 0
),
wghtd_freq = frequency * exp1 * exp2
)

Expand Down
5 changes: 2 additions & 3 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ run <- function(
biological_data,
em_catch_data = NULL,
save_loc = NULL,
n_boot = 10000
) {
if(!is.null(em_catch_data)) {
n_boot = 10000) {
if (!is.null(em_catch_data)) {
do_em <- TRUE
} else {
do_em <- FALSE
Expand Down

0 comments on commit 5fb3b8b

Please sign in to comment.