diff --git a/R/Calc_Anisotropic_Mesh.R b/R/Calc_Anisotropic_Mesh.R index ff428d5..24bb276 100644 --- a/R/Calc_Anisotropic_Mesh.R +++ b/R/Calc_Anisotropic_Mesh.R @@ -26,7 +26,7 @@ function(loc_x, loc_g, loc_i, Method, Extrapolation_List, anisotropic_mesh=NULL, } }else{ loc_z = rbind( loc_x, loc_g, loc_i ) - outer_hull = INLA::inla.nonconvex.hull(loc_i, convex = -0.05, concave = -0.05) + outer_hull = INLA::inla.nonconvex.hull( as.matrix(loc_z), convex = -0.05, concave = -0.05) anisotropic_mesh = INLA::inla.mesh.create( loc_x, plot.delay=NULL, refine=refine, boundary=outer_hull, ...) } diff --git a/R/Convert_LL_to_UTM_Fn.R b/R/Convert_LL_to_UTM_Fn.R index 15fe087..1d495a3 100644 --- a/R/Convert_LL_to_UTM_Fn.R +++ b/R/Convert_LL_to_UTM_Fn.R @@ -21,7 +21,7 @@ function( Lon, Lat, zone=NA, flip_around_dateline=FALSE ){ # Convert # if zone=NA or NULL, then it automatically detects appropriate zone Tmp = cbind('PID'=1,'POS'=1:length(Lon),'X'=Lon,'Y'=Lat) - if( flip_around_dateline==TRUE ) Tmp[,'X'] = 180 + ifelse( Tmp[,'X']>0, Tmp[,'X']-360, Tmp[,'X']) + if( flip_around_dateline==TRUE ) Tmp[,'X'] = ifelse( Tmp[,'X']>0, Tmp[,'X']-180, Tmp[,'X']+180) attr(Tmp,"projection") = "LL" attr(Tmp,"zone") = zone tmpUTM = PBSmapping::convUL(Tmp) #$ diff --git a/R/Prepare_AI_Extrapolation_Data_Fn.R b/R/Prepare_AI_Extrapolation_Data_Fn.R index 4bbcef0..b742734 100644 --- a/R/Prepare_AI_Extrapolation_Data_Fn.R +++ b/R/Prepare_AI_Extrapolation_Data_Fn.R @@ -12,7 +12,6 @@ function( strata.limits=NULL, zone=NA, flip_around_dateline=TRUE, ... ){ Data_Extrap <- aleutian_islands_grid # Survey areas - #Area_km2_x = 4 * 1.852^2 * ifelse( Data_Extrap[,'EBS_STRATUM']!=0, 1, 0 ) Area_km2_x = Data_Extrap[,'Area_km2'] # Augment with strata for each extrapolation cell diff --git a/R/Prepare_NZ_Extrapolation_Data_Fn.R b/R/Prepare_NZ_Extrapolation_Data_Fn.R index 03253fe..f1018bf 100644 --- a/R/Prepare_NZ_Extrapolation_Data_Fn.R +++ b/R/Prepare_NZ_Extrapolation_Data_Fn.R @@ -8,13 +8,8 @@ function( strata.limits=NULL, zone=NA, survey="Chatham_rise", flip_around_dateli message("Using strata ", strata.limits) # Read extrapolation data - if( is.null(Data) ){ - utils::data( chatham_rise_grid, package="FishStatsUtils" ) - Data_Extrap <- chatham_rise_grid - }else{ - #stop( "Survey doesn't match New Zealand grid options" ) - Data_Extrap <- Data - } + utils::data( chatham_rise_grid, package="FishStatsUtils" ) + Data_Extrap <- chatham_rise_grid # Survey areas #Area_km2_x = 4 * 1.852^2 * ifelse( Data_Extrap[,'EBS_STRATUM']!=0, 1, 0 ) @@ -29,9 +24,9 @@ function( strata.limits=NULL, zone=NA, survey="Chatham_rise", flip_around_dateli } # Convert extrapolation-data to an Eastings-Northings coordinate system - if( is.numeric(zone) ){ - tmpUTM = Convert_LL_to_UTM_Fn( Lon=Data_Extrap[,'Lon'], Lat=Data_Extrap[,'Lat'], zone=zone, flip_around_dateline=flip_around_dateline) #$ - colnames(tmpUTM) = c('E_km','N_km') + if( is.na(zone) || is.numeric(zone) ){ + tmpUTM = Convert_LL_to_UTM_Fn( Lon=Data_Extrap[,'Lon'], Lat=Data_Extrap[,'Lat'], zone=zone, flip_around_dateline=flip_around_dateline) + colnames(tmpUTM)[3:4] = c('E_km','N_km') }else{ tmpUTM = Convert_LL_to_EastNorth_Fn( Lon=Data_Extrap[,'Lon'], Lat=Data_Extrap[,'Lat'], crs=zone ) } diff --git a/R/make_spatial_info.R b/R/make_spatial_info.R index 31363d2..6e1de52 100644 --- a/R/make_spatial_info.R +++ b/R/make_spatial_info.R @@ -58,6 +58,7 @@ make_spatial_info = function( n_x, Lon_i, Lat_i, Extrapolation_List, knot_method LON_intensity = Extrapolation_List$Data_Extrap[ which_rows, 'Lon'] LAT_intensity = Extrapolation_List$Data_Extrap[ which_rows, 'Lat'] } + if( !(knot_method %in% c("samples","grid")) ) stop("`knot_method` must be either `samples` or `grid`") } # Convert to an Eastings-Northings coordinate system