|
2 | 2 | #' |
3 | 3 | #' Creates the flow networkd table used by RHESSys |
4 | 4 | #' @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. |
8 | 5 | #' @param asprules List of aspatial structure and inputs. Also can be path to rules file - must be used along with template input. |
9 | 6 | #' @param road_width >0, defaults to 1. |
10 | 7 | #' @inheritParams RHESSysPreprocess |
11 | 8 | #' @author Will Burke |
12 | 9 | #' @export |
13 | 10 |
|
14 | 11 | CreateFlownet = function(flownet_name, |
15 | | - readin = NULL, |
16 | 12 | template = NULL, |
17 | 13 | type = "raster", |
18 | 14 | typepars = NULL, |
@@ -44,12 +40,7 @@ CreateFlownet = function(flownet_name, |
44 | 40 | template_clean = template_list[[1]] # template in list form |
45 | 41 | var_names = template_list[[2]] # names of template vars |
46 | 42 | 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")) |
53 | 44 |
|
54 | 45 | # Check for streams map, menu allows input of stream map |
55 | 46 | 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, |
82 | 73 | } |
83 | 74 |
|
84 | 75 | # 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] |
86 | 77 | maps_in = unique(cfmaps[cfmaps[,2] != "none" & !cfmaps[,1] %in% notamap,2]) |
87 | 78 |
|
88 | 79 | # ------------------------------ Use GIS_read to get maps ------------------------------ |
@@ -129,7 +120,7 @@ CreateFlownet = function(flownet_name, |
129 | 120 | if (!is.null(asprules)) { |
130 | 121 | asp_map = template_clean[[which(var_names == "asp_rule")]][3] # get rule map/value |
131 | 122 |
|
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 |
133 | 124 | asp_map = gsub(".tif|.tiff","",asp_map) |
134 | 125 | asp_mapdata = as.data.frame(readmap)[asp_map] |
135 | 126 |
|
@@ -174,9 +165,9 @@ CreateFlownet = function(flownet_name, |
174 | 165 | asp_mapdata = asp_maps$asprule |
175 | 166 | } |
176 | 167 |
|
177 | | - } else if ("asp_rule" %in% notamap) { # if is a single number |
| 168 | + } else { # if is a single number |
178 | 169 | 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) |
180 | 171 | } |
181 | 172 | asp_list = aspatial_patches(asprules = asprules, asp_mapdata = asp_mapdata) |
182 | 173 | } |
|
0 commit comments