James-Thorson-NOAA / VAST

Spatio-temporal analysis of univariate or multivariate data, e.g., standardizing data for multiple species or stages
http://www.FishStats.org
GNU General Public License v3.0
124 stars 53 forks source link

tapply error in make_spatial_info #186

Open mkapur opened 5 years ago

mkapur commented 5 years ago

Possibly related to #176. I am using a custom strata, and have confirmed that colsums(extrap$a_el) does not equal zero for any region. At first I was getting zeros, but it seems like this can occur if your strata limits are nonsensical or your Data_Geostat does not have any observations for that region (correct)?

My main issue is that when I run FishStatsUtils::make_spatial_info I receive the following:

Error in tapply(a_el[, l], INDEX = factor(NN_Extrap$nn.idx, levels = 1:nrow(loc_x)),  : 
  arguments must have same length

I am not positive which arguments to check on. Let me know if I should move this to fishstatsutils, or if you need more than I have placed below. I understand you can't re-run it without my Data_Geostat but any pointers on things that may be mismatched might help. Thanks!

strata.limits <- data.frame(
  'STRATA' = c("R5","R4", "R3"),
  'west_border' = c(-180, -145, -143),
  'east_border' = c(-145, -144, -110),
  'north_border' = c(63, 63, 63),
  'south_border' = c(50, 50, 50) )

R345_Extrap <-
  make_extrapolation_info(
    Region = 'User',
    strata.limits = strata.limits,
    input_grid = data.frame(
      'Lon' = Data_Geostat$Lon,
      'Lat' = Data_Geostat$Lat,
      'Area_km2' = rep(4, nrow(Data_Geostat))
    )
  )
colSums( R345_Extrap$a_el ) #check area sums
   R5    R4    R3 
93368   352  2052

saveRDS(R345_Extrap, file = "./data/r345_extrap.rds")
Extrapolation_List <-  readRDS("./data/RDSFILES/R345_Extrap.rds") 

Spatial_List <- FishStatsUtils::make_spatial_info( grid_size_km=25, 
                                                  n_x=100, 
                                                  fine_scale=FALSE, 
                                                  Method=Method, 
                                                  Lon_i = Data_Geostat[,'Lon'], 
                                                  Lat_i =Data_Geostat[,'Lat'], 
                                                  LON_intensity=Extrapolation_List$Data_Extrap[which(Extrapolation_List$Data_Extrap[,'Include']==TRUE),'Lon'], 
                                                  LAT_intensity=Extrapolation_List$Data_Extrap[which(Extrapolation_List$Data_Extrap[,'Include']==TRUE),'Lat'],
                                                  Extrapolation_List=Extrapolation_List, DirPath=RunDir, Save_Results=TRUE )
James-Thorson-NOAA commented 5 years ago

Because you have make_spatial_info(..., Save_Results=TRUE), its possible that you have a Kmeans=X.RData saved in your working directory from an old run and its loading that and then confused about it. Please remove that file, retry and report back?

mkapur commented 5 years ago

Thanks for the quick reply, just tried that and got the same error unfortunately. It's a new directory each time so I don't think it is reading in something incorrectly. Let me know if there is something else I can check into.

James-Thorson-NOAA commented 5 years ago

I don't have any other ideas without looking at a minimal example.