-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
491b7a7
commit e0470a7
Showing
10 changed files
with
231 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#' Clean Lat and Lon | ||
#' | ||
#' Clean latitude and longitude data across the dateline | ||
#' @param x Pot or observer data with columns longitude, latitude, and eastwest | ||
#' @return x with location information correctect across the date line to be negative | ||
#' @examples | ||
#' clean_lat_lon(pots) | ||
#' @export | ||
clean_lat_lon <- function(x) { | ||
|
||
x %>% | ||
mutate(longitude = ifelse(longitude > 0, longitude * -1, longitude), | ||
longitude = ifelse(longitude == -9, NA, longitude), | ||
longitude = ifelse(eastwest == "E", (-180 - longitude) + -180, longitude)) -> out | ||
|
||
return(out) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' Get Directed Discards | ||
#' | ||
#' Estimate directed fishery discards by sex using subtraction method | ||
|
||
#' @param retained_catch NULL. Output of `get_retaied_catch()`. | ||
#' @param total_catch NULL. Output of `get_total_catch()`. 'by' argument could be anything as long as group or sex is included. | ||
#' @param stock NULL. Character string stock abbreviation: BSSC, WBT, EBT, BBRKC, EAG, WAG, PIGKC, SMBKC, PIBKC, PIRKC, WAIRKC. | ||
#' @return Data frame including crab year, fishery, sex, discards, and discard mortality. | ||
#' @examples get_discards(retained_catch, total_catch, stock = "BBRKC", handling_mortality = 0.3) | ||
#' | ||
#' @export | ||
#' | ||
get_discards <- function(retained_catch, total_catch, stock, handling_mortality = 0.3) { | ||
|
||
# directed fishery codes | ||
tibble(stock_abbrev = c("BSSC", "WBT", "EBT", "BBRKC", "EAG", "WAG", "PIGKC", "SMBKC", "PIBKC", "PIRKC", "WAIRKC"), | ||
fish_code = c("QO", "QT", "TT", "TR", "OB", "RB", "QB", "QP", "QP", "QR", "RR")) %>% | ||
filter(stock_abbrev == stock) %>% | ||
pull(fish_code) -> fish_code | ||
|
||
# summarise total catch | ||
if("group" %in% names(total_catch)){ | ||
total_catch %>% | ||
# add sex | ||
mutate(sex = case_when(group == "female" ~ 2, | ||
group == "sublegal_male"~ 1, | ||
group == "legal_male"~ 1)) -> total_catch | ||
} | ||
|
||
if(sum(grepl("group|sex", names(total_catch))) == 0){ | ||
stop("Total catch must be by 'group', 'sex', or both !!") | ||
} | ||
|
||
total_catch %>% | ||
# filter for the directd fishery | ||
filter(substring(fishery, 1, 2) == fish_code) %>% | ||
group_by(crab_year, fishery, sex) %>% | ||
summarise(total_catch_n = sum(total_catch_n, na.rm = T), | ||
total_catch_wt = sum(total_catch_wt, na.rm = T)) %>% ungroup %>% | ||
# join to retained catch | ||
full_join(retained_catch %>% | ||
mutate(sex = 1), by = c("crab_year", "fishery", "sex")) %>% | ||
mutate(retained_n = ifelse(sex == 2, 0, retained_n), | ||
retained_wt = ifelse(sex == 2, 0, retained_wt)) %>% | ||
# add discards | ||
mutate(discard_n = total_catch_n - retained_n, | ||
discard_wt = total_catch_wt - retained_wt, | ||
discard_mortality_n = discard_n * handling_mortality + retained_n, | ||
discard_mortality_wt = discard_wt * handling_mortality + retained_wt) -> out | ||
|
||
return(out) | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.