archive/mardown/99_feeding_networks_report.md

title: "Snow crab predators" author: - name: given: Snow Crab Unit family: DFO Science # orcid: 0000-0003-3632-5723 # email: jae.choi@dfo-mpo.gc.ca # email: choi.jae.seok@gmail.com # corresponding: true affiliation: - name: Bedford Institute of Oceanography, Fisheries and Oceans Canada city: Dartmouth state: NS # url: www.bio.gc.ca date: last-modified date-format: "YYYY-MM-D" keywords: - basic feeding networks abstract: | Details of stomach contents data base. toc: true toc-depth: 4 number-sections: true highlight-style: pygments

bibliography: media/references.bib

csl: media/canadian-journal-of-fisheries-and-aquatic-sciences.csl # see https://www.zotero.org/styles for more

license: "CC BY"

copyright: holder: Jae S. Choi year: 2024

citation:

container-title: https://github.com/jae0/bio.snowcrab/

doi: NA

funding: "The snow crab scientific survey was funded by the snow crab fishers of Maritimes Region of Atlantic Canada." editor: render-on-save: false execute: echo: true format: html: code-fold: true code-overflow: wrap html-math-method: katex self-contained: true embed-resources: true pdf: pdf-engine: lualatex docx: default fontsize: 12pt params: year_assessment: 2024 media_loc: "media" sens: 1 debugging: FALSE

First set up environment and get the data.

#| eval: true
#| output: false
#| warning: false
#| error: false 
# startup libraries and directories

require(aegis)

year_assessment = params$year_assessment

p = bio.snowcrab::load.environment( year.assessment=year_assessment )

project_directory = p$data_root

data_dir = file.path( project_directory, "data", "diets" )

require(data.table) # for speed
require(lubridate)
require(stringr) 
require(gt)  # table formatting
require(ggplot2)

require(aegis) # map-related 
require(bio.taxonomy)  # handle species codes

# assimilate the CSV data tables:
# diet = get_feeding_data( data_dir, redo=TRUE )  # if there is a data update
diet = get_feeding_data( data_dir, redo=FALSE )

What are the predators of snow crab?

#| eval: true
#| output: true
#| label: predator_list
#| tbl-cap: "All predators of snow crab on Scotian Shelf of Atlantic Canada. Of 58287 finfish stomach samples, 159 had snow crab (0.28%). There is no indormation on snow crab diet in the database."
tx = taxa_to_code("snow crab")  
# matching codes are 
#  spec    tsn                  tx                   vern tx_index
#1  528 172379        BENTHODESMUS           BENTHODESMUS     1659
#2 2522  98427        CHIONOECETES SPIDER QUEEN SNOW UNID      728
#3 2526  98428 CHIONOECETES OPILIO        SNOW CRAB QUEEN      729
# 2 and 3 are correct

snowcrab_predators = diet[ preyspeccd %in% c(2522, 2526), ]  # n=159 oservations out of a total of 58287 observations in db (=0.28% of all data)
snowcrab_predators$Species = code_to_taxa(snowcrab_predators$spec)$vern
snowcrab_predators$Predator = factor(snowcrab_predators$Species)

counts = snowcrab_predators[ , .(Frequency=.N), by=.(Species)]
setorderv(counts, "Frequency", order=-1)

gt::gt(counts) |> gt::tab_options(table.font.size = 12, data_row.padding = gt::px(1), 
    summary_row.padding = gt::px(1), grand_summary_row.padding = gt::px(1), 
    footnotes.padding = gt::px(1), source_notes.padding = gt::px(1), 
    row_group.padding = gt::px(1))

Where are the predators with snow crab in their stomachs?

#| eval: false
#| output: false
#| label: temp_depth
#| fig-cap: "Temperature and depths of snow crab predation on the Scotian Shelf of Atlantic Canada. Grey is all species observations in diet data base. Red is snow crab as prey."
#| fig-dpi: 144
#| fig-height: 4
#plot( depth ~ bottom_temperature, diet, pch=18, col="grey")
#points( depth ~ bottom_temperature, snowcrab_predators, col="red", pch=19 )
#| eval: true
#| output: true
#| label: map_observations_pre2010
#| fig-cap: "Locations where snow crab predation was observed on the Scotian Shelf of Atlantic Canada, 2000-2010."
#| fig-dpi: 144
#| fig-height: 6
ggplot() + 
    borders("world", fill = "lightgray", colour = "grey80") + 
    xlim(c( -65.5, -57.1)) + ylim(c(42.1, 47.1)) +
    geom_point(data=snowcrab_predators[year(timestamp) %in% c(2000:2010),], aes(x=slongdd, y=slatdd, colour=Predator ), size=2.5 ) +
    labs(x="Longitude", y="Latitude", caption="2000-2010") +
    theme(legend.position="inside", legend.position.inside =c(0.16, 0.65), legend.title=element_blank(), legend.text=element_text(size=6.0) 
 ) 
#| eval: true
#| output: true
#| label: map_observations_post2010
#| fig-cap: "Locations where snow crab predation was observed on the Scotian Shelf of Atlantic Canada, 2011-2020."
#| fig-dpi: 144
#| fig-height: 6
ggplot() + 
    borders("world", fill = "lightgray", colour = "grey80") + 
    xlim(c( -65.5, -57.1)) + ylim(c(42.1, 47.1)) +
    geom_point(data=snowcrab_predators[year(timestamp) %in% c(2011:2020),], aes(x=slongdd, y=slatdd, colour=Predator ), size=2.5 ) +
    labs(x="Longitude", y="Latitude", caption="2011-2020") +
    theme(legend.position="inside", legend.position.inside =c(0.16, 0.725), legend.title=element_blank(), legend.text=element_text(size=6.0) )

Project location of predators upon species composition information

Basic idea is that we have a reasonable undertanding of demersal communities. Based upon this, we can project where these predation events are most likely.

Note:

#| eval: false
#| output: true
# Loadings are eigenvectors scaled by the square roots of the respective eigenvalues
loadings = eigenvectors %*% sqrt(diag( eigenvalues, nrow = length( eigenvalues ))) 

# scores are sum of dot products
scores = indat %*% t(pracma::pinv(loadings ))  
#| eval: true
#| output: true
#| warning: false
#| error: false 

yrs = 1999:year_assessment
carstm_model_label="default"
require(aegis)
require(aegis.speciescomposition)

p = speciescomposition_parameters( yrs=yrs, carstm_model_label=carstm_model_label )

# speciescomposition_db( DS="speciescomposition.ordination.redo", p=p )  # analsysis
# speciescomposition_db( DS="speciescomposition.redo", p=p  ) # compute planar coords and remove dups

pca = speciescomposition_db( DS="pca", p=p )  # analsysis
names(pca)
# [1] "cm"               "indat"            "rotate"           "eigenvalues"     
# [5] "eigenvectors"     "loadings"         "scores"           "variance"        
# [9] "variance_percent" "total_variance"  

predator_names = unique(snowcrab_predators$Species)

pcares = as.data.frame( pca$loadings )
pcares$vern = taxonomy.recode( from="spec", to="taxa", tolookup=rownames( pcares ) )$vern
pcares$sc_predator = 0
pcares$sc_predator[ which(pcares$vern %in% predator_names) ] = 1   

toblank = which( pcares$sc_predator==0)
toblank = setdiff( toblank,  which(pcares$vern=="SNOW CRAB QUEEN" ) )
pcares$label = pcares$vern
pcares$label[toblank] = "+" 


plot( PC2 ~ PC1, pcares, type="n")
text( PC2 ~ PC1, labels=label, data=pcares, cex=0.8 )

pcares$uv = pcares$sc_predator
pcares$uv[ which( pcares$vern=="SNOW CRAB QUEEN")] = 1
setDT(pcares)


# re-weight species by frequency
setDT(counts)
counts[, weight := Frequency / sum(Frequency) ]

pcares$Species = pcares$vern
pcares = counts[pcares, on="Species"]
pcares$weight[ which(is.na(pcares$weight)) ] = 0
pcares$weight = pcares$weight * 3
pcares$weight[ pcares$Species =="SNOW CRAB QUEEN" ] = 3


# uvs =pcares$uv %*% t(pracma::pinv(pca$loadings ))    
# points( uvs[2] ~ uvs[1], col="red" )
# segments(0, 0, x1 = uvs[1], y1 = uvs[2], col = "red", lwd = 2)

# uvsw = pcares$uv*pcares$weight %*% t(pracma::pinv(pca$loadings ))    
# points( uvsw[2] ~ uvsw[1], col="green" )
# segments(0, 0, x1 = uvsw[1], y1 = uvsw[2], col = "green", lwd = 2)

Question: Where do these predators and snow crab co-occur?

Next use eigenvectors from community field and apply to individual predators's consumption patterns ... this identifies where along the axes they are focussing in terms of diet.

Plot distances along axes of key species.

Issues^1

Bibliography



jae0/snowcrab documentation built on Feb. 20, 2025, 2:27 p.m.