Skip to content

Commit db30060

Browse files
committed
Update to v2
1 parent 988e14a commit db30060

18 files changed

+1140
-10
lines changed

README.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
1-
# Model code for Zooplankton Model of Size Spectrum (ZooMSS v1)
1+
# Model code for Zooplankton Model of Size Spectrum (ZooMSS v2)
22

3-
This repo holds the code for Zooplankton Model of Size Spectrum (ZooMSS v1) as published in Heneghan et al. 2016 (pdf attached).
43

5-
The size-spectrum model consists of a size-spectrum comprised of three communities: phytoplankton, zooplankton, and fish. The phytoplankton component covers the smallest size classes and is held constant as a background resource spectrum for zooplankton. Size-dependent processes of growth and mortality drive the zooplankton and fish components.
64

7-
Heneghan RF, Everett JD, Blanchard JL and Richardson AJ (2016) Zooplankton Are Not Fish: Improving Zooplankton Realism in Size-Spectrum Models Mediates Energy Transfer in Food Webs. *Front. Mar. Sci.* **3**:201. doi: 10.3389/fmars.2016.00201
8-
https://doi.org/10.3389/fmars.2016.00201
5+
## Overview of ZooMSS
6+
7+
The Zooplankton Model of Size Spectra (ZooMSS) is a functional size-spectrum model of the marine ecosystem (following Heneghan et al. 2016, ZooMSSv1) to resolve phytoplankton, nine zooplankton functional groups (heterotrophic flagellates and ciliates, omnivorous and carnivorous copepods, larvaceans, euphausiids, salps, chaetognaths and jellyfish) and three size-based fish groups. Zooplankton functional groups are resolved using their body-size ranges, size- based feeding characteristics and carbon content, and the zooplankton community emerges from the model across global environmental gradients, depending on the functional traits of the different groups.
8+
9+
We developed the Zooplankton Model of Size Spectra version 2 (ZooMSSv2) based on the prototype of Heneghan et al. (2016). ZooMSSv2 uses the functional size-spectrum framework (Blanchard et al., 2017) to resolve the body size ranges, size-based feeding characteristics and carbon content of nine zooplankton groups and three fish groups. The model is run on 5° grid squares across the global ocean. For each region, the model is forced with the long- term mean satellite sea surface temperature and chlorophyll a from MODIS-Aqua.
10+
11+
ZooMSSv2 represents the marine ecosystem as three communities: phytoplankton, zooplankton and fish. The zooplankton community consists of nine of the most abundant zooplankton groups, and the fish community was made up of a small, medium and large group. Dynamics of the phytoplankton are not explicitly resolved in the model, rather the mean size structure of the phytoplankton community is estimated directly from satellite chlorophyll a observations (Brewin et al., 2010; Barnes et al., 2011; Hirata et al., 2011). Abundances of the zooplankton and fish communities are driven by size-dependent processes of growth and mortality, with the temporal dynamics of each functional group governed by separate second- order McKendrick-von Foerster equations.
12+
13+
14+
## How to run ZooMSS using `R`
15+
16+
### Model Structure
17+
18+
The model is split into 5 main files.
19+
20+
1. Setup_RUN_NAME.R - Set up your own specific simulation. This is the only file you usually need to edit.
21+
22+
2. fZooMSS_Model.R - The top-level model function which seuqentially runs the following 3 functions, and saves the output.
23+
24+
+ fZooMSS_Params.R - Set all the parameter values for the model.
25+
26+
+ fZooMSS_Setup.R - Do all calculations which can be done in advance of the time loop.
27+
28+
+ fZooMSS_Run.R - Contains the time-dependent loop.
29+
30+
### Input files
31+
32+
ZooMSS requires two input files:
33+
34+
1. TestGroups.csv which contains all the taxa-specific parameter values, including size ranges.
35+
36+
2. And RDS file which contains all environmental data for each grid cell. This includes chlorophyll a (chlo), sea surface temperature (sst), bathymetry (bathy), phytoplankton slope and intercept, and latitude/longitude which is useful for plotting.
37+
38+
39+
### Running
40+
To run the model, you simply need to provide the relevent information in Setup_RUN_NAME.R and run the script.
41+
42+
## Publications
43+
44+
1. Heneghan, R.F., Everett, J.D., Blanchard, J.L., Richardson, A.J., 2016. Zooplankton Are Not Fish: Improving Zooplankton Realism in Size-Spectrum Models Mediates Energy Transfer in Food Webs. Front. Mar. Sci. 3, 1–15. https://doi.org/10.3389/fmars.2016.00201
45+
46+
2. Heneghan, R.F., Everett, J.D., Sykes, P., Batten, S.D., Edwards, M., Takahashi, K., Suthers, I.M., Blanchard, J.L., Richardson, A.J., in review, A global size-spectrum model of the marine ecosystem that resolves zooplankton composition. Ecological Modelling
47+
48+
49+
## Getting Help
50+
51+
If you are running the model come across a problem, raise an issue on GitHub: https://github.com/MathMarEcol/ZoopSizeSpectraModel/issues
52+
53+
If you find some errors, or just want to improve the model, we'd love you to go ahead and make the changes and then submit a pull request for us to check and approve.
54+
955

10-
## SCRIPTS
11-
ZooMSS_Shell.R: You run the model from this script.
12-
ZooMSS_Parameters.R: Parameters for the model.
13-
ZooMSS_Stability: Code for stability analysis via Newton-Raphson method.
14-
ZooMSS_PDE: The model code.

TestGroups.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Species,Type,FeedType,Prop,W0,Wmax,Wmat,SearchCoef,SearchExp,PPMRscale,PPMR,FeedWidth,GrossGEscale,Carbon,Repro,PlotColour
2+
Flagellates,Zooplankton,Heterotroph,0.1,-10.7,-6.8,-8.8,640,0.8,1.5,NA,0.36,2.5,0.15,0,seagreen3
3+
Ciliates,Zooplankton,Heterotroph,0.1,-9.3,-6.3,-8.3,640,0.8,0.04,NA,0.47,2.5,0.15,0,seagreen4
4+
Larvaceans,Zooplankton,FilterFeeder,0.1,-6.4,-3.2,-5.2,640,0.8,-3,NA,0.7,2.5,0.02,0,lightgoldenrod4
5+
OmniCopepods,Zooplankton,Omnivore,0.04,-7.5,-3.5,-5.5,640,0.8,-0.5,NA,0.57,2.5,0.12,0,cornflowerblue
6+
CarnCopepods,Zooplankton,Carnivore,0.06,-7.5,-2.5,-4.5,640,0.8,1.5,NA,0.36,2.5,0.12,0,darkred
7+
Euphausiids,Zooplankton,Omnivore,0.1,-4.2,0.2,-1.8,640,0.8,-2,NA,0.7,2.5,0.12,0,darkblue
8+
Chaetognaths,Zooplankton,Carnivore,0.1,-5.9,-0.9,-2.9,640,0.8,1,NA,0.46,2.5,0.04,0,firebrick1
9+
Salps,Zooplankton,FilterFeeder,0.01,-4.7,1.4,-0.6,640,0.8,-2.68,NA,0.7,2.5,0.02,0,lightgoldenrod3
10+
Jellyfish,Zooplankton,Carnivore,0.01,-3,2,0,640,0.8,0.73,NA,0.52,2.5,0.005,0,orange
11+
Fish_Small,Fish,Carnivore,NA,-3,2,0,640,0.8,NA,100,1.3,2.5,0.1,0,lightcoral
12+
Fish_Med,Fish,Carnivore,NA,-3,4,2,640,0.8,NA,100,1.3,2.5,0.1,0,coral3
13+
Fish_Large,Fish,Carnivore,NA,-3,7,4,640,0.8,NA,100,1.3,2.5,0.1,0,coral4

ZooMSS.Rproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Encoding: UTF-8
1111

1212
RnwWeave: Sweave
1313
LaTeX: pdfLaTeX
14+
15+
StripTrailingWhitespace: Yes
16+
17+
QuitChildProcessesOnExit: Yes

ZooMSS_Plot_GlobalMap.R

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
library(tidyverse)
2+
library(rnaturalearth)
3+
library(rnaturalearthdata)
4+
library(sf)
5+
library(raster)
6+
7+
source("fZooMSS_Xtras.R")
8+
9+
w <- 10^(seq(from = -10.7, to = 7, 0.1)) # Size bins of whole model
10+
11+
res <- read_rds("Output/res_20200429_Control.RDS")
12+
groups <- read_csv("TestGroups.csv")
13+
enviro <- read_rds("envirofull_20200317.RDS")
14+
15+
# Calculate biomass of each species for each cell
16+
bioms <- fZooMSS_SpeciesBiomass(res,w)
17+
bioms <- as.data.frame(t(as.data.frame(bioms)))
18+
colnames(bioms) <- groups$Species # Add names
19+
rownames(bioms) <- c() # Remove row names
20+
21+
bioms <- bind_cols(bioms, enviro) # Bind enviro data
22+
23+
# Which variable to plot
24+
var = "Fish_Small"
25+
26+
# What to plot
27+
df <- bioms %>%
28+
dplyr::select("Lon", "Lat", all_of(var))
29+
30+
# Now do the plotting
31+
world <- ne_countries(scale = "medium", returnclass = "sf")
32+
world_sf <- st_transform(world, crs = 54009) # Convert to Mollweide
33+
34+
df_raster <- rasterFromXYZ(df) #Convert first two columns as lon-lat and third as value
35+
df_poly <- rasterToPolygons(df_raster, fun=NULL, n=4, na.rm=TRUE, digits=12, dissolve=FALSE) # Convert to polygon which is better for plotting
36+
df_sf <- st_as_sf(df_poly, crs = 4326) # Convert to sf
37+
38+
st_crs(df_sf) <- 4326 # Set base projection
39+
df_sf_moll <- st_transform(df_sf, crs = 54009) # Alter the CRS to mollweide
40+
41+
gg_world <- ggplot() +
42+
geom_sf(data = df_sf_moll, aes_string(fill = var), color = NA) +
43+
geom_sf(data = world_sf, size = 0.05, fill = "grey50") +
44+
scale_fill_gradient(low = "white",
45+
high = "lightcoral",
46+
space = "Lab",
47+
na.value = "grey50",
48+
aesthetics = "fill",
49+
oob = scales::squish,
50+
guide = guide_colourbar(title = paste0(var, " Biomass"),
51+
title.position = "top",
52+
title.hjust = 0.5)) +
53+
theme(plot.background = element_rect(fill = NA),
54+
plot.margin = unit(c(0,0,0,0), "mm"),
55+
panel.grid.major = element_line(colour = "grey50", size = 0.2),
56+
panel.background = element_blank(),
57+
panel.border = element_blank(),
58+
legend.position = "bottom",
59+
legend.key.width = unit(20,"mm"),
60+
legend.key.height = unit(4,"mm"))
61+
62+
63+
graphics.off()
64+
x11(width = 8, height = 6)
65+
gg_world
66+
ggsave(paste0("Figures/Biomass_",var,".png"), dpi = 300)

ZooMSS_Plot_RunTime.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
library(tidyverse)
2+
library(patchwork)
3+
4+
# Load all files
5+
fi <- list.files("RawOutput/", full.names = TRUE)
6+
7+
# Create empty df to store data
8+
df <- tibble("No" = rep(NA, length(fi)),
9+
"SST" = rep(NA, length(fi)),
10+
"Chl" = rep(NA, length(fi)),
11+
"RunTime" = rep(NA, length(fi)))
12+
13+
for (i in 1:length(fi)){
14+
15+
dat <- read_rds(fi[i])
16+
17+
df$No[i] <- i
18+
df$SST[i] <- dat$model$param$sst
19+
df$Chl[i] <- dat$model$param$chlo
20+
df$RunTime[i] <- as.numeric(dat$model$model_runtime[3])/60
21+
rm(dat)
22+
23+
}
24+
# Plot
25+
gg1 <- ggplot(data = df, aes(x = log10(Chl), y = RunTime)) +
26+
geom_point() +
27+
geom_smooth(method = "loess") +
28+
theme_bw() +
29+
ylab("Model Run Time (mins)")
30+
31+
gg2 <- ggplot(data = df, aes(x = SST, y = RunTime)) +
32+
geom_point() +
33+
geom_smooth(method = "loess") +
34+
theme_bw() +
35+
ylab("Model Run Time (mins)")
36+
37+
x11(width = 12, height = 6)
38+
gg1 / gg2
39+
ggsave("Figures/Model_RunTime.png", dpi = 300)
40+

ZooMSS_Plot_SpeciesAccum.R

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
## Now lets have a look at how the output changes in 50 year increments
3+
4+
library(tidyverse)
5+
library(patchwork)
6+
fi <- list.files("RawOutput", full.names = TRUE)
7+
8+
int <- 50
9+
tm <- seq(int,1000,int)
10+
11+
# Create empty df to store data
12+
out <- tibble("SST" = numeric(),
13+
"Chl" = numeric(),
14+
"Run" = numeric(),
15+
"Time" = numeric(),
16+
"Abund" = numeric(),
17+
"Growth" = numeric(),
18+
"Mort" = numeric())
19+
20+
for (i in 1:length(fi)){
21+
dat <- read_rds(fi[i])
22+
for (j in 1:length(tm)){
23+
24+
sp <- dat$model$param$Groups$Species
25+
26+
df <- tibble("SST" = rep(NA, length(sp)),
27+
"Chl" = rep(NA, length(sp)),
28+
"Run" = rep(NA, length(sp)),
29+
"Time" = rep(NA, length(sp)),
30+
"Abund" = rep(NA, length(sp)),
31+
"Growth" = rep(NA, length(sp)),
32+
"Mort" = rep(NA, length(sp)))
33+
34+
for (k in 1:length(sp)){
35+
36+
df$Run[k] <- i
37+
df$Time[k] <- tm[j]
38+
df$SST[k] <- dat$model$param$sst
39+
df$Chl[k] <- dat$model$param$chlo
40+
df$Species[k] <- sp[k]
41+
df$Abund[k] <- sum(colMeans(dat$model$N[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
42+
df$Growth[k] <- sum(colMeans(dat$model$gg[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
43+
df$Mort[k] <- sum(colMeans(dat$model$Z[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
44+
45+
46+
# df$Abund[k] <- sum(colMeans(dat$model$N[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
47+
# df$Growth[k] <- sum(colMeans(dat$model$gg[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
48+
# df$Mort[k] <- sum(colMeans(dat$model$Z[(ceiling(0.5*tm[j]):tm[j]),k,], dims = 1))
49+
}
50+
51+
out <- bind_rows(out, df)
52+
rm(df)
53+
54+
}
55+
}
56+
57+
58+
x11(width = 12, height = 6)
59+
out %>%
60+
# filter(Species == "OmniCopepods") %>%
61+
mutate(Run = as.factor(Run),
62+
Species = factor(Species, levels=sp),
63+
ChlSST = factor(paste0(Chl, "Chl-", SST, "SST"))) %>%
64+
ggplot(aes(x = Time, y = log10(Abund))) +
65+
# geom_point(size = 0.5) +
66+
geom_line(aes(colour = Run), size = 0.1) +
67+
facet_wrap(~ Species, ncol = 4, scales = "free") +
68+
theme_bw() +
69+
theme(legend.position = "none") +
70+
scale_x_continuous(expand = c(0, 0)) +
71+
scale_y_continuous(expand = c(0, 0))
72+
73+
ggsave("Figures/SpeciesAccumulation.png", dpi = 200)
74+
75+

ZooMSS_RUN_NAME.pbs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
#PBS -l nodes=1:ppn=1,mem=1gb
4+
#PBS -l walltime=11:59:59
5+
6+
#PBS -m ae
7+
#PBS -o JobOutput/
8+
#PBS -e JobOutput/
9+
#PBS -J 1-1638
10+
#PBS -j oe
11+
12+
module purge
13+
module add R/3.6.1
14+
15+
cd $PBS_O_WORKDIR
16+
17+
Rscript setup_RUNS_NAME.R

ZooMSS_User_Manual.Rmd

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "ZooMSS User Manual"
3+
author: "The UQ ZooMSS Team"
4+
date: "18/03/2020"
5+
output: pdf_document
6+
---
7+
8+
```{r setup, include=FALSE}
9+
knitr::opts_chunk$set(echo = TRUE)
10+
```
11+
12+
Note: This is still very much a work in progress.
13+
14+
## Overview of ZooMSS
15+
16+
The Zooplankton Model of Size Spectra (ZooMSS) is a functional size-spectrum model of the marine ecosystem (following Heneghan et al. 2016, ZooMSSv1) to resolve phytoplankton, nine zooplankton functional groups (heterotrophic flagellates and ciliates, omnivorous and carnivorous copepods, larvaceans, euphausiids, salps, chaetognaths and jellyfish) and three size-based fish groups. Zooplankton functional groups are resolved using their body-size ranges, size- based feeding characteristics and carbon content, and the zooplankton community emerges from the model across global environmental gradients, depending on the functional traits of the different groups.
17+
18+
We developed the Zooplankton Model of Size Spectra version 2 (ZooMSSv2) based on the prototype of Heneghan et al. (2016). ZooMSSv2 uses the functional size-spectrum framework (Blanchard et al., 2017) to resolve the body size ranges, size-based feeding characteristics and carbon content of nine zooplankton groups and three fish groups. The model is run on 5° grid squares across the global ocean. For each region, the model is forced with the long- term mean satellite sea surface temperature and chlorophyll a from MODIS-Aqua.
19+
20+
ZooMSSv2 represents the marine ecosystem as three communities: phytoplankton, zooplankton and fish. The zooplankton community consists of nine of the most abundant zooplankton groups, and the fish community was made up of a small, medium and large group. Dynamics of the phytoplankton are not explicitly resolved in the model, rather the mean size structure of the phytoplankton community is estimated directly from satellite chlorophyll a observations (Brewin et al., 2010; Barnes et al., 2011; Hirata et al., 2011). Abundances of the zooplankton and fish communities are driven by size-dependent processes of growth and mortality, with the temporal dynamics of each functional group governed by separate second- order McKendrick-von Foerster equations.
21+
22+
23+
## How to run ZooMSS using `R`
24+
25+
### Model Structure
26+
27+
The model is split into 5 main files.
28+
29+
1. Setup_RUN_NAME.R - Set up your own specific simulation. This is the only file you usually need to edit.
30+
31+
2. fZooMSS_Model.R - The top-level model function which seuqentially runs the following 3 functions, and saves the output.
32+
33+
+ fZooMSS_Params.R - Set all the parameter values for the model.
34+
35+
+ fZooMSS_Setup.R - Do all calculations which can be done in advance of the time loop.
36+
37+
+ fZooMSS_Run.R - Contains the time-dependent loop.
38+
39+
### Input files
40+
41+
ZooMSS requires two input files:
42+
43+
1. TestGroups.csv which contains all the taxa-specific parameter values, including size ranges.
44+
45+
2. And RDS file which contains all environmental data for each grid cell. This includes chlorophyll a (chlo), sea surface temperature (sst), bathymetry (bathy), phytoplankton slope and intercept, and latitude/longitude which is useful for plotting.
46+
47+
48+
### Parameter Values
49+
50+
Insert table from Heneghan et al (in review)
51+
52+
### Output
53+
54+
TBC
55+
56+
### Running
57+
To run the model, you simply need to provide the relevent information in Setup_RUN_NAME.R and run the script.
58+
59+
### Plotting
60+
61+
TBC
62+
63+
## Useful reading
64+
65+
Datta Paper
66+
The other thing to look at would be some of the numerical methods we use
67+
- Simpson’s method for the growth, mortality and diffusion integrals and
68+
- a semi-implicit upward finite difference scheme to solve the PDE at each time step.
69+
For the PDE numerical method, check out Appendix 1 of my thesis (attached)
70+
Info on the difference scheme in Press’ 2007 book: Numerical Recipes, the Art of Scientific Computing (Available at UQ Library)
71+
72+
73+
On 1 Apr 2020, at 06:50, Richardson, Anthony (O&A, St. Lucia) <[email protected]> wrote:
74+
75+
<Datta et al. - 2010 - A Jump-Growth M odel for Predator–Prey Dynamics De.pdf>
76+
77+
## Publications
78+
79+
1. Heneghan, R.F., Everett, J.D., Blanchard, J.L., Richardson, A.J., 2016. Zooplankton Are Not Fish: Improving Zooplankton Realism in Size-Spectrum Models Mediates Energy Transfer in Food Webs. Front. Mar. Sci. 3, 1–15. https://doi.org/10.3389/fmars.2016.00201
80+
81+
2. Heneghan, R.F., Everett, J.D., Sykes, P., Batten, S.D., Edwards, M., Takahashi, K., Suthers, I.M., Blanchard, J.L., Richardson, A.J., in review, A global size-spectrum model of the marine ecosystem that resolves zooplankton composition. Ecological Modelling
82+
83+
## References
84+
85+
TBC
86+
87+
## Getting Help
88+
89+
If you are running the model come across a problem, raise an issue on GitHub: https://github.com/MathMarEcol/ZooMSS/issues
90+
91+
If you find some errors, or just want to improve the model, we'd love you to go ahead and make the changes and then submit a pull request for us to check and approve.
92+
93+
Same for this manual. If there is information lacking, errors etc, please fix it rather than just reporting it. This should be a team effort.
94+
95+

envirofull_20200317.RDS

53.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)