Skip to content

Commit

Permalink
fix 2005 landings conversion factor
Browse files Browse the repository at this point in the history
  • Loading branch information
MandyKarnauskas-NOAA committed Oct 6, 2023
1 parent fcbbf91 commit 9672e5c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 128 deletions.
112 changes: 0 additions & 112 deletions indicator_processing/fishery_dependent/.Rhistory

This file was deleted.

84 changes: 69 additions & 15 deletions indicator_processing/fishery_dependent/INDICATOR_total_landings.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ rm(list = ls())

# input data for Puerto Rico ---------------------------
setwd("C:/Users/mandy.karnauskas/Desktop/Caribbean-ESR/indicator_processing/fishery_dependent/")
dat <- read.csv("C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/Jun2022/PR_landings_83_20_wSC.csv")
dat <- read.csv("C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/Jun2022/PR_landings_83_20_wSC_2005cor.csv")

table(dat$YEAR_LANDED)

# check multiplier adjustments -------------------------

dat$xADJ <- dat$POUNDS_LANDED * 1/dat$CORRECTION_FACTOR
hist(dat$ADJUSTED_POUNDS - dat$xADJ)
max(abs(dat$ADJUSTED_POUNDS - dat$xADJ), na.rm = T)
table(round(dat$ADJUSTED_POUNDS) - round(dat$xADJ))
#dat$ADJUSTED_POUNDS <- dat$xADJ
summary(dat$xADJ == dat$POUNDS_LANDED * 1/dat$CORRECTION_FACTOR)

# define start and end years ---------------------------
styear <- 1990
Expand All @@ -35,20 +31,25 @@ sort(table(d$ITIS_COMMON_NAME[grep("LOBSTER", d$ITIS_COMMON_NAME)]))
sort(table(d$ITIS_COMMON_NAME[grep("CONCH", d$ITIS_COMMON_NAME)]))

d$sppgrp <- "other"
#d$sppgrp[grep("LOBSTER", d$ITIS_COMMON_NAME)] <- "lobster"
d$sppgrp[grep("LOBSTERS,SPINY", d$ITIS_COMMON_NAME)] <- "lobster"
d$sppgrp[grep("LOBSTER", d$ITIS_COMMON_NAME)] <- "lobster"
#d$sppgrp[grep("LOBSTERS,SPINY", d$ITIS_COMMON_NAME)] <- "lobster" # to compare directly to only spiny lobster
d$sppgrp[grep("CONCH", d$ITIS_COMMON_NAME)] <- "conch"

table(d$ITIS_COMMON_NAME, d$sppgrp)

# check for rule of 3 ------------------------

table(d$sppgrp, d$YEAR_LANDED)
table(table(d$sppgrp, d$YEAR_LANDED) < 3)

# sum landings by year ----------------------

totland_pr <- tapply(d$ADJUSTED_POUNDS, list(d$YEAR_LANDED, d$sppgrp), sum, na.rm = T) / 10^3
dim(totland_pr)
totland_pr
matplot(totland_pr, type = "l", lty = 1, lwd = 2)
matplot(1990:2020, totland_pr, type = "l", lty = 1, lwd = 2)

ls()
rm(list = ls()[-match(c("totland_pr", "styear", "enyear"), ls())])

# calculate for STT --------------------------------------

Expand Down Expand Up @@ -76,36 +77,89 @@ d$sppgrp[grep("CONCH", d$SPECIES_NM)] <- "conch"

table(d$SPECIES_NM, d$sppgrp)

# check for rule of 3 ------------------------

table(d$TRIP_YEAR, d$sppgrp)
table(table(d$TRIP_YEAR, d$sppgrp) <= 3)

# sum landings by year ----------------------

totland_st <- tapply(d$POUNDS_LANDED, list(d$TRIP_YEAR, d$sppgrp), sum, na.rm = T) / 10^3
totland_st[3, 1] <- NA # fix confidentiality issue
dim(totland_st)
totland_st
totland_st[is.na(totland_st)] <- 0
matplot(totland_st, type = "l")

# calculate for STX --------------------------------------

rm(list = ls()[-match(c("totland_st", "totland_pr", "styear", "enyear"), ls())])

dat <- read.csv("C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/STX_072011_present_LANDINGS_trip_2021-03-11.csv")
head(dat)

# take a look at data fields ----------------------------

table(dat$LANDING_AREA_NAME)
table(dat$TRIP_YEAR)
d <- dat[which(dat$TRIP_YEAR >= styear & dat$TRIP_YEAR <= enyear), ]
d$TRIP_YEAR <- factor(d$TRIP_YEAR, levels = c(styear: enyear))
table(d$TRIP_YEAR)

# check field codes -----------------

table(d$TRIP_YEAR, useNA = "always")

# look at top landings -----------------------

sort(tapply(d$POUNDS_LANDED, d$SPECIES_NM, sum, na.rm = T))
sort(table(d$SPECIES_NM[grep("LOBSTER", d$SPECIES_NM)]))
sort(table(d$SPECIES_NM[grep("CONCH", d$SPECIES_NM)]))

d$sppgrp <- "other"
d$sppgrp[grep("LOBSTER", d$SPECIES_NM)] <- "lobster"
d$sppgrp[grep("CONCH", d$SPECIES_NM)] <- "conch"

table(d$SPECIES_NM, d$sppgrp)

# check for rule of 3 ------------------------

table(d$TRIP_YEAR, d$sppgrp)
table(table(d$TRIP_YEAR, d$sppgrp) <= 3)

# sum landings by year ----------------------

totland_sx <- tapply(d$POUNDS_LANDED, list(d$TRIP_YEAR, d$sppgrp), sum, na.rm = T) / 10^3
dim(totland_sx)
totland_sx
#totland_sx[is.na(totland_sx)] <- 0
matplot(totland_sx, type = "l")

# summarize and plot ---------------------

ls()[grep("totland", ls())]

datdata <- styear:enyear
inddata <- data.frame(cbind(totland_pr[, 2], totland_st[, 2],
totland_pr[, 1], totland_st[, 1],
totland_pr[, 3], totland_st[, 3]))
inddata <- data.frame(cbind(totland_pr[, 2], totland_st[, 2], totland_sx[, 2],
totland_pr[, 1], totland_st[, 1], totland_sx[, 1],
totland_pr[, 3], totland_st[, 3], totland_sx[, 3]))
labs <- c("Lobster landings", "thousands of pounds", "Puerto Rico",
"Lobster landings", "thousands of pounds", "St. Thomas and St. John",
"Lobster landings", "thousands of pounds", "St. Croix",
"Conch landings", "thousands of pounds", "Puerto Rico",
"Conch landings", "thousands of pounds", "St. Thomas and St. John",
"Conch landings", "thousands of pounds", "St. Croix",
"Landings of all other species", "thousands of pounds", "Puerto Rico",
"Landings of all other species", "thousands of pounds", "St. Thomas and St. John")
"Landings of all other species", "thousands of pounds", "St. Thomas and St. John",
"Landings of all other species", "thousands of pounds", "St. Croix")

indnames <- data.frame(matrix(labs, nrow = 3, byrow = F))
s <- list(labels = indnames, indicators = inddata, datelist = datdata) #, ulim = ulidata, llim = llidata)
class(s) <- "indicatordata"

setwd("C:/Users/mandy.karnauskas/Desktop/Caribbean-ESR/indicator_plots/")

plotIndicatorTimeSeries(s, coltoplot = 1:6, plotrownum = 2, sublabel = T, sameYscale = F,
plotIndicatorTimeSeries(s, coltoplot = 1:9, plotrownum = 3, plotcolnum = 3, sublabel = T, sameYscale = F,
widadj = 0.8, hgtadj = 0.7, trendAnalysis = F) # outtype = "png")

#inddata <- s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,76 @@ dim(dat2)
#write.table(dat2, file = "C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/Jun2022/PR_landings_83_20_wSC.csv",
# sep = ",", col.names = T, row.names = F)

d <- dat2
# fix error with 2005 correction factor ----------------

rm(list = ls())
dat <- read.csv("C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/Jun2022/PR_landings_83_20_wSC.csv")

table(dat$YEAR_LANDED)

# check multiplier adjustments -------------------------

dat$xADJ <- dat$POUNDS_LANDED * 1/dat$CORRECTION_FACTOR
hist(dat$ADJUSTED_POUNDS - dat$xADJ)
max(abs(dat$ADJUSTED_POUNDS - dat$xADJ), na.rm = T)
table(round(dat$ADJUSTED_POUNDS) - round(dat$xADJ))
#dat$ADJUSTED_POUNDS <- dat$xADJ

# fix 2005 correction factor ---------------------------

d5 <- dat[which(dat$YEAR_LANDED == 2005), ]
table(d5$CORRECTION_FACTOR, d5$MUNICIPALITY)
plot(d5$CORRECTION_FACTOR ~ d5$MUNICIPALITY)
tapply(d5$CORRECTION_FACTOR, d5$MUNICIPALITY, sd)

d4 <- dat[which(dat$YEAR_LANDED == 2004), ]
d6 <- dat[which(dat$YEAR_LANDED == 2006), ]

tapply(d4$CORRECTION_FACTOR, d4$MUNICIPALITY, sd, na.rm = T)
tapply(d6$CORRECTION_FACTOR, d6$MUNICIPALITY, sd, na.rm = T)

c4 <- tapply(d4$CORRECTION_FACTOR, d4$MUNICIPALITY, mean, na.rm = T)
c6 <- tapply(d6$CORRECTION_FACTOR, d6$MUNICIPALITY, mean, na.rm = T)
summary(names(c4) == names(c6))

c5 <- (c4 + c6) / 2
c5[10]
c6[10]
table(c4)
table(c6)
table(c5)

table(d5$CORRECTION_FACTOR)
lis265 <- names(which(c5 == 0.265))
lis465 <- names(which(c5 == 0.465))
lis475 <- names(which(c5 == 0.475))
lis835 <- names(which(c5 == 0.835))

dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005 & dat$MUNICIPALITY %in% lis265)] <- 0.265
dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005 & dat$MUNICIPALITY %in% lis465)] <- 0.465
dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005 & dat$MUNICIPALITY %in% lis475)] <- 0.475
dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005 & dat$MUNICIPALITY %in% lis835)] <- 0.835

table(dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005)])
dat[which(dat$CORRECTION_FACTOR > 0.9 & dat$YEAR_LANDED == 2005), ]
c6[10]
dat$CORRECTION_FACTOR[which(dat$CORRECTION_FACTOR > 0.9 & dat$YEAR_LANDED == 2005)] <- c6[10]
table(dat$CORRECTION_FACTOR[which(dat$YEAR_LANDED == 2005)])


# check
dat$xADJ <- dat$POUNDS_LANDED * 1/dat$CORRECTION_FACTOR
hist(dat$ADJUSTED_POUNDS - dat$xADJ)
max(abs(dat$ADJUSTED_POUNDS - dat$xADJ), na.rm = T)
table(round(dat$ADJUSTED_POUNDS) - round(dat$xADJ))
dat$ADJUSTED_POUNDS <- dat$xADJ

#write.table(dat, file = "C:/Users/mandy.karnauskas/Desktop/CONFIDENTIAL/CaribbeanData/Jun2022/PR_landings_83_20_wSC_2005cor.csv",
# sep = ",", col.names = T, row.names = F)

#################################################################

d <- dat

# take a look at data fields ----------------------------
table(d$VESSEL, useNA = "always")
Expand Down

0 comments on commit 9672e5c

Please sign in to comment.