Open neilcampbelll opened 1 year ago
Polyvalent gears, or multiple target assemblages (e.g. DWS and DEF). How should catch or effort be split in these cases.
Create a table from the script to count how many multi-gear or multi-metier trips exist, document what has been done with them.
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){
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("LEKG|LEEURO", colnames(e))]
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) }
The use of "splitamongpings" is not well documented in the workflow. This could be improved by requiring some sort of flagging.