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

Add depth for the U.S. shoreside fleet to figure set #1037

Open
kellijohnson-NOAA opened this issue Feb 7, 2023 · 2 comments
Open

Add depth for the U.S. shoreside fleet to figure set #1037

kellijohnson-NOAA opened this issue Feb 7, 2023 · 2 comments
Assignees
Labels
topic: data Data used to fit the stock assessment topic: R code type: enhancement

Comments

@kellijohnson-NOAA
Copy link
Collaborator

Request from Dan Waldeck during the 2023 SRG meeting.

@kellijohnson-NOAA kellijohnson-NOAA added type: enhancement topic: data Data used to fit the stock assessment topic: R code labels Feb 7, 2023
@kellijohnson-NOAA kellijohnson-NOAA added this to the 2024 milestone milestone Feb 7, 2023
@kellijohnson-NOAA kellijohnson-NOAA self-assigned this Feb 7, 2023
@kellijohnson-NOAA
Copy link
Collaborator Author

@John-R-Wallace-NOAA would you be willing to help me with logbook data to get depth for shoreside catch of Pacific Hake? What table should I request access to from PacFIN?

@John-R-Wallace-NOAA
Copy link

 # Hake is often caught with midwater gear, however there are two depths for midwater tows, the net depth and the bottom depth - I will look at both.
 
 
 # --- Download  a function from GitHub and attach a package ---
 sourceFunctionURL <- function (URL,  type = c("function", "script")[1]) {
           " # For more functionality, see gitAFile() in the rgit package ( https://github.com/John-R-Wallace-NOAA/rgit ) which includes gitPush() and git() "
           if (!any(installed.packages()[, 1] %in% "httr"))  install.packages("httr") 
           File.ASCII <- tempfile()
           if(type == "function")
             on.exit(file.remove(File.ASCII))
           getTMP <- httr::GET(gsub(' ', '%20', URL))
           
           if(type == "function") {
             write(paste(readLines(textConnection(httr::content(getTMP))), collapse = "\n"), File.ASCII)
             source(File.ASCII)
           } 
           if(type == "script") {
             fileName <- strsplit(URL, "/")[[1]]
             fileName <- rev(fileName)[1]
             write(paste(readLines(textConnection(httr::content(getTMP))), collapse = "\n"), fileName)
           }  
    }
 
 sourceFunctionURL("https://raw.githubusercontent.com/John-R-Wallace-NOAA/JRWToolBox/master/R/agg.table.R") 
 
 library(lattice)
 
 # ---------------------------------------------------------------------------------------
 
 # For info, including a link to my PacFIN logbook cleanup repo, see here:  \\nwcfile.nmfs.local\FRAM\Assessments\PacFIN\Main PacFIN Logbook Cleanup - 2021
 
 # The SQL code containing the PacFIN tables used is in the repo here:  PacFIN_Logbook_Download_and_Cleanup/R/Funcs and Data/PacFIN Logbook Data by Year.R
 ...
 from pacfin.lbk_trip tr, pacfin.lbk_tow tw, pacfin.lbk_catch c, pacfin.lbk_sp s,
       pacfin.asp, pacfin.lbk_gr g, pacfin.lbk_pr p1, pacfin.lbk_pr p2, 
       pacfin.lbkprmtlst prmt
 ...
 
 
 #  I am using the latest shortform logbook data used by Derek (postdoc work after the saildrone project) and by Jameal for his 'Stay or Go' paper.  
 #         Shortform format is tows in rows crossed with species (FMP plus Mackerel) and metadata in columns. 
 load("\\\\nwcfile.nmfs.local\\FRAM\\Assessments\\PacFIN\\Main PacFIN Logbook Cleanup - 2021\\LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel 26 May 2022.RData")
 
 # Note that only CA has logbook data from 1981-86 and CA logbook information for 2020 was still not in PacFIN (and perhaps not all of WA) when this data was extracted and processed. 
 table(LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel$RYEAR, LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel$AGID)
       
            C     O     W
   1981 22869     0     0
   1982 22772     0     0
   1983 19922     0     0
   1984 17138     0     0
   1985 18647     0     0
   1986 18479     0     0
   1987 15466 15124 10661
   1988 16978 18367 11451
   1989 19292 22902 13372
   1990 16314 19298 11714
   1991 18280 27667 11475
   1992 18440 23848 11514
   1993 17510 27383 10402
   1994 15621 20137  7902
   1995 16278 17392  6277
   1996 17353 17802  5310
   1997 18501 16166  5043
   1998 15140 14547  4223
   1999 15871 12634  4024
   2000 11661 10948  3833
   2001 12615 10917  3664
   2002 12785  8502  2818
   2003  9928  9172  3430
   2004  9069  8714  2876
   2005 10014  9588  2714
   2006  8473 10417  2087
   2007  7412  9942  1558
   2008  7464 10593  1194
   2009  7520 12450  1290
   2010  6016 10160   987
   2011  5358  6915  1024
   2012  5687  6403   989
   2013  6574  7305   939
   2014  7376  6120   647
   2015  8389  6085   410
   2016  6943  5872   512
   2017  6800  6322   803
   2018  6180  5836   242
   2019  4192  5573   224
   2020     0  4586    83
 
 
 
 # PacFIN has a 'depth1' and 'depth2' with corresponding 'depth_type1' and  'depth_type1', which could contain, e.g.: N=Net depth, B= Bottom depth. 
 #        Unfortunately, 'depth2' and depth types 1 and 2 are completely blank, last I Iooked.
 # One is left to wondering if the reported depth in 'depth1' is net or bottom depth for midwater tows.
 # Using the depthMeters() function in my Imap package, I found the bathymetric depth by lat/long to compare to 'depth1' and to use for bottom depth when no depth was reported.
 
 
 # Avoiding the earlier years where misreporting was common, note that for midwater (MDT) tows 'depth1' are often not as deep as the bottom depth.
 # (For midwater tows, perhaps a minimum delta between 'depth1' and the bathymetric depth could be used to find those tows where 'depth1' is truly the net depth.)
 xyplot(DEPTH1 ~ DepthGIS.m | GRID, data = LB.ShortForm.with.Hake.Strat[LB.ShortForm.with.Hake.Strat$RYEAR >= 2015, ], 
        panel = function(...) { panel.xyplot(...); panel.abline(0, 1, col = 'green') })
 
 
 # The net and bottom depth for Hake can be looked for all tows with a positive Hake catch, or when the post-hoc fishing strategy (based on species comp. in the tow) is defined to be a Hake tow.  
 #        (Of course, a simple minimum limit of Hake catch in a tow could also be used.)
 # The midwater tow and bottom depth results are quite similar, and the post-hoc Hake strategy results are shown below.
 # State waters based on latitude (see the 'Compare Raw and Processed Logbook to FIshticket Data' folder in the repo) or where the catch was landed using state agency (AGID) , could also be used. 
 #        (Or any strata based on the metadata.)
 
 # LB.Hake <- LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel[LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel$PWHT.kg > 0, ]
 LB.Hake <- LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel[LB.ShortForm.with.Hake.Strat.Ves.num.Mackerel$Strategy == 'HAKE', ]
 dim(LB.Hake)
 
 
 
 agg.table(aggregate(list(Number_of_Tows = LB.Hake$BestBtmDepth.m), list(GRID = LB.Hake$GRID, State.Waters.PSMFC = LB.Hake$State.Waters.PSMFC), length), sortColNames = TRUE)
 
       Number_of_Tows 
 
 GRID  State.Waters.PSMFC 
 
        CA     OR     WA
 FFT    NA     41     71
 FTS    NA     NA     38
 GFL    18     NA     NA
 GFS    30     NA     NA
 GFT   870     48     98
 MDT 3,532 22,879 21,892
 OTW    14     NA     NA
 RLT    NA     28     67
 
 
 agg.table(aggregate(list(DEPTH1.m = LB.Hake$DEPTH1 * 1.8288), list(GRID = LB.Hake$GRID, State.Waters.PSMFC = LB.Hake$State.Waters.PSMFC), mean, na.rm = TRUE), digits = 1, sortColNames = TRUE)
 
         DEPTH1.m 
 
  RID       State.Waters.PSMFC 
 
        CA    OR    WA
 FFT    NA 127.0  82.6
 FTS    NA    NA  36.0
 GFL 336.3    NA    NA
 GFS 150.2    NA    NA
 GFT 135.2 204.7  92.4
 MDT 204.0 215.6 185.5
 OTW 121.4    NA    NA
 RLT    NA 239.1 227.7
 
 
 agg.table(aggregate(list(BestBtmDepth.m = LB.Hake$BestBtmDepth.m), list(GRID = LB.Hake$GRID, State.Waters.PSMFC = LB.Hake$State.Waters.PSMFC), mean, na.rm = TRUE), digits = 1, sortColNames = TRUE)
  
       BestBtmDepth.m 
 
 GRID   State.Waters.PSMFC 
 
        CA    OR    WA
 FFT    NA 127.0  82.6
 FTS    NA    NA  36.0
 GFL 336.3    NA    NA
 GFS 150.2    NA    NA
 GFT 138.8 204.6  92.4
 MDT 296.7 234.8 238.9
 OTW 121.4    NA    NA
 RLT    NA 239.1 231.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: data Data used to fit the stock assessment topic: R code type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants