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

Plot biomass index #39

Closed
wants to merge 4 commits into from
Closed

Plot biomass index #39

wants to merge 4 commits into from

Conversation

chantelwetzel-noaa
Copy link
Contributor

A few updates were needed to align with the latest version of VAST. The branch fixed the following items:

  1. Correct names and function arguments to read and create index plots
  2. Added the specifications for the tweedie distribution in the summary_nwfsc function
  3. Modified the ss_plot function to use red for CA, purple for OR, and blue for WA in order to align better with temperature gradients along the West Coast.

@kellijohnson-NOAA
Copy link
Contributor

Thanks @chantelwetzel-noaa for these edits! Super helpful. I peaked at some of them yesterday so I have an initial question ... do we care that these are breaking changes and now the plotting won't work with older saved output?

@chantelwetzel-noaa
Copy link
Contributor Author

That is a great question and was going to leave it up to you decide. I created the pull request to ensure that you saw these changes and did not go through the work to figure out them on your own. Personally, I suspect the frequency of people wanting to replot old runs is fairly low.

@kellijohnson-NOAA
Copy link
Contributor

Yeah, I do not want to open any old runs that is for sure. And, if we were too open an old run, I am guessing that the csv of model output is going to be the only thing that is of real interest.

Copy link
Contributor

@kellijohnson-NOAA kellijohnson-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chantel - thank you so much for all of these proposed changes. There are a few that are absolutely necessary and a few that I think need modifications. Let me know how you want to proceed from here and if any of my comments do not make sense.

@@ -42,7 +42,8 @@ summary_nwfsc <- function(obj, parameter_estimates, savedir = NULL) {
"Poisson-link",
switch(as.character(obj$env$data$ObsModel[1]),
"1" = "Lognormal",
"2" = "Gamma")))
"2" = "Gamma",
"10" = "Tweedie")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also add this distribution to obs_model in VAST_spp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I only changed it where the code broke. In addition to adding this to the VAST_spp function the other setting that is required with tweedie is:

rho_config = c(Beta1 = 3, Beta2 = 0, Epsilon1 = 0, Epsilon2 = 0)
field = c(Omega1 = 0, Epsilon1 = 0, Omega2 = "IID", Epsilon2 = "IID")

which is then passed into the settings. I think adding a check or setting these two items to match these settings by default when using the tweedie might be helpful for users.

FieldConfig = settings[["FieldConfig"]],
RhoConfig = settings[["RhoConfig"]],
OverdispersionConfig = settings[["overdispersion"]],
ObsModel = settings[["ObsModelcondition"]],
bias.correct = TRUE,
#calculate derived quantities of interest, no harm
#Options = ,#default is more than original VASTWestCoast
#use_anisotropy = TRUE, #default
#use_anisotropy = settings[["use_anistrophy"]], #default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to leave this commented out? I was using comments with default values listed for VAST just so that I knew what the default was. Also needs to be added to the default settings list in get_settings().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I missed that this was still in there. I did this while trying to troubleshoot why my tweedie model would not run so I was exploring controlling whether the anisotropy was on or off.

@@ -73,15 +73,15 @@ VAST_do <- function(Database, settings, conditiondir, compiledir,
purpose = "index2",
fine_scale = settings[["fine_scale"]],
strata.limits = settings[["strata"]],
#zone = NA, #default
zone = settings[["zone"]], #default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting needs to be added to the default setting list in get_settings().

@@ -135,28 +135,32 @@ VAST_do <- function(Database, settings, conditiondir, compiledir,
save(list = ls(all.names = TRUE), file = file.path(conditiondir, "Save.RData"))
return(out)
}
save(list = ls(all.names = TRUE), file = file.path(conditiondir, "Save.RData"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The objects are saved at the end of the function. I am assuming that you added this here just because the errors in plots were causing things to not be saved. I think that it is better to just fix the plots and save things at the end rather than save all present objects and save them again. So, I recommend removing this change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the if statement above to include a check to see if the estimates of standard error are present as well and if not then exit early.
if ("simpleError" %in% class(out) | is.null(out$parameter_estimates$SD) ) {


maps <- tryCatch(suppressWarnings(FishStatsUtils::plot_results(settings = info, fit = out,
working_dir = file.path(conditiondir, .Platform$file.sep),
check_residuals = TRUE)),
error = function(e) e)

index <- suppressWarnings(FishStatsUtils::plot_biomass_index(
fit = out,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this should fix #41.

@@ -66,11 +66,11 @@ plot_index <- function(dir, recursive = TRUE, area = NULL, filter = NULL,
basename(dirname(files)), SIMPLIFY = FALSE))

#subset data and calculate confidence intervals
if (is.null(keepyears)) keepyears <- unique(data[, "Year"])
data <- data[data[, "Year"] %in% keepyears, ]
if (is.null(keepyears)) keepyears <- unique(data[, "Time"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really want to use "Time_1", etc. for plotting?

@@ -52,7 +52,7 @@ plot_index <- function(dir, recursive = TRUE, area = NULL, filter = NULL,

#get the index information that is saved to the disk
dir <- normalizePath(dir, mustWork = TRUE)
files <- dir(dir, pattern = "Table_for_SS3", full.names = TRUE,
files <- dir(dir, pattern = "Index", full.names = TRUE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there would be less changes if we just used "our" Table_for_SS3" rather than the automated Index.csv. That way only the csv would need to be saved and all downstream code would work b/c the csv would have the previously utilized column names. This is different than what I said in our previous chat, but I think rather than changing given that Jim doesn't use years that we should just use what we had before.

@kellijohnson-NOAA
Copy link
Contributor

I have partitioned out of the required changes into individual commits along with some other needed changes in the branch fix_2022update.
Can you create a single commit on the master branch or in a new branch (with a pull request) for the color changes? Then we can just close this pull request?

kellijohnson-NOAA added a commit that referenced this pull request Apr 15, 2022
Changes to VAST and FishStatsUtils that create the file
Index rather than Table_for_SS3 led to column name changes.
These legacy columns are easily recreated and saved similar to
the old table in Table_for_SS3.csv to allow downstream code to work.
This change was discussed in #39 with great changes made by
@chantelwetzel-noaa but we decided to go with the simpler change here
rather than changing the column names of everything in VASTWestCoast
which would also lead to code changes that would be needed for
assessment purposes.
@chantelwetzel-noaa
Copy link
Contributor Author

As always, I am not sure if I followed instructions correctly (I am a git problem). I made a color change commit to the new "fix_2022update" branch. After re-reading your instructions again, I don't think this is exactly what you were looking for, but hopefully the way I did it was ok. I am going to now close this pull request.

@kellijohnson-NOAA
Copy link
Contributor

No worries @chantelwetzel-noaa committing to the fix_2022update is just fine. I am also going to delete the plot_biomass_index branch now.

@kellijohnson-NOAA kellijohnson-NOAA deleted the plot_biomass_index branch April 15, 2022 14:57
kellijohnson-NOAA added a commit that referenced this pull request Apr 15, 2022
Changes to VAST and FishStatsUtils that create the file
Index rather than Table_for_SS3 led to column name changes.
These legacy columns are easily recreated and saved similar to
the old table in Table_for_SS3.csv to allow downstream code to work.
This change was discussed in #39 with great changes made by
@chantelwetzel-noaa but we decided to go with the simpler change here
rather than changing the column names of everything in VASTWestCoast
which would also lead to code changes that would be needed for
assessment purposes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants