Conversation
Dynamically plot timeseries of SPR quantities. Valid quantities include SPR, fishing intensity (1-SPR), or SPR Ratio (a potentially user defined SPR quantity.
Allow user to specify y-axis label in `plot_spr`. This is important so users can ammend the default labels, esepcially when SPR quantities are user defined.
1-spr is stored as "spr_report" within the SPR_SERIES module. Removed the explicit recalculation of it, and added "spr_report" explicitly to the label filter.
|
@Schiano-NOAA Do we want to add SPR tables to this PR? |
sbreitbart-NOAA
left a comment
There was a problem hiding this comment.
Thanks for working on this, @JZahner1! I've added some comments about how to update the section where the plot is exported. I'll let @Schiano-NOAA review the rest of the plot. Happy to answer questions here or in a meeting if that's easier.
@JZahner1 Just the plot please! If you want to make a table, it should be in a separate PR however I am not sure that's on our planned development list. |
Co-authored-by: Sophie Breitbart <sophie.breitbart@noaa.gov>
| ) { | ||
|
|
||
|
|
||
| quantity <- match.arg(quantity) |
There was a problem hiding this comment.
please adjust this so there is some default selection
| quantity <- match.arg(quantity) | |
| if (length(quantity) > 1 quantity <- "spr" else quantity <- match.arg(quantity) |
There was a problem hiding this comment.
or alternative put a warning that there is no selected quantity so when it fails if the user doesn't put something in there, they know what is going on
There was a problem hiding this comment.
@Schiano-NOAA Im pretty sure that R defaults to using the first element if a vector is set as a default parameter value. So if no value is provided, "spr" is used. I can certainly add that to the function documentation. Restricting multiple selections is a good idea though.
There was a problem hiding this comment.
Ah okay i was wondering if it did. I was testing it in line and and it didn't select one in the swtich but might behave differently within a function
There was a problem hiding this comment.
yah. match.arg doesn't really work outside of a function
There was a problem hiding this comment.
match.arg will take the first element of the vector provided in the function call specifications as the default. There is an internal argument to match.arg to not allow multiple selections, i.e., several.ok = FALSE.
There was a problem hiding this comment.
@kellijohnson-NOAA thanks for sharing! Does it throw an error if multiple options are provided but several.ok=FALSE or does it default back to the first valid option?
There was a problem hiding this comment.
It errors
calculate_stat <- function(x, type = c("mean", "median", "sd")) {
# 1. Validate the user input against the default vector options above
type <- match.arg(type, several.ok = FALSE)
# 2. Execute code based on the validated choice
switch(type,
mean = mean(x, na.rm = TRUE),
median = median(x, na.rm = TRUE),
sd = sd(x, na.rm = TRUE))
}
calculate_stat(1:10)
[1] 5.5
calculate_stat(1:10, type = c("mean", "median"))
Error in match.arg(type, several.ok = FALSE) : 'arg' must be of length 1
There was a problem hiding this comment.
@sbreitbart-NOAA @Schiano-NOAA is this behavior we want (e.g., throwing an error when multiple options are input), or do we want to fallback to the default "spr" quantity? Both seem equally reasonable to me.
There was a problem hiding this comment.
Hmm tough call. I think it would be good to fall back to the default and provide a warning message that it has > 1 selected so setting to default or you could set it to the first option provided.
Set SPR quantity to default value ("spr") if user specified more than 1 quantity in function call.
| dir = figures_dir, | ||
| scale_amount = scale_amount, | ||
| unit_label = unit_label | ||
| scale_amount = scale_amount |
There was a problem hiding this comment.
I don't see scale_amount set as an argument in the function and I don't think we want it?
| scale_amount = scale_amount | |
| scale_amount = 1 |
There was a problem hiding this comment.
This stopped me from creating an rda
There was a problem hiding this comment.
I originally commented (made a code "suggestion") where I tried to "suggest" removing the unit_label line. It may have gotten wonky and erased the scale_amount line. In any case, to be clear, the scale_amount line was originally = scale_amount and should remain that way (unless I'm missing something, @Schiano-NOAA ). The unit_label line can be deleted. So, it should look like this:
dat = dat,
dir = figures_dir,
scale_amount = scale_amount
)
}
There was a problem hiding this comment.
scale_amount isn't defined as a function input (i guess you can pass it as an extra parameter), so I dont think we can use do scale_amount=scale_amount here. Plus, for SPR, there are no units, so theres nothing to "scale" anyway.
There was a problem hiding this comment.
Yeah it should be changed to 1 as Josh did ⬆️
Co-authored-by: Sam (Schiano) Bredeck <125507018+Schiano-NOAA@users.noreply.github.com>
Schiano-NOAA
left a comment
There was a problem hiding this comment.
My apologies there is one more thing. This is not functional with BAM output. BAM contains "spr" so I am not sure why it's not working. I will send you an example file to test and work on
plot_sprallows for plotting a timeseries of spawning potential ratio (SPR) quantities.Users may specify one of three options to customize what quantity is plotted:
spr- spawning potential ratiofishing_intensity- fishing intensity, or 1-SPRspr_ratio- the quantity associated with the SPR derived quantity. For some model (e.g., SS3), this quantity may be customizable by the user.Some models may only plot
spr_ratiowith uncertainty intervals.