James-Thorson-NOAA / FishStatsUtils

Shared resources for spatio-temporal models
GNU General Public License v3.0
10 stars 16 forks source link

plot_results() and plot_biomass_index() #74

Closed David-S-Hanisko-NOAA closed 3 years ago

David-S-Hanisko-NOAA commented 3 years ago

I recently updated VAST to the latest version using the development branches for VAST and FishStatUtils available on 06-05-2021. I came across the following error during one of my test runs. The error only seems to occur when the fitted model is set to any object other than ‘fit’. If, I have interpreted the code correctly it looks as if the ‘fit’ object is not passed to plot_biomass_index() from plot_result() so it appears to be referencing ‘fit’ from the global environment at line 160 (dev branch) in plot_biomass_index(). It also prevents plot_biomass_index() from running independently of plot_results(). Sorry to bring this up if it is by design.

I also had a question regarding potential changes to the output of Index.csv from plot_biomass_index(). Would it be possible to output an indicator for strata as well as category? My hack below appears to work at least for my limited testing.

Also in regards to index.csv, I noticed that the for the past several versions of VAST/FishStatUtils there appear to values outputted for years without any data. However, the corresponding plots have these years removed/set to NA. Would it make sense to have these years output to Index.csv as NA in cases where estimation of the missing years in not wanted?

Appreciate your feedback, please let me know if you would like session informaton, versions and logs.

Thanks for all the work keeping things not only up and running but with continued improvements.

Error when object is not ‘fit’ …

Making plot of abundance index

Not using bias-corrected estimates for abundance index (natural-scale)... Not using bias-corrected estimates for abundance index (log-scale)... *Error in units(fit$data_list$b_i/fit$data_list$a_i fit$extrapolation_list$Area_km2[1]) : object 'fit' not found** In addition: Warning message: In spTransform(xSP, CRSobj, ...) : NULL source CRS comment, falling back to PROJ string

adding strata to Index.csv

# Write to file 2
Table2 = NULL
  for( cI in 1:TmbData$n_c ){
    for( sI in 1:TmbData$n_l ){
      index_units = make_unit_label( u=units(Index_ctl), lab="", parse=FALSE )
      Tmp2 = data.frame( "Year"=year_labels, "Unit"=index_units, "Estimate"=as.vector(Index_ctl[cI,,sI,'Estimate']), "SD_log"=as.vector(log_Index_ctl[cI,,sI,'Std. Error']), "SD_mt"=as.vector(Index_ctl[cI,,sI,'Std. Error']) )
      if( TmbData$n_l > 1 ) Tmp2 = cbind( "Stratum"=strata_names[sI], Tmp2)
      if( TmbData$n_c > 1 ) Tmp2 = cbind( "Category"=category_names[cI], Tmp2)
      Table2 = rbind( Table2, Tmp2 )          
    }
  }
write.csv( Table2, file=paste0(DirName,"/Index_2.csv"), row.names=FALSE)
James-Thorson-NOAA commented 3 years ago

Sorry to be so slow in responding ... I think I fixed this by adding a new preferring input format to plot_biomass_index, as available in dev branch currently. thanks for flagging it!