Skip to content

Commit

Permalink
Fix bug...
Browse files Browse the repository at this point in the history
... triggered when fine_scale=TRUE and observations are only available in a subset of the extrapolation-grid
  • Loading branch information
James-Thorson-NOAA authored Nov 9, 2019
2 parents 7537c71 + 736f670 commit 3ab2411
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/Calc_Anisotropic_Mesh.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
}

Expand Down
2 changes: 1 addition & 1 deletion R/Convert_LL_to_UTM_Fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) #$
Expand Down
1 change: 0 additions & 1 deletion R/Prepare_AI_Extrapolation_Data_Fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 5 additions & 10 deletions R/Prepare_NZ_Extrapolation_Data_Fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 )
}
Expand Down
1 change: 1 addition & 0 deletions R/make_spatial_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ab2411

Please sign in to comment.