Skip to content

Commit 55a4f49

Browse files
committed
Minor flownet updates and gisread cleanup
1 parent 77d227c commit 55a4f49

3 files changed

Lines changed: 118 additions & 190 deletions

File tree

R/CreateFlownet.R

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
#'
33
#' Creates the flow networkd table used by RHESSys
44
#' @param flownet_name The name of the flow network file to be created. Will be coerced to have ".flow" extension if not already present.
5-
#' @param readin readin indicates the maps to be used. If CreateFlowmet.R is run it's own, this should point to the template which references the maps(or values)
6-
#' used for the various levels and statevars. Otherwise, if run inside of RHESSysPreprocess, readin will use the map data from world_gen.R,
7-
#' Streams map, and other optional maps, still need to be specified.
85
#' @param asprules List of aspatial structure and inputs. Also can be path to rules file - must be used along with template input.
96
#' @param road_width >0, defaults to 1.
107
#' @inheritParams RHESSysPreprocess
118
#' @author Will Burke
129
#' @export
1310

1411
CreateFlownet = function(flownet_name,
15-
readin = NULL,
1612
template = NULL,
1713
type = "raster",
1814
typepars = NULL,
@@ -44,12 +40,7 @@ CreateFlownet = function(flownet_name,
4440
template_clean = template_list[[1]] # template in list form
4541
var_names = template_list[[2]] # names of template vars
4642
map_info = template_list[[5]] # tables of maps and their inputs/names in the template
47-
48-
if (!wrapper & is.character(readin)) { #if run outside of rhessyspreprocess.R, and if readin is character. readin is the template (and path)
49-
cfmaps = rbind(map_info,c("cell_length","none"), c("streams","none"), c("roads","none"), c("impervious","none"),c("roofs","none"))
50-
} else if (wrapper | (!wrapper & is.matrix(readin))) { # map info is passsed directly from world gen - either in wrapper or outside of wrapper and readin is matrix
51-
cfmaps = readin
52-
}
43+
cfmaps = rbind(map_info,c("cell_length","none"), c("streams","none"), c("roads","none"), c("impervious","none"),c("roofs","none"))
5344

5445
# Check for streams map, menu allows input of stream map
5546
if (is.null(streams) & (cfmaps[cfmaps[,1] == "streams",2] == "none" | is.na(cfmaps[cfmaps[,1] == "streams",2]))) {
@@ -82,7 +73,7 @@ CreateFlownet = function(flownet_name,
8273
}
8374

8475
# check inputs are maps or values
85-
notamap = cfmaps[suppressWarnings( which(!is.na(as.numeric(cfmaps[,2])))),1]
76+
notamap = cfmaps[suppressWarnings(which(!is.na(as.numeric(cfmaps[,2])))),1]
8677
maps_in = unique(cfmaps[cfmaps[,2] != "none" & !cfmaps[,1] %in% notamap,2])
8778

8879
# ------------------------------ Use GIS_read to get maps ------------------------------
@@ -129,7 +120,7 @@ CreateFlownet = function(flownet_name,
129120
if (!is.null(asprules)) {
130121
asp_map = template_clean[[which(var_names == "asp_rule")]][3] # get rule map/value
131122

132-
if (!"asp_rule" %in% notamap) { # if it's a map
123+
if (suppressWarnings(is.na(as.numeric(asp_map)))) { # if it's a map
133124
asp_map = gsub(".tif|.tiff","",asp_map)
134125
asp_mapdata = as.data.frame(readmap)[asp_map]
135126

@@ -174,9 +165,9 @@ CreateFlownet = function(flownet_name,
174165
asp_mapdata = asp_maps$asprule
175166
}
176167

177-
} else if ("asp_rule" %in% notamap) { # if is a single number
168+
} else { # if is a single number
178169
asp_mapdata = map_df[[cfmaps[cfmaps[,1] == "basin",2]]]
179-
asp_mapdata[!is.na(asp_mapdata)] = as.numeric(cfmaps[cfmaps[,1] == "asp_rule",2])
170+
asp_mapdata[!is.na(asp_mapdata)] = as.numeric(asp_map)
180171
}
181172
asp_list = aspatial_patches(asprules = asprules, asp_mapdata = asp_mapdata)
182173
}

0 commit comments

Comments
 (0)