Skip to content

Commit 955f641

Browse files
committed
Added more specific NAs in world error
1 parent d903107 commit 955f641

3 files changed

Lines changed: 52 additions & 41 deletions

File tree

R/GIS_read.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,17 @@ GIS_read = function(maps_in, type, typepars, map_info = NULL, seq_patch_IDs = FA
185185

186186
# Check for missing data (within world map mask) - no fix, just an error since I think this will break things if left unchecked
187187
cat("Checking for missing data within bounds of world map.\n")
188-
if (!is.null("map_info") &
189-
sum(is.na(raster::values(read_stack)[!is.na(raster::values(read_stack[[map_info[map_info[, 1] == "world", 2][[1]]]])),
190-
!colnames(raster::values(read_stack)) %in% map_info[map_info[, 1] == "streams", 2]])) > 0) {
191-
# Add in future? - which maps are missing data?
192-
stop("Missing data within bounds of world level map. Check you input maps.")
188+
if (!is.null("map_info")) {
189+
wrld_vals = !is.na(raster::values(read_stack[[map_info[map_info[, 1] == "world", 2][[1]]]]))
190+
NAs_in_wrld = lapply(as.data.frame(raster::values(read_stack)), function(X) {sum(is.na( X[wrld_vals]))})
191+
if ("streams" %in% map_info[, 1]) {
192+
NAs_in_wrld[[map_info[map_info[, 1] == "streams", 2]]] = NULL
193+
}
194+
if (any(NAs_in_wrld > 0) ) {
195+
cat("One or more maps have NAs within the bounds of the world map, see maps and counts of NAs below:\n")
196+
print(NAs_in_wrld[NAs_in_wrld > 0])
197+
stop("See above and check your input maps.")
198+
}
193199
}
194200

195201
# Convert maps to SpatialGridDataFrame since world_gen.R expects that format

R/spatial_input_gen.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ spatial_input_gen = function(name,
3636

3737
warning("Work in progress - May not work, output crs/proj is weird, optional args/fucntionality is broken, probably best to run line by line")
3838

39+
# maybe this will help
40+
library(rgrass7)
41+
42+
basin = NULL
43+
patch = FALSE
44+
define_watershed = FALSE
45+
easting = NULL
46+
northing = NULL
47+
gisDbase = NULL
48+
location = NULL
49+
mapset = NULL
50+
3951
# check and convert file paths for args
4052

4153

@@ -74,7 +86,7 @@ spatial_input_gen = function(name,
7486
}
7587

7688
# --- checking env and stuff ---
77-
# gmeta()
89+
# rgrass7::gmeta()
7890
# rgrass7::execGRASS(cmd = "g.mapset", flags = "p")
7991
# rgrass7::execGRASS(cmd = "g.mapset", flags = "l")
8092
# rgrass7::execGRASS(cmd = "g.list", flags = "p", type = "raster")

R/utils.R

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,31 @@ init_defaults = function() {
1212

1313
# run this is preprocess isn't working to check out if anything stands out with the maps
1414
# i'll try to add checks to this as needed.
15-
debug_spatial = function(template, typepars, streams) {
16-
17-
template = template_read(template = template)
18-
maps = as.data.frame(unique(template[[5]]))
19-
maps = rbind(maps, c("streams", streams))
20-
21-
map_paths = file.path(typepars, maps$Map)
22-
23-
maps$Exists = sapply(map_paths, file.exists)
24-
25-
library(raster)
26-
# going to assume this might not work, tho this is how they are read normally
27-
#map_stack = raster::stack(x = map_paths)
28-
map_data = list()
29-
for (i in seq_along(map_paths)) {
30-
map_data[[i]] = raster(map_paths[i])
31-
32-
maps$extent = paste(map_data[[i]]@extent[1:4])
33-
maps$cellsize = res(map_data[[i]])
34-
35-
maps$ncell = ncell(map_data[[i]])
36-
maps$NAs = sum(is.na(values(map_data[[i]])))
37-
maps$NULLs = sum(is.null(map_data[[i]]))
38-
maps$proj = paste(crs(map_data[[i]]@crs))
39-
40-
41-
}
42-
43-
prob = map_stack[values(map_stack$pch_30m1000.1) == 15660]
44-
45-
46-
47-
48-
49-
}
15+
# debug_spatial = function(template, typepars, streams) {
16+
#
17+
# template = template_read(template = template)
18+
# maps = as.data.frame(unique(template[[5]]))
19+
# maps = rbind(maps, c("streams", streams))
20+
#
21+
# map_paths = file.path(typepars, maps$Map)
22+
#
23+
# maps$Exists = sapply(map_paths, file.exists)
24+
#
25+
# library(raster)
26+
# # going to assume this might not work, tho this is how they are read normally
27+
# #map_stack = raster::stack(x = map_paths)
28+
# map_data = list()
29+
# for (i in seq_along(map_paths)) {
30+
# map_data[[i]] = raster(map_paths[i])
31+
#
32+
# maps$extent = paste(map_data[[i]]@extent[1:4])
33+
# maps$cellsize = res(map_data[[i]])
34+
#
35+
# maps$ncell = ncell(map_data[[i]])
36+
# maps$NAs = sum(is.na(values(map_data[[i]])))
37+
# maps$NULLs = sum(is.null(map_data[[i]]))
38+
# maps$proj = paste(crs(map_data[[i]]@crs))
39+
#
40+
# }
41+
#
42+
# }

0 commit comments

Comments
 (0)