Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description of use of split among pings #13

Open
neilcampbelll opened this issue Sep 27, 2023 · 3 comments
Open

Description of use of split among pings #13

neilcampbelll opened this issue Sep 27, 2023 · 3 comments
Labels
Discussion Needed Points which require discussion and decisions documentation Improvements or additions to documentation High Priority Urgent things needing attention at the next hackathon Workflow Block 2 Data analysis workflow code

Comments

@neilcampbelll
Copy link
Contributor

The use of "splitamongpings" is not well documented in the workflow. This could be improved by requiring some sort of flagging.

@neilcampbelll neilcampbelll added documentation Improvements or additions to documentation Workflow Block 2 Data analysis workflow code Discussion Needed Points which require discussion and decisions High Priority Urgent things needing attention at the next hackathon labels Oct 23, 2023
@neilcampbelll
Copy link
Contributor Author

Polyvalent gears, or multiple target assemblages (e.g. DWS and DEF). How should catch or effort be split in these cases.

@neilcampbelll
Copy link
Contributor Author

Create a table from the script to count how many multi-gear or multi-metier trips exist, document what has been done with them.

@jepol77
Copy link
Contributor

jepol77 commented Feb 1, 2024

Here is a method for splitting metier/gear/mesh-size/ices retangle/gear width into the tacsatp file:

trip_assign <- function(tacsatp, eflalo, col = "LE_GEAR", trust_logbook = T){

if(col == "LE_MET"){
tst <- data.table(eflalo)[get(col) %in% valid_metiers & !is.na(get(col)) ,.(uniqueN(get(col))), by=.(FT_REF)]
}else{
tst <- data.table(eflalo)[!is.na(get(col)),.(uniqueN(get(col))), by=.(FT_REF)]
}
if(nrow(tst[V1>1])==0){
warning(paste("No duplicate", col, "in tacsatp"))
return(data.frame())
}

e <- data.table(eflalo)[FT_REF %in% tst[V1>1]$FT_REF]
tz <- data.table(tacsatp)[FT_REF %in% tst[V1>1]$FT_REF]
suppressWarnings(tz[, (col) := NULL])
if(trust_logbook){
First bind by landing date
e2 <- e[,.(get(col)[length(unique(get(col))) == 1]), by = .(FT_REF, LE_CDAT)]
names(e2) <- c("FT_REF", "LE_CDAT", col)
tz <- tz |>
left_join(e2, by = c("FT_REF" = "FT_REF", "SI_DATE" = "LE_CDAT"), relationship = "many-to-many")
tz <- unique(tz)
If some are still missing, use haul information to get the closest time
if(nrow(tz[is.na(get(col))]) > 0){
#set formats right
e$FT_DDATIM <- as.POSIXct(paste(e$FT_DDAT, e$FT_DTIME,
sep = " "), tz = "GMT", format = "%d/%m/%Y %H:%M")
e$FT_LDATIM <- as.POSIXct(paste(e$FT_LDAT, e$FT_LTIME,
sep = " "), tz = "GMT", format = "%d/%m/%Y %H:%M")
e$LE_SDATTIM <- as.POSIXct(paste(e$LE_SDAT, e$LE_STIME,
sep = " "), tz = "GMT", format = "%d/%m/%Y %H:%M")
e$LE_EDATTIM <- as.POSIXct(paste(e$LE_EDAT, e$LE_ETIME,
sep = " "), tz = "GMT", format = "%d/%m/%Y %H:%M")
tx <- tz[is.na(get(col))]
tx[, (col) := NULL]
mx <- rbind(e[,.(meantime = LE_SDATTIM), by = .(get(col))], e[,.(meantime = LE_EDATTIM), by = .(get(col))])
names(mx) <- c(col, "meantime")
tx[, time := SI_DATIM]
setkey(tx, time)
setkey(mx, meantime)
tx <- mx[tx, roll="nearest"]
tx$meantime <- NULL
tz <- rbindlist(list(tz[!is.na(get(col))], tx), fill = T)
}
}else{
tz[, (col) := NA]
}
Bind to the category with most value
if(nrow(tz[is.na(get(col))]) > 0){
if(!"LE_KG_TOT" %in% names(e)){
idxkgeur <- colnames(e)[grepl("LE_KG_|LE_EURO_", colnames(e))]
# Calculate the total KG and EURO for each row
e$LE_KG_TOT <- rowSums(e[,..idxkgeur], na.rm = TRUE)
}
highvalue <- e[,.(LE_KG_TOT = sum(LE_KG_TOT, na.rm = T)), by = .(FT_REF, get(col))]
highvalue <- highvalue[,.(get[which.max(LE_KG_TOT)]), by = .(FT_REF)]
names(highvalue) <- c("FT_REF", col)
tx <- tz[is.na(get(col))]
tx[, (col) := NULL]
tz <- merge(tx, highvalue)
}
return(tz)
}

tacsatpa_LE_GEAR <- trip_assign(tacsatp, eflalo, col = "LE_GEAR", trust_logbook = T)
tacsatp <- rbindlist(list(tacsatp[tacsatp$FT_REF %!in% tacsatpa_LE_GEAR$FT_REF,], tacsatpa_LE_GEAR), fill = T)

tacsatpa_LE_MSZ <- trip_assign(tacsatp, eflalo, col = "LE_MSZ", trust_logbook = T)
tacsatp <- rbindlist(list(tacsatp[tacsatp$FT_REF %!in% tacsatpa_LE_MSZ$FT_REF,], tacsatpa_LE_MSZ), fill = T)

tacsatpa_LE_RECT <- trip_assign(tacsatp, eflalo, col = "LE_RECT", trust_logbook = T)
tacsatp <- rbindlist(list(tacsatp[tacsatp$FT_REF %!in% tacsatpa_LE_RECT$FT_REF,], tacsatpa_LE_RECT), fill = T)

tacsatpa_LE_MET <- trip_assign(tacsatp, eflalo, col = "LE_MET", trust_logbook = T)
tacsatp <- rbindlist(list(tacsatp[tacsatp$FT_REF %!in% tacsatpa_LE_MET$FT_REF,], tacsatpa_LE_MET), fill = T)

if("LE_WIDTH" %in% names(eflalo)){
tacsatpa_LE_WIDTH <- trip_assign(tacsatp, eflalo, col = "LE_WIDTH", trust_logbook = T)
tacsatp <- rbindlist(list(tacsatp[tacsatp$FT_REF %!in% tacsatpa_LE_WIDTH$FT_REF,], tacsatpa_LE_WIDTH), fill = T)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Needed Points which require discussion and decisions documentation Improvements or additions to documentation High Priority Urgent things needing attention at the next hackathon Workflow Block 2 Data analysis workflow code
Projects
None yet
Development

No branches or pull requests

2 participants