Skip to content

Commit

Permalink
Dev (#77)
Browse files Browse the repository at this point in the history
* Improve rotate_factors...

... to allow working with projected values of factors

* small fix to plot_factors update...

... h/t Kristen Omori

* fix bug with many extrapolation-grid cells with Area=0...

... this issue arises e.g. with Region = "Other" and h/t Ellen Yasumiishi for flagging the issue!  the bug manifested in an uniformative error, so no change of previous users having untrustworthy results arising from it.

* fix bug in last commit

* update docs

* improve docs

* Enhance rotate_factors ...

... to work even when estimating a factor model where some factors have variance approaching zero.

* fix a plotting bug in `plot_factors` ...

... that arose when plotting factor-model Omegas

* fix to `plot_factors` when doing dual ordination

* Fix summary.fit_model( ..., what="residuals") ...

... in response to #72, h/t Nicholas Ducharme-Barthe for reporting the bug (which threw an uninformative error)

* Adding plots for spatially-varying catchability

* improve panel-labels in density plots

* add loc_s and latlon_s ...

... for potential future use in new feature for habitat-specific variance-covariance among variables

* fix typo in last commit

* fix typo in last commit

* Change default colors for plots ...

... and add option to calculate subarea totals using Longitude for Region="eastern_bering_sea"

* adding units package

* update docs

* adding amend_output ...

... which labels Report for use in subsequent plotting

* Fix bug in fit_model ...

... caused during earlier push

* Improve `amend_output`

* Update plot_biomass_index ...

... to use metadata_ctz, and deprecate compatibility with MIST and SpatialDeltaGLMM

* fix new bug in plot_biomass_index ...

... introduced a couple commits earlier in dev branch; also improve stability for DHARMa using PIT residuals

* Continue to improve stability for DHARMa residuals ...

... see discussion here: florianhartig/DHARMa#286

* update plots

* Change make_covariates ...

... to avoid passing unnecessarily large X_itp object, which exceeded R memory limits in some extreme cases

* small update ...

... to deal with amend_output change where Density=0 such that log(Density) = -Inf, which was causing plotting problems

* Update deprecated.R functions for old diagnostic plots ...

... to deal with case of not specifying explicit units

* various updates to doxygen reference docs

* Update deprecated.R

* Update deprecated.R

* fix DHARMa residuals when b_i=NA, and improve plot_data(.) to work with projargs

* fix bug in dev-changes for project_coordinates

* fix bugs in dev-branch for plot_data

* improve DHARMa plots ...

... by removing useless p-values

* fix dev-branch bug in plot_biomass_index ...

... which now requires `extrapolation_list` to pull appropriate units for plot

* adding West Coast Groundfish combo survey ...

... to VAST shapefiles

* small style-guide improvements

* Improve default labelling in plots ...

... by calling `amend_output` within `plot_maps`

* Avoid crash in `plot_maps` ...

... when asking to plot variable that is excluded from model

* Fix annoying warnings about PROJ.4

* Eliminate (most) annoying warnings from PROJ.4

* small fixes ..

... to eliminate remaining PROJ.4 warnings, and fix plotting crash regarding contours in missing variables

* small fix ...

... to allow for passing a color function `col` to `plot.fit_model`

* remove dependency `plotKML` with `raster`

h/t @Jason-Conner-NOAA for pointing out that `plotKML` was removed from CRAN

* fix bug in last commit

* Simplify plot_biomass_index ...

... by incorporating `amend_output` into function

* fit issues in last committ ...

... such that amend_output is now responsible for handing units

* adding units for mean_Z_ctm ...

... extracted using `sf` which is now a dependency

* Fix use of units for range-shift metrics

* fix bug in recent commit ...

... which caused `plot_maps` to not plot SEs properly by default

* update docs

* fix bug in amend_outputs ...

... regarding optional Report slot `mean_D_ctl`

* update docs
  • Loading branch information
James-Thorson-NOAA authored Oct 29, 2021
1 parent 80d5cbe commit 132ae46
Show file tree
Hide file tree
Showing 58 changed files with 1,386 additions and 693 deletions.
14 changes: 8 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: FishStatsUtils
Type: Package
Title: Utilities (shared code and data) for FishStats spatio-temporal modeling toolbox
Version: 2.9.1
Date: 2021-03-16
Version: 2.10.0
Date: 2021-10-29
Authors@R:
c(person(given = "James",
family = "Thorson",
Expand All @@ -28,7 +28,8 @@ Imports:
devtools,
mixtools,
sp,
plotKML,
sf,
raster,
plotrix,
TMB,
MatrixModels,
Expand All @@ -45,7 +46,8 @@ Imports:
DHARMa,
viridisLite
Depends:
R (>= 3.5.0)
R (>= 3.5.0),
units
Suggests:
testthat
Remotes:
Expand All @@ -56,5 +58,5 @@ LazyData: yes
BuildVignettes: yes
Encoding: UTF-8
RoxygenNote: 7.1.1
URL: http://github.com/james-thorson/FishStatsUtils
BugReports: http://github.com/james-thorson/FishStatsUtils/issues
URL: http://github.com/james-thorson-NOAA/FishStatsUtils
BugReports: http://github.com/james-thorson-NOAA/FishStatsUtils/issues
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export(Prepare_WCGBTS_Extrapolation_Data_Fn)
export(Prepare_WCGHL_Extrapolation_Data_Fn)
export(Print_Message)
export(Rotate_Fn)
export(amend_output)
export(calc_cov)
export(calculate_proportion)
export(combine_extrapolation_info)
Expand All @@ -57,6 +58,7 @@ export(plot_anisotropy)
export(plot_biomass_index)
export(plot_cov)
export(plot_data)
export(plot_dharma)
export(plot_encounter_diagnostic)
export(plot_factors)
export(plot_index)
Expand All @@ -76,4 +78,5 @@ export(project_coordinates)
export(rotate_factors)
export(sample_variable)
export(simulate_data)
export(strip_units)
export(summarize_covariance)
2 changes: 1 addition & 1 deletion R/Prepare_XXXX_Extrapolation_Data_Fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function( strata.limits=NULL, projargs=NA, zone=NA, flip_around_dateline=TRUE, .
Area_km2_x = Data_Extrap[,'Area_in_survey_km2']

# Augment with strata for each extrapolation cell
Tmp = cbind("BEST_DEPTH_M"=0, "BEST_LAT_DD"=Data_Extrap[,'Lat'], "propInSurvey"=1)
Tmp = cbind("BEST_DEPTH_M"=0, "BEST_LON_DD"=Data_Extrap[,'Lon'], "BEST_LAT_DD"=Data_Extrap[,'Lat'], "propInSurvey"=1)
a_el = as.data.frame(matrix(NA, nrow=nrow(Data_Extrap), ncol=nrow(strata.limits), dimnames=list(NULL,strata.limits[,'STRATA'])))
for(l in 1:ncol(a_el)){
a_el[,l] = apply(Tmp, MARGIN=1, FUN=match_strata_fn, strata_dataframe=strata.limits[l,,drop=FALSE])
Expand Down
161 changes: 161 additions & 0 deletions R/amend_output.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@


#' Amend output from VAST for user convenience
#'
#' \code{amend_output} add labels, units, and performs logical operations,
#' e.g., adds zeros as needed, to simplify user and downstream interpretation.
#'
#' @export
amend_output <-
function( fit = NULL,
TmbData = fit$data_list,
Report = fit$Report,
extrapolation_list = fit$extrapolation_list,
Map = fit$tmb_list$Map,
Sdreport = fit$parameter_estimates$SD,
year_labels = fit$year_labels,
category_names = fit$category_names,
strata_names = fit$strata_names ){

# Local functions
add_dimnames = function( Report, report_names, dimnames ){
for( i in seq_along(report_names) ){
if( report_names[i] %in% names(Report) ){
dimnames(Report[[report_names[i]]]) = dimnames
}
}
return(Report)
}

# Defaults
if( "treat_nonencounter_as_zero" %in% names(TmbData$Options_list$Options) ){
treat_missing_as_zero = TmbData$Options_list$Options["treat_nonencounter_as_zero"]
}else{
treat_missing_as_zero = FALSE
}

# Local function
process_labels = function( labels, prefix, length ){
if(is.null(labels)){
labels = paste0( prefix, "_", seq_len(length) )
}else{
if(length(labels)!=length) stop("Check labels")
}
return(labels)
}

# Fill in missing inputs
if( "D_xt" %in% names(Report)){
# SpatialDeltaGLMM
year_labels = process_labels( year_labels, "Time", ncol(Report$D_xt) )
category_names = "singlespecies"
}
if( "D_xct" %in% names(Report)){
# VAST Version < 2.0.0
year_labels = process_labels( year_labels, "Time", dim(Report$D_xct)[3] )
category_names = process_labels( category_names, "Category", dim(Report$D_xct)[2] )
}
if( "D_xcy" %in% names(Report)){
# VAST Version >= 2.0.0
year_labels = process_labels( year_labels, "Time", dim(Report$D_xcy)[3] )
category_names = process_labels( category_names, "Category_", dim(Report$D_xcy)[2] )
}
if( "D_gcy" %in% names(Report)){
# VAST Version 8.0.0 through 9.3.0
year_labels = process_labels( year_labels, "Time", dim(Report$D_gcy)[3] )
category_names = process_labels( category_names, "Category", dim(Report$D_gcy)[2] )
}
if( "D_gct" %in% names(Report)){
# VAST Version >= 9.4.0
year_labels = process_labels( year_labels, "Time", dim(Report$D_gct)[3] )
category_names = process_labels( category_names, "Category", dim(Report$D_gct)[2] )
}
if("dhat_ktp" %in% names(Report)){
# MIST Version <= 14
year_labels = process_labels( year_labels, "Time", dim(Report$dhat_ktp)[2] )
category_names = process_labels( category_names, "Category", dim(Report$dhat_ktp)[3] )
}
if("dpred_ktp" %in% names(Report)){
# MIST Version >= 15
year_labels = process_labels( year_labels, "Time", dim(Report$dpred_ktp)[2] )
category_names = process_labels( category_names, "Category", dim(Report$dpred_ktp)[3] )
}
strata_names = process_labels( strata_names, "Stratum", dim(Report$Index_ctl)[3] )

# Determine year-category pairs with no data
Num_gct = rep(1,TmbData$n_g) %o% abind::adrop(TmbData$Options_list$metadata_ctz[,,'num_notna',drop=FALSE], drop=3)
Num_ctl = abind::adrop(TmbData$Options_list$metadata_ctz[,,'num_notna',drop=FALSE], drop=3) %o% rep(1,TmbData$n_l)
Num_ctm = abind::adrop(TmbData$Options_list$metadata_ctz[,,'num_notna',drop=FALSE], drop=3) %o% rep(1,TmbData$n_m)
if( treat_missing_as_zero==TRUE ){
# if treat_missing_as_zero==TRUE, then switch density from year-categories with no data to zero
Report$D_gct = ifelse(Num_gct==0, 0, Report$D_gct)
Report$Index_ctl = ifelse(Num_ctl==0, 0, Report$Index_ctl)
}else{
# If some intercepts are mapped off, then switch density from year-categories with no data to NA
if( any(is.na(Map$beta2_ft)) | any(is.na(Map$beta2_ft)) ){
Report$D_gct = ifelse(Num_gct==0, NA, Report$D_gct)
Report$Index_ctl = ifelse(Num_ctl==0, NA, Report$Index_ctl)
}
}

# No need to map off spatial statistics mean_Z_ctm or effective_area_ctl in any years
# These are valid when betas are mapped off, or even when epsilons are mapped off given the potential covariates
#if( any(is.na(Map$beta2_ft)) | any(is.na(Map$beta2_ft)) ){
# if("mean_Z_ctm" %in% names(Report)) Report$mean_Z_ctm = ifelse(Num_ctm==0, NA, Report$mean_Z_ctm)
# if("effective_area_ctl" %in% names(Report)) Report$effective_area_ctl = ifelse(Num_ctl==0, NA, Report$effective_area_ctl)
#}

# Add labels for all variables plotted using `plot_maps`
Report = add_dimnames( Report = Report,
report_names = c("P1_gct","P2_gct","R1_gct","R2_gct","D_gct","Epsilon1_gct","Epsilon2_gct","eta1_gct","eta2_gct"),
dimnames = list(NULL, "Category"=category_names, "Time"=year_labels) )
Report = add_dimnames( Report = Report,
report_names = c("Omega1_gc","Omega2_gc"),
dimnames = list(NULL, "Category"=category_names) )
Report = add_dimnames( Report = Report,
report_names = "Xi1_gcp",
dimnames = list(NULL, "Category"=category_names, "Covariate"=colnames(TmbData$X1_ip)) )
Report = add_dimnames( Report = Report,
report_names = "Xi2_gcp",
dimnames = list(NULL, "Category"=category_names, "Covariate"=colnames(TmbData$X2_ip)) )
Report = add_dimnames( Report = Report,
report_names = "Phi1_gk",
dimnames = list(NULL, "Covariate"=colnames(TmbData$Q1_ik)) )
Report = add_dimnames( Report = Report,
report_names = "Phi2_gk",
dimnames = list(NULL, "Covariate"=colnames(TmbData$Q2_ik)) )

# Add labels for other useful variables
Report = add_dimnames( Report = Report,
report_names = c("Index_ctl","effective_area_ctl","mean_D_ctl"),
dimnames = list("Category"=category_names, "Time"=year_labels, "Stratum"=strata_names) )
Report = add_dimnames( Report = Report,
report_names = "mean_Z_ctm",
dimnames = list("Category"=category_names, "Time"=year_labels, colnames(TmbData$Z_gm)) )

# Modify Sdreport
if( !is.null(Sdreport) ){
# See plot_biomass_index for how to efficiently use and combine SEs
}

# Add units
units(Report$Index_ctl) = units(TmbData$b_i / TmbData$a_i * extrapolation_list$Area_km2[1])
units(Report$D_gct) = units(TmbData$b_i)

# Add units for COG, see: https://github.com/r-quantities/units/issues/291
# In case of re-running amend_output on objects with existing units
if( "mean_Z_ctm" %in% names(Report) ){
units(Report$mean_Z_ctm) = as_units("km")
}
if( "mean_D_ctl" %in% names(Report) ){
units(Report$mean_D_ctl) = units(TmbData$b_i)
}
if( "effective_area_ctl" %in% names(Report) ){
#units(Report$effective_area_ctl) = paste0( sf::st_crs( extrapolation_list$projargs )$units, "^2" )
units(Report$effective_area_ctl) = as_units("km^2")
}

# Check for bad entries
return( Report )
}

1 change: 1 addition & 0 deletions R/convert_shapefile.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ convert_shapefile = function( file_path,
... ){

shapefile_input = rgdal::readOGR( file_path, verbose=FALSE, p4s=projargs_for_shapefile )
# rgdal::writeOGR
message("Reading shapefile with projargs: ", print(shapefile_input@proj4string))
# raster::shapefile(.) has simplified read-write interface for future reference
if( !(shapefile_input@class %in% c("SpatialPolygonsDataFrame","SpatialPolygons")) ){
Expand Down
30 changes: 15 additions & 15 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,12 @@ Plot_range_quantiles = function( Data_Extrap, Report, TmbData, a_xl, NN_Extrap,
}

# Extrapolation locations
Data_Extrap_Range = cbind( Data_Extrap[,c('Lat','Lon','N_km','E_km')], 'Include'=ifelse(Data_Extrap[,'Area_km2']>0, TRUE, FALSE) )
Data_Extrap_Range = cbind( Data_Extrap[,c('Lat','Lon','N_km','E_km')], 'Include'=ifelse(strip_units(Data_Extrap[,'Area_km2'])>0, TRUE, FALSE) )
# Add and rescale density
for(t in 1:length(Year_Set)){
Data_Extrap_Range = cbind( Data_Extrap_Range, Report$Index_xtl[NN_Extrap$nn.idx,t,1] * (Data_Extrap[,'Area_km2'] / a_xl[NN_Extrap$nn.idx,1]) )
Data_Extrap_Range = cbind( Data_Extrap_Range, Report$Index_xtl[NN_Extrap$nn.idx,t,1] * (strip_units(Data_Extrap[,'Area_km2']) / a_xl[NN_Extrap$nn.idx,1]) )
colnames( Data_Extrap_Range )[ncol(Data_Extrap_Range)] = paste0("Year_",Year_Set[t])
Data_Extrap_Range[,paste0("Year_",Year_Set[t])] = ifelse( Data_Extrap[,'Area_km2']==0 & a_xl[NN_Extrap$nn.idx,1]==0, 0, Data_Extrap_Range[,paste0("Year_",Year_Set[t])])
Data_Extrap_Range[,paste0("Year_",Year_Set[t])] = ifelse( strip_units(Data_Extrap[,'Area_km2'])==0 & a_xl[NN_Extrap$nn.idx,1]==0, 0, Data_Extrap_Range[,paste0("Year_",Year_Set[t])])
}

# Plot
Expand Down Expand Up @@ -1559,7 +1559,7 @@ plot_quantile_diagnostic <- function(TmbData,
}

# Find where b_i > 0 within category i_e
Which = which(TmbData$b_i > 0 & e_i == (i_e-1))
Which = which(strip_units(TmbData$b_i) > 0 & e_i == (i_e-1))
Q = rep(NA, length(Which)) # vector to track quantiles for each observation
y = array(NA, dim=c(length(Which),1000)) # matrix to store samples
pred_y = var_y = rep(NA, length(Which) ) # vector to track quantiles for each observation
Expand All @@ -1577,27 +1577,27 @@ plot_quantile_diagnostic <- function(TmbData,
}
if( length(ObsModel_ez[i_e,])==1 || ObsModel_ez[i_e,2]%in%c(0,3) ){
for(ObsI in 1:length(Which)){
pred_y[ObsI] = TmbData$a_i[Which[ObsI]] * exp(Report$P2_i[Which[ObsI]])
pred_y[ObsI] = strip_units(TmbData$a_i[Which[ObsI]]) * exp(Report$P2_i[Which[ObsI]])
}
}
if( length(ObsModel_ez[i_e,])>=2 && ObsModel_ez[i_e,2]%in%c(1,4) ){
for(ObsI in 1:length(Which)){
if(sigmaM[e_i[Which[ObsI]]+1,3]!=1) stop("`QQ_Fn` will not work with Poisson-link delta model across all VAST versions given values for turned-off parameters")
R1_i = 1 - exp( -1 * sigmaM[e_i[Which[ObsI]]+1,3] * TmbData$a_i[Which[ObsI]] * exp(Report$P1_i[Which[ObsI]]) )
pred_y[ObsI] = TmbData$a_i[Which[ObsI]] * exp(Report$P1_i[Which[ObsI]]) / R1_i * exp(Report$P2_i[Which[ObsI]]);
R1_i = 1 - exp( -1 * sigmaM[e_i[Which[ObsI]]+1,3] * strip_units(TmbData$a_i[Which[ObsI]]) * exp(Report$P1_i[Which[ObsI]]) )
pred_y[ObsI] = strip_units(TmbData$a_i[Which[ObsI]]) * exp(Report$P1_i[Which[ObsI]]) / R1_i * exp(Report$P2_i[Which[ObsI]]);
}
}

# Simulate quantiles for different distributions: Loop through observations
for(ObsI in 1:length(Which)){
if(ObsModel_ez[i_e,1]==1){
y[ObsI,] = rlnorm(n=ncol(y), meanlog=log(pred_y[ObsI])-pow(sigmaM[i_e,1],2)/2, sdlog=sigmaM[i_e,1]) # Plotting in log-space
Q[ObsI] = plnorm(q=TmbData$b_i[Which[ObsI]], meanlog=log(pred_y[ObsI])-pow(sigmaM[i_e,1],2)/2, sdlog=sigmaM[i_e,1])
Q[ObsI] = plnorm(q=strip_units(TmbData$b_i[Which[ObsI]]), meanlog=log(pred_y[ObsI])-pow(sigmaM[i_e,1],2)/2, sdlog=sigmaM[i_e,1])
}
if(ObsModel_ez[i_e,1]==2){
b = pow(sigmaM[i_e, 1],2) * pred_y[ObsI];
y[ObsI,] = rgamma(n=ncol(y), shape=1/pow(sigmaM[i_e,1],2), scale=b)
Q[ObsI] = pgamma(q=TmbData$b_i[Which[ObsI]], shape=1/pow(sigmaM[i_e,1],2), scale=b)
Q[ObsI] = pgamma(q=strip_units(TmbData$b_i[Which[ObsI]]), shape=1/pow(sigmaM[i_e,1],2), scale=b)
}
}

Expand All @@ -1612,7 +1612,7 @@ plot_quantile_diagnostic <- function(TmbData,
Quantiles = quantile(y[ObsI,],prob=c(0.025,0.25,0.75,0.975))
lines(x=c(ObsI,ObsI), y=Quantiles[2:3], lwd=2)
lines(x=c(ObsI,ObsI), y=Quantiles[c(1,4)], lwd=1,lty="dotted")
if(TmbData$b_i[Which[ObsI]]>max(Quantiles) | TmbData$b_i[Which[ObsI]]<min(Quantiles)){
if( strip_units(TmbData$b_i[Which[ObsI]])>max(Quantiles) | strip_units(TmbData$b_i[Which[ObsI]])<min(Quantiles)){
points(x=ObsI,y=TmbData$b_i[Which[ObsI]],pch=4,col="red",cex=2)
}
}
Expand Down Expand Up @@ -1696,8 +1696,8 @@ plot_residuals = function( Lat_i, Lon_i, TmbData, Report, Q, projargs='+proj=lon
which_i_in_y = which( apply(which_i_in_y,MARGIN=1,FUN=all) )
if( length(which_i_in_y)>0 ){
exp_rate_xy[,yI] = tapply( Report$R1_i[which_i_in_y], INDEX=factor(spatial_list$knot_i[which_i_in_y],levels=1:spatial_list$n_x), FUN=mean )
obs_rate_xy[,yI] = tapply( TmbData$b_i[which_i_in_y]>0, INDEX=factor(spatial_list$knot_i[which_i_in_y],levels=1:spatial_list$n_x), FUN=mean )
total_num_xy[,yI] = tapply( TmbData$b_i[which_i_in_y], INDEX=factor(spatial_list$knot_i[which_i_in_y],levels=1:spatial_list$n_x), FUN=length )
obs_rate_xy[,yI] = tapply( strip_units(TmbData$b_i[which_i_in_y])>0, INDEX=factor(spatial_list$knot_i[which_i_in_y],levels=1:spatial_list$n_x), FUN=mean )
total_num_xy[,yI] = tapply( strip_units(TmbData$b_i[which_i_in_y]), INDEX=factor(spatial_list$knot_i[which_i_in_y],levels=1:spatial_list$n_x), FUN=length )
}else{
total_num_xy[,yI] = 0
}
Expand All @@ -1722,7 +1722,7 @@ plot_residuals = function( Lat_i, Lon_i, TmbData, Report, Q, projargs='+proj=lon

# Extract quantile for positive catch rates
#Q_i = Q[["Q"]]
which_pos = which(TmbData$b_i>0)
which_pos = which( strip_units(TmbData$b_i)>0 )
bvar_ipos = bpred_ipos = NULL
# Univariate Q interface
if( all(c("var_y","pred_y") %in% names(Q)) ){
Expand Down Expand Up @@ -1763,7 +1763,7 @@ plot_residuals = function( Lat_i, Lon_i, TmbData, Report, Q, projargs='+proj=lon
which_ipos_in_y = ( TmbData$t_iz[which_pos,] == outer(rep(1,length(which_pos)),TmbData$t_yz[yI,]) )
which_ipos_in_y = which( apply(which_ipos_in_y,MARGIN=1,FUN=all) )
if( length(which_i_in_y_and_pos)>0 ){
sum_obs_xy[,yI] = tapply( TmbData$b_i[which_i_in_y_and_pos], INDEX=factor(spatial_list$knot_i[which_i_in_y_and_pos],levels=1:spatial_list$n_x), FUN=sum )
sum_obs_xy[,yI] = tapply( strip_units(TmbData$b_i[which_i_in_y_and_pos]), INDEX=factor(spatial_list$knot_i[which_i_in_y_and_pos],levels=1:spatial_list$n_x), FUN=sum )
sum_exp_xy[,yI] = tapply( bpred_ipos[which_ipos_in_y], INDEX=factor(spatial_list$knot_i[which_i_in_y_and_pos],levels=1:spatial_list$n_x), FUN=sum )
var_exp_xy[,yI] = tapply( bvar_ipos[which_ipos_in_y], INDEX=factor(spatial_list$knot_i[which_i_in_y_and_pos],levels=1:spatial_list$n_x), FUN=sum )
}
Expand Down Expand Up @@ -1794,7 +1794,7 @@ plot_residuals = function( Lat_i, Lon_i, TmbData, Report, Q, projargs='+proj=lon
# Spatial information
# Aggregate residual-values to knots regardless of value for fine_scale
x2i = spatial_list$NN_Extrap$nn.idx[,1]
Include = extrapolation_list[["Area_km2_x"]]>0 & extrapolation_list[["a_el"]][,1]>0
Include = strip_units(extrapolation_list[["Area_km2_x"]])>0 & strip_units(extrapolation_list[["a_el"]][,1])>0
DF = cbind( extrapolation_list$Data_Extrap[,c('Lon','Lat')], "x2i"=x2i, "Include"=Include )

# Fill in labels
Expand Down
Loading

0 comments on commit 132ae46

Please sign in to comment.