diff --git a/HARP-2023-Summer/Mapping/Config/mapstyle_config.R b/HARP-2023-Summer/Mapping/Config/mapstyle_config.R index 45285584..c58924b9 100644 --- a/HARP-2023-Summer/Mapping/Config/mapstyle_config.R +++ b/HARP-2023-Summer/Mapping/Config/mapstyle_config.R @@ -23,10 +23,14 @@ #Everything in custom aesthetics can be adjusted, if not changed, then defaults(below custom) will be used #Human-readable metric names- add here any new metric names being used and their readable version -read_metric_name <- c('runid_0', 'runid_1','runid_3','runid_11','runid_12','runid_13','runid_14','runid_15','runid_16','runid_17','runid_18','runid_19','runid_20','runid_21','runid_22', 'fiveyr_avg_mgy', "wd_mgd", "gw_demand_mgd", "ps_mgd", "wsp2020_2040_mgy", "runid_11_wd_mgd", "runid_13_wd_mgd") +read_metric_name <- c('runid_0', 'runid_1','runid_3','runid_11','runid_12','runid_13','runid_14','runid_15','runid_16','runid_17','runid_18','runid_19','runid_20','runid_21','runid_22', 'fiveyr_avg_mgy', "wd_mgd", "gw_demand_mgd", "ps_mgd", + "wsp2020_2040_mgy", "runid_11_wd_mgd", "runid_13_wd_mgd", 'runid_11_l90_Qout', "runid_13_l90_Qout", "runid_17_l90_Qout", 'runid_11_l30_Qout','runid_13_l30_Qout', 'runid_17_l30_Qout', + 'runid_11_7q10','runid_13_7q10', 'runid_17_7q10', 'runid_11_Smin_L30_mg', 'runid_13_Smin_L30_mg') new_metric_name <- c('Pre-Condition', 'Historical Condition', 'Permit Term Max', '2020 Demand Scenario', '2030 Demand Scenario', '2040 Demand Scenario', 'Median Climate Change Scenario (50/50)- 2020 Demand', 'Dry Climate Change Scenario (10/10) - 2020 Demand', 'Wet Climate Change Scenario (90/90) - 2020 Demand ', 'Dry Climate Change Scenario (10/20) - 2040 Demand ', '2020 Exempt User Runs', 'Median Climate Change Scenario (50/50)- 2040 Demand', - 'Wet Climate Change Scenario (90/90) - 2040 Demand', '2015 Demand 2010', '2015 Demand 2040', 'Five Year Avg Use(MGY)', 'Withdraws(MGD)', 'Ground Water Demand (MGD)', "Point Source (MGD)", "Water Supply Plan 2020-2040 MGY", "2020 Demand Scenario Withdraws (MGD)", "2040 Demand Scenario Withdraws (MGD)") + 'Wet Climate Change Scenario (90/90) - 2040 Demand', '2015 Demand 2010', '2015 Demand 2040', 'Five Year Avg Use(MGY)', 'Withdraws(MGD)', 'Ground Water Demand (MGD)', "Point Source (MGD)", "Water Supply Plan 2020-2040 MGY", + "2020 Demand Scenario Withdraws (MGD)", "2040 Demand Scenario Withdraws (MGD)", "2020 Demand Scenario-L90", "2040 Demand Scenario-L90", "Dry Climate 2040- L90", "2020 Demand Scenario- L30", "2040 Demand Scenario- L30", + "Dry Climate 2040- L30", "2020 Demand Scenario- 7q10", "2040 Demand Scenario- 7q10", "Dry Climate 2040- 7q10", "2020 Demand- Min Storage L30", "2040 Demand- Min Storage L30") metric_names <- data.frame(read_metric_name, new_metric_name) # adapt this to permit us to store pre-configured sets @@ -49,7 +53,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_l90_Qout', 'runid_13_l90_Qout', 'percentDiff_l90_Qout_runid_11_runid_13'), sort_col = 'percentDiff_l90_Qout_runid_11_runid_13', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( metric='l90_Qout', @@ -59,7 +64,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_l90_Qout','runid_17_l90_Qout', 'percentDiff_l90_Qout_runid_11_runid_17'), sort_col = 'percentDiff_l90_Qout_runid_11_runid_17', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( metric='l30_Qout', @@ -69,7 +75,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_l30_Qout','runid_13_l30_Qout', 'percentDiff_l30_Qout_runid_11_runid_13'), sort_col = 'percentDiff_l30_Qout_runid_11_runid_13', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( metric='l30_Qout', @@ -79,7 +86,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_l30_Qout','runid_17_l30_Qout', 'percentDiff_l30_Qout_runid_11_runid_17'), sort_col = 'percentDiff_l30_Qout_runid_11_runid_17', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( metric='7q10', @@ -89,7 +97,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_7q10','runid_13_7q10', 'percentDiff_7q10_runid_11_runid_13'), sort_col = 'percentDiff_7q10_runid_11_runid_13', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), # list(metric='water_available_mgd', column_name='water_available_mgd_runid_13'), list( @@ -100,25 +109,27 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_7q10', 'runid_17_7q10', 'percentDiff_7q10_runid_11_runid_17'), sort_col = 'percentDiff_7q10_runid_11_runid_17', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( - metric='Smin_L30_mg', + metric='Smin_L30_mg', data_set = 'rseg_no_geom', - column_name='runid_13_Smin_L30_mg', - run_label = 'Minimum Storage', - tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_Smin_L30_mg', 'runid_13_Smin_L30_mg', 'percentDiff_Smin_L30_mg_runid_11_runid_17'), + column_name='runid_13_Smin_L30_mg', + run_label = 'Minimum Storage', + tables_cols = c('name', 'riverseg', 'Metric', 'runid_11_Smin_L30_mg', 'runid_13_Smin_L30_mg', 'percentDiff_Smin_L30_mg_runid_11_runid_13'), sort_col = 'runid_13_Smin_L30_mg', - sort_decreasing = TRUE, - show_map = TRUE - ), + sort_decreasing = TRUE, + show_map = TRUE, + digit = 2 + ), list( data_set = 'facils_nogeom', - metric='unmet30_mgd', #replace with unmet demand req - column_name='runid_11_unmet30_mgd', - run_label = 'Highest 30-day Potential Unmet Demand', + metric='unmet30_mgd', #replace with unmet demand req + column_name='runid_11_unmet30_mgd', + run_label = 'Highest 30-day Potential Unmet Demand', tables_cols = c('facility', 'Facility_hydroid', 'riverseg', 'runid_11_unmet30_mgd', 'runid_13_unmet30_mgd', 'runid_17_unmet30_mgd' ,'gw_frac'), - sort_decreasing = FALSE, + sort_decreasing = FALSE, show_map= FALSE ) ), @@ -132,7 +143,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_401_l30_Qout', 'runid_601_l30_Qout', 'percentDiff_l30_Qout_runid_0_runid_601'), sort_col = 'percentDiff_l30_Qout_runid_401_runid_601', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( data_set = 'rseg_no_geom', @@ -142,7 +154,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_401_7q10', 'runid_601_7q10', 'percentDiff_7q10_runid_0_runid_601'), sort_col = 'percentDiff_7q10_runid_401_runid_601', sort_decreasing = FALSE, - show_map = TRUE + show_map = TRUE, + digit = 2 ), list( data_set = 'rseg_no_geom', @@ -152,7 +165,8 @@ run_sets <- list( tables_cols = c('name', 'riverseg', 'Metric', 'runid_401_Smin_L30_mg', 'runid_601_Smin_L30_mg', 'percentDiff_Smin_L30_mg_runid_0_runid_601'), sort_col = 'runid_601_Smin_L30_mg', sort_decreasing = TRUE, - show_map = TRUE + show_map = TRUE, + digit = 2 ) ) ) diff --git a/HARP-2023-Summer/Mapping/Functions/fn_mapgen.R b/HARP-2023-Summer/Mapping/Functions/fn_mapgen.R index 01f30e79..bda0e428 100644 --- a/HARP-2023-Summer/Mapping/Functions/fn_mapgen.R +++ b/HARP-2023-Summer/Mapping/Functions/fn_mapgen.R @@ -11,7 +11,7 @@ library(ggspatial) library(ggrepel) library(geosphere) library(arcpullr) -source(paste0(github_uri,"/HARP-2023-Summer/Mapping/Functions/fn_filter_map.R"),local = TRUE) +source(paste0(github_uri,"/HARP-2023-Summer/Mapping/Functions/fn_filter_map.R"),local = TRUE) ## nhd layer will be pulled and processed before function is called but filtering of flowlines to plot will be done within this function ## bbox should come in with format of named list of coords: xmin, ymin, xmax, ymax diff --git a/HARP-2023-Summer/Mapping/Functions/fn_tablegen.R b/HARP-2023-Summer/Mapping/Functions/fn_tablegen.R index b17b6d31..7c506ce1 100644 --- a/HARP-2023-Summer/Mapping/Functions/fn_tablegen.R +++ b/HARP-2023-Summer/Mapping/Functions/fn_tablegen.R @@ -20,7 +20,7 @@ fn_tablegen <- function( font.size = 8, background.color = "white", na_str = "NA", nan_str = "NA", #padding = 1, table.layout = 'fixed', tabcolsep = 1.5, - fonts_ignore = T, big.mark = "", decimal.mark = ".", digits = 4 ) #fonts_ignore applies when knitting as pdf + fonts_ignore = T, big.mark = "", decimal.mark = ".", digits = 2) #fonts_ignore applies when knitting as pdf if (columns == "all") { #columns param in function is all meaning keep columns as normal ft <- flextable(table) @@ -31,7 +31,7 @@ fn_tablegen <- function( ft <- theme_vanilla(ft) ft <- autofit(ft) - ft <- width(ft, j=1, width = 1.5) + ft <- width(ft, j=1, width = 1) ft <- width(ft, width = 1) ft <- align(ft, align = alignment, part = "all") diff --git a/HARP-2023-Summer/Mapping/README.md b/HARP-2023-Summer/Mapping/README.md index 5133af5c..6dde6782 100644 --- a/HARP-2023-Summer/Mapping/README.md +++ b/HARP-2023-Summer/Mapping/README.md @@ -86,15 +86,11 @@ rmarkdown::render(paste0(github_location, "/HARParchive/HARP-2023-Summer/Mapping - **origin**: name of the region, locality, or rivseg, make sure to use correct naming - - **rivseg**: river segment ID of basin to be mapped, for map type basin +- **rivseg**: river segment ID of basin to be mapped, for map type basin - - **locality**: locality/county of interest, for map type locality +- **locality**: locality/county of interest, for map type locality - - - - ``` - **region**: region of interest, must match a region name in - ``` +- **region**: region of interest, must match a region name in - **Possible regions** :`BigSandy_UpperTennessee_1`, `BigSandy_UpperTennessee_2`, `Chowan_1`, `Chowan_2`, `Eastern_Shore`, `MiddleJames_1`, `MiddleJames_2`, `MiddleJames_3`, `NewRiver_1`, `NewRiver_2`, `NorthernCoastalPlain_1`, `NorthernCoastalPlain_2`, `NorthernCoastalPlain_3`, `NorthernPiedmont_1`, `NorthernPiedmont_2`, `NorthernVirginia`, `Roanoke_1`, `Roanoke_2`, `Roanoke_3`, `Shenandoah_1`, `Shenandoah_2`, `SoutheastVirginia`, `UpperJames_1`, `UpperJames_2`, `York_James_1`, `York_James_2` @@ -118,6 +114,8 @@ rmarkdown::render(paste0(github_location, "/HARParchive/HARP-2023-Summer/Mapping - *Possible Metrics*: `wsp2020_2040_mgy` +- **foundation_path**: use to access the foundation files in your local machine if needed + - **rivseg_metric**: drought metric for riverseg maps, can list multiple, use c() - *Possible Metrics*: `190_Qout`,`7q10`, `l30_Qout`, etc. @@ -157,7 +155,7 @@ rmarkdown::render(paste0(github_location, "/HARParchive/HARP-2023-Summer/Mapping ### General Info -This RMD pulls in the csv files created in `Dataframe_Generator.R` and forms them into the desired maps and tables. The final output of this document is the desired Markdown file for the users input. +This RMD pulls in the csv files created in `Dataframe_Generator.R` and forms them into the desired maps and tables. The final output of this document is the desired Markdown file for the users input. This document also heavily uses mapstyle_config. ### Render @@ -241,6 +239,9 @@ format: - tables_cols: this is what columns are desired in the tables presented, such as c('name', 'riverseg', 'Metric', 'runid_11_l30_Qout', 'runid_13_l30_Qout', 'percentDiff_l30_Qout_runid_11_runid_13'), - sort_col: this is what column will be sorted by in the table, such as 'percentDiff_l30_Qout_runid_11_runid_13', - sort_decreasing: this is TRUE if sorting by decreasing and FALSE if sorting by increasing + - data_set = use 'rseg_no_geom' for metrics that use rseg data. Use 'facils_nogeom' for metrics that use facil data, like unmet demand. + - show_map = 'TRUE' when mapping for rseg data, 'FALSE' when mapping for facil data or unmet demand + - digit = the decimals you want to round that table to - Everything in custom aesthetics can be adjusted, if not changed, then defaults (below custom) will be used @@ -267,7 +268,7 @@ format: ### Riversegmaps_config -to edit later(might end up merging into mapstyle) +Creates the coloring for different percentages on the map as well as the highlight level for the tables. # Example Renders diff --git a/HARP-2023-Summer/Mapping/WSP_Regional_Summaries.Rmd b/HARP-2023-Summer/Mapping/WSP_Regional_Summaries.Rmd index a1d5645b..9216d821 100644 --- a/HARP-2023-Summer/Mapping/WSP_Regional_Summaries.Rmd +++ b/HARP-2023-Summer/Mapping/WSP_Regional_Summaries.Rmd @@ -84,6 +84,7 @@ show_map <- params$show_map if (!exists("HARParchive_location")){ HARParchive_location <- "https://raw.githubusercontent.com/HARPgroup/HARParchive/master"} + source(paste0(HARParchive_location,"/HARP-2023-Summer/Mapping/Functions/fns_spatial.R")) #load functions for dealing with spatial data source(paste0(HARParchive_location,"/HARP-2023-Summer/Mapping/Functions/fn_mapgen.R")) #load mapping function source(paste0(HARParchive_location,"/HARP-2023-Summer/Mapping/Functions/fn_tablegen.R")) #load table function @@ -661,6 +662,7 @@ for (k in 1:length(run_config$riverseg_metrics)){ display_metric <- run_config$riverseg_metrics[[k]]$metric display_title <- run_config$riverseg_metrics[[k]]$run_label + digit <- run_config$riverseg_metrics[[k]]$digit #metrics, to be suppressed later? rseg_display$Metric <- display_metric @@ -668,6 +670,13 @@ for (k in 1:length(run_config$riverseg_metrics)){ #assemble our table, with the columns in order defined by table_cols rseg_display <- rseg_display[table_cols] #need to make sure table_cols and column_name properly done in mapstyle_config or will get error here + #rounding + numeric <- names(rseg_display[, sapply(rseg_display, is.numeric)]) + + for (x in 1:length(numeric)) { + rseg_display[,numeric[x]]<- round(rseg_display[,numeric[x]], digit) + } + #na messages nacols <- colSums(is.na(rseg_display)) == nrow(rseg_display) @@ -681,6 +690,18 @@ for (k in 1:length(run_config$riverseg_metrics)){ #fill blanks with NA rivTables[[k]][rivTables[[k]] == ''] <- NA + for (i in 1:length(table_cols)) { + for (x in 1:nrow(metric_names)){ + if (table_cols[i]==metric_names$read_metric_name[x]) + { + names(rivTables[[k]])[names(rivTables[[k]]) == table_cols[i]] <- metric_names$new_metric_name[x] + } + else + { + next + } + } +} #defining titles rivtablemetric <- paste0(display_metric) #define title here for mapping so each map has diff metric title, pass into function @@ -692,7 +713,7 @@ for (k in 1:length(run_config$riverseg_metrics)){ ft2 <- fn_tablegen(featr_type = FALSE, table = rivTables[[k]], columns = "all", alignment = "left", metric = display_metric, origin_type = origin_type, - origin = origin , tabletitle = rivtabletitle, + origin = origin , tabletitle = display_title, num=rivtablenum, highlight_col = display_column, highlight_limit = -10) #flextable function assign(paste0('table', k), ft2, envir = globalenv()) @@ -718,6 +739,8 @@ for (k in 1:length(run_config$riverseg_metrics)){ #fill blanks with NA rivTables[[k]][rivTables[[k]] == ''] <- NA + #Human Readable Names- edit in mapstyle config + #defining titles rivtablemetric <- paste0(display_metric) #define title here for mapping so each map has diff metric title, pass into function