Skip to content

Commit

Permalink
Tidy up two hake summary plots, reverse relevant axes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-edwards committed Jan 26, 2025
1 parent fc0e062 commit 867f341
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 46 deletions.
32 changes: 32 additions & 0 deletions R-temp/DATA_Combined_glorys_hake_UW_for_Andy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Label,year,Y_rec,sd,Tspawn,SSHjac,LSTegg,MLDyolk,PUTlate,MLDlate,PUTpjuv
Main_RecrDev_1993,1993,1.233055,0.232753684,8.311134668,0.110258826,0.006708707,22.09670217,0.01508376,14.21322424,0.033230048
Main_RecrDev_1994,1994,1.26465,0.235726599,8.272401215,0.069240736,-0.012617161,22.65164084,0.017278571,14.47404627,0.040307155
Main_RecrDev_1995,1995,0.3079695,0.287185332,8.455425571,0.086401409,-0.023165738,17.05935286,0.006666622,13.68389892,0.029069904
Main_RecrDev_1996,1996,0.6996405,0.247378357,8.252790499,0.056572963,-0.019721103,17.84476808,0.012082204,13.19930294,0.038106574
Main_RecrDev_1997,1997,0.101917,0.305877767,8.091284941,0.059912231,0.000894966,20.46312422,0.034685206,14.36911914,0.044120163
Main_RecrDev_1998,1998,0.8010245,0.23634098,9.137963898,0.134179724,-0.034939316,30.23971618,0.013243863,15.70182425,0.038225151
Main_RecrDev_1999,1999,2.68468,0.202953346,8.192577395,0.016859,-0.004354906,23.24144231,0.027535092,16.73875098,0.038559782
Main_RecrDev_2000,2000,-1.05894,0.493807718,8.108151183,0.049960367,-0.001676588,19.22980387,0.023176336,14.08417498,0.033822186
Main_RecrDev_2001,2001,0.2921025,0.236061784,8.16568017,0.039053222,-0.005114129,22.14183762,0.019779982,14.12983663,0.03108994
Main_RecrDev_2002,2002,-3.109825,0.560401217,8.473241071,0.036630097,0.008399896,20.93658646,0.025500696,14.83069092,0.039760817
Main_RecrDev_2003,2003,0.572323,0.228231931,8.586772603,0.068695969,-0.023107233,20.36526882,0.017819871,14.75784725,0.046710933
Main_RecrDev_2004,2004,-3.127965,0.615869402,8.47609184,0.07622712,-0.019560615,19.8171068,0.025608959,13.64260083,0.042958905
Main_RecrDev_2005,2005,1.129935,0.217140944,8.327135072,0.106985151,-0.002394898,20.99612446,0.020565282,14.23338664,0.044051676
Main_RecrDev_2006,2006,0.83347,0.225543956,8.306707409,0.074908611,-0.005849837,19.52307249,0.024184703,14.0190032,0.045297367
Main_RecrDev_2007,2007,-3.575215,0.660059307,8.398796769,0.033199208,-0.013941219,22.97263811,0.019073689,14.27312576,0.036042932
Main_RecrDev_2008,2008,1.869325,0.209096959,8.146671987,0.02065585,-0.008204137,21.39060793,0.032542546,14.98415089,0.042127317
Main_RecrDev_2009,2009,0.4833155,0.278489534,8.408069082,0.050593665,-0.002549679,19.80725139,0.013294424,14.24426952,0.025202565
Main_RecrDev_2010,2010,2.907905,0.199560384,8.681655178,0.099378385,-0.005835074,22.80451028,0.010904688,15.72343292,0.025352384
Main_RecrDev_2011,2011,-0.8300225,0.422640426,8.352907111,0.049937373,-0.007399734,19.94028467,0.037279182,14.88602397,0.050429655
Main_RecrDev_2012,2012,0.5710345,0.239371122,8.084445028,0.040940192,-0.011916394,20.09140583,0.024208746,14.73726736,0.038635835
Main_RecrDev_2013,2013,-0.9457155,0.445993037,8.160620289,0.040617482,-0.010330403,22.07909326,0.022726769,13.72648618,0.036619842
Main_RecrDev_2014,2014,2.15022,0.227204419,8.518104525,0.100204085,-0.000121623,19.36148496,0.025179229,13.94997669,0.035377169
Main_RecrDev_2015,2015,-3.334675,0.652479429,8.499941331,0.124987825,-0.020629438,19.96274216,0.021637187,14.3985363,0.039731624
Main_RecrDev_2016,2016,1.810195,0.245887832,8.801100127,0.106445447,-0.007241434,21.89004737,0.014348154,14.13064856,0.034708294
Main_RecrDev_2017,2017,0.499257,0.324736786,8.363064273,0.104547249,-0.000679466,19.00807175,0.028448721,14.1671562,0.044431918
Main_RecrDev_2018,2018,-0.8865055,0.56673768,8.446540621,0.081109126,-0.007217913,23.12266229,0.027114643,14.99061044,0.045369177
Main_RecrDev_2019,2019,-1.26426,0.729419712,8.735108339,0.110391058,-0.004412149,23.91646039,0.024195257,14.02831174,0.04167583
Main_RecrDev_2020,2020,1.61481,0.4133584,8.861360578,0.099408054,0.01220699,21.49089644,0.011226579,14.74510402,0.029182776
Main_RecrDev_2021,2021,2.394355,0.44319551,8.129602552,0.062519839,0.007255588,21.07924921,0.032270986,15.18793064,0.032967345
Main_RecrDev_2022,2022,0.6987995,0.840439455,8.438951954,0.06907991,0.007864924,19.56214851,0.040459521,14.93756718,0.04287624
Main_RecrDev_2023,2023,NA,NA,8.428806408,0.113287848,0.000914227,22.09819945,0.026903702,14.90169047,0.0393882
45 changes: 19 additions & 26 deletions R-temp/ecosystem-summary-hake-glorys.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,6 @@ ecosystem_summary_hake_glorys <- function(max_year = 2024,
class(mld_yolk_index) <- class(oni)






# Going to have to generate anomalies, and so just need medians, at least for now
herring_competition <- dplyr::filter(herring_spawning_biomass,
region == "WCVI") %>%
dplyr::select(c("year",
"median"))


bi

hake_total_biomass_age_1 # only had median



# Should generalise for adding more on. Think we should restrict each to the
# full range of hake recruitment years. TODO need tweaking regarding year of effect.
min_year <- min(glorys_new$year)
Expand Down Expand Up @@ -146,10 +129,13 @@ ecosystem_summary_hake_glorys <- function(max_year = 2024,
plot(temp_spawn_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
ylab = "",
ylim = rev(range(temp_spawn_index$anomaly)),
y_axis_reverse = TRUE)
mtext("Mean temperature during spawning - fish less likely to spawn when higher",
side = 3, adj = 0, cex = 0.7, line = 0.3)

# TODO not sure which way this goes
plot(ssh_jac_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
Expand All @@ -160,30 +146,37 @@ ecosystem_summary_hake_glorys <- function(max_year = 2024,
plot(ast_eggs_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
mtext("Net along-shore transport - increased northward advection away from juvenile nursery areas decreases recruitment TODO check",
ylab = "",
ylim = rev(range(ast_eggs_index$anomaly)),
y_axis_reverse = TRUE)
mtext("Net along-shore transport - increased northward advection away from juvenile nursery areas decreases recruitment",
side = 3, adj = 0, cex = 0.7, line = 0.3)

plot(pu_late_larv_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
ylab = "",
ylim = rev(range(pu_late_larv_index$anomaly)),
y_axis_reverse = TRUE)
mtext("Strength of poleward current - increased northward advection away from juvenile nursery areas decreases recruitment",
side = 3, adj = 0, cex = 0.7, line = 0.3)

plot(mld_late_larv_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
mtext("Mean location of mixed layer depth (Mar-Jun) - TODO figure out",
# larvae aggregate at base of mixed layer so mixed layer depth may limit how far they rise in the water column affecting later transport",
ylab = "",
ylim = rev(range(mld_late_larv_index$anomaly)),
y_axis_reverse = TRUE)
mtext("Mean mixed layer depth (Mar-Jun) - TODO figure out",
side = 3, adj = 0, cex = 0.7, line = 0.3)

plot(mld_yolk_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
mtext("Mean location of mixed layer depth (Jan-Apr) - TODO figure out",
ylab = "",
ylim = rev(range(mld_yolk_index$anomaly)),
y_axis_reverse = TRUE)
mtext("Mean location of mixed layer depth (Jan-Apr)",
side = 3, adj = 0, cex = 0.7, line = 0.3)
mtext("Year", side = 1, line = 3)
}
55 changes: 36 additions & 19 deletions R-temp/ecosystem-summary-hake.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
##' Ecosystem summary for Pacific Hake. Currently
##' ignored in .Rbuildignore as developing.
##'
##' Flipping anomaly (+/-) for some variables so that +ve is good for hake recuitment, as per table
##' in 2025 draft hake assessment. Need to document properly.
##' Also shifting years based on that table. # year (x-axis) is the year of
##' influenced age-0 hake recruitment
##'
##' Using the drivers we have that were found by
##' Vestfals et al. These are currently (from Figure 7):
##' * age-2+ herring spawning? biomass off WCVI (increased competition with herring on summer
Expand Down Expand Up @@ -61,26 +66,28 @@ ecosystem_summary_hake <- function(max_year = 2024,
# Decide to calculate anomalies for only the time period given? I think so as
# that's what would be used in any analysis. Call each an index.
# TODO make a function for this, since will get used repeatedly. And check if
# min year is min_year then no need to re-standardise
# min year is min_year then no need to re-standardise.
# year becomes year that hake recruitment is influenced.
herring_index <- dplyr::filter(herring_competition,
year >= min_year) %>%
dplyr::mutate(anomaly = standardise(median))
year >= min_year - 1) %>% # -1 since going to
# increment next.
dplyr::mutate(year = year + 1,
anomaly = standardise(median))
class(herring_index) <- class(oni) # so a pacea_index for plotting

# TODO - need to figure out shifting of years. x-axis should be the year of
# influenced age-0 hake recruitment
# TODO and flip axes


#expect_equal(min(bi$year),
# min_year)
# shift years by 1 like herring and then restandardise
bi_index <- dplyr::filter(bi,
year >= min_year)
year >= min_year - 1) %>%
dplyr::mutate(year = year + 1,
anomaly = standardise(anomaly))

hake_index <- dplyr::filter(hake_total_biomass_age_1,
year >= min_year) %>%
dplyr::mutate(anomaly = standardise(median))
class(hake_index) <- class(oni)
# shift years by 1 like herring and then resntdardise
hake_age1_index <- dplyr::filter(hake_total_biomass_age_1,
year >= min_year - 1) %>%
dplyr::mutate(year = year + 1,
anomaly = standardise(median))
class(hake_age1_index) <- class(oni)

x_lim <- c(lubridate::dmy(paste0("0101", 1965)),
lubridate::dmy(paste0("0101", max_year))) # TODO automate
Expand All @@ -92,24 +99,34 @@ ecosystem_summary_hake <- function(max_year = 2024,
ylab = "") # Else too much info; putting it into mtext
mtext("Hake age-0 recruitment (billions of fish)", side = 3, adj = 0, cex = 0.7,
line = 0.3)

plot(herring_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
ylab = "",
ylim = rev(range(herring_index$anomaly)), # TODO add to
# plot.pacea_index and test everything,
# so don't need to specify this if
# y_axis_revers = TRUE
y_axis_reverse = TRUE)
mtext("Pacific Herring spawning biomass off WCVI - increases competition, lower recruitment next year",
side = 3, adj = 0, cex = 0.7, line = 0.3)

plot(bi_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
ylab = "",
ylim = rev(range(bi_index$anomaly)),
y_axis_reverse = TRUE)
mtext("North Pacific Current Bifurcation Index - poorer feeding conditions BC/WA/OR, lower recruitment next year",
side = 3, adj = 0, cex = 0.7, line = 0.3)

plot(hake_index, lwd = lwd_index,
plot(hake_age1_index, lwd = lwd_index,
xlim = x_lim,
xlab = "",
ylab = "")
ylab = "",
ylim = rev(range(hake_age1_index$anomaly)),
y_axis_reverse = TRUE)

mtext("Hake total biomass of age-1 fish - predation on age-0 fish",
side = 3, adj = 0, cex = 0.7, line = 0.3)
Expand Down Expand Up @@ -167,6 +184,6 @@ ecosystem_summary_hake <- function(max_year = 2024,
## }
#return(list(herring_index = herring_index,
# bi_index = bi_index,
# hake_index= hake_index,
# hake_age1_index= hake_age1_index,
# x_lim = x_lim))
}
9 changes: 8 additions & 1 deletion R/plot-pacea-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
##' @param y_tick_by increment for y-axis ticks; gets
##' overwritten in `add_tickmarks()` if this yields more than
##' `y_tick_max_number` tickmarks. If using [plot.pacea_biomass()] the default
##' of 1 gets automatically changed to 0.25 for `plot(hake_biomass)`.
##' of 1 gets automatically changed to 0.25 for `plot(hake_biomass)`. If
##' `y_axis_reverse` is TRUE then the negative of `y_tick_by` (which should
##' always be positive) is passed onto `add_tickmarks()`.
##' @param y_tick_start where to start y-axis tickmarks, set automatically if not
##' specified (may need to occasionally specify)
##' @param y_tick_end where to end y-axis tickmars, as for `y_tick_start`
Expand Down Expand Up @@ -105,6 +107,7 @@ plot.pacea_index <- function(obj,
event_pch = 20,
event_cex = 3,
event_col = "grey",
y_axis_reverse = FALSE,
...
){
stopifnot("value must be a column of the pacea_index object" =
Expand All @@ -116,6 +119,10 @@ plot.pacea_index <- function(obj,
stopifnot("event_lub needs to be a Date class (created using lubridate); can use event_years instead for annual events" =
"Date" %in% class(event_lub) | is.null(event_lub))

if(y_axis_reverse){
y_tick_by = - y_tick_by
}

obj_lub <- lubridate_pacea_series(obj = obj,
smooth_over_year = smooth_over_year)

Expand Down

0 comments on commit 867f341

Please sign in to comment.