-
Notifications
You must be signed in to change notification settings - Fork 2
/
CCRP_Generate_Climate_Futures_CustomLocation.Rmd
263 lines (176 loc) · 8.96 KB
/
CCRP_Generate_Climate_Futures_CustomLocation.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
---
title: "NPS park climate futures"
author: "Climate Change Response Program"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: html_document
---
```{r setup, warning=FALSE, include = FALSE}
knitr::opts_chunk$set(
echo = FALSE,
collapse = TRUE,
warning = TRUE, # set to FALSE when done
message = TRUE # set to FALSE when done
)
library(here); library(plyr);# Use here::here when package lubridate is used
library(plotrix); library(zoo); library(ggplot2); library(grid); library(cowplot); library(reshape2); library(raster); library(ncdf4); library(reshape2); library(WriteXLS); library(data.table); library(RColorBrewer); library(ggrepel); library(lubridate); library(dplyr); library(forcats); library(openxlsx); library("WaterBalance"); library(sf); library(raster); library(rgdal); library(R.utils); library(tmap); library(tmaptools); library(ggmap); library(ggspatial);
library(gridExtra); library(SPEI); library(tidyr); library(tibble); library(sp); library(skimr); library(stringr); library(ggpubr); library(lemon); library(ggfortify); library(extRemes);library(data.table);library(sp);library(terra)
```
# For loop that reads names from csv file for park
```{r user-inputs-1, warning=FALSE, include = FALSE}
rm(list = ls())
# -------------- Input site information -------------------------------------- #
SiteID = "BLRV"
Park = "BLRV"
SiteName = SiteID #optional - set at SiteID if don't want to use
Lat = 41.939028
Lon = -71.431884
set.seed(50)
# --------------- Input local folder information ----------------------------- #
project_root_dir <- here::here()
local_rss_dir <- 'C:/Users/arunyon/3D Objects/Local-files/RCF_Testing/' # local directory where you want this repo copied. Should be something like 'C:/Users/adillon/Documents/RSS/'. Next lines create folder for park
local_rss_dir <- paste0(local_rss_dir,SiteName)
if(dir.exists(local_rss_dir) == FALSE){
dir.create(local_rss_dir)
}
if(dir.exists(here::here( "PARK")) == FALSE){
dir.create(here::here( "PARK"))
}
OutDir = paste0('./PARK/',SiteName,"/") # for .csv's
if(dir.exists(OutDir) == FALSE){
dir.create(OutDir)
}
DataDir = paste0(OutDir,'input-data/') # for .csv's
if(dir.exists(DataDir) == FALSE){
dir.create(DataDir)
}
```
## `r SiteID`
```{r site-info, message=FALSE, warning=FALSE, include = FALSE,error=TRUE}
source(here::here("scripts", "get_site_info_CustomLocation.R")) # Extract local inputs; seconds to run
# source(here::here("scripts", "create_site_maps_Koppen.R")) # Create site maps
source(here::here("scripts", "get_params_CustomLocation.R"))
```
```{r user-inputs-2, warning=FALSE, include = FALSE}
CFs_all <- c("Warm Wet", "Hot Wet", "Central", "Warm Dry", "Hot Dry")
##Color schemes
#Colors for CF values plotted side by side (match order of CFs vector)
colors5 <- c("#6EB2D4", "#05689F", "#F6B294", "#CA0020","grey")
colors5.2 <- c("#6EB2D4", "#05689F", "grey", "#F6B294", "#CA0020")
centroids_csv <- "Y" #Switch for using Tercek csvs or downloading own data
Indiv_method <- "pca" # Switch for method Indiv_method = c("corner", "pca")
Percent_skill_cutoff = .1 #percentage of models to drop from ranking
MethodCaption="Y" # Indicates whether Q/I present at bottom of plot to ID CF method used
# --------- Information for Climate Futures Analyses (MACA) ------------------ #
# Specify parameters:
Yr = 2050 #Central year
Range = 30 #Number of years to summarize (should be at least 30)
BasePeriod = "1979-2012"
rollLen = 10 #rolling mean length for timeseries plots
# Threshold percentages for defining Climate futures. Default low/high: 0.25, 0.75
CFLow = 0.25
CFHigh = 0.75
QuantileLow = 0.05 #Quantiles for temperature threshold calculations
QuantileHigh = 0.95
HotTemp = 95
ColdTemp = 32
PrecipThreshold = 0.05
# ------------ Information for WB analyses ------------------------ #
#Method for PET calculation
PET_Method = "Oudin" #Hamon is default method for daily PRISM and MACA data (containing only Tmax, Tmin, and Date).
# ------------ Information for drought analyses ------------------------ #
## SPEI variables
SPEI_per<-6 # This is the value for the period SPEI is aggregated. 6-months is standard but could change if want.
truncation<- -.5 # SPEI value, under which drought events are considered
SPEI_start <- 1980
SPEI_end <- 2012
```
```{r Climate-Futures, message=FALSE, warning=FALSE, include = FALSE}
SiteID = SiteName
source(here::here("scripts", "Drobo_terra.R"), local = knitr::knit_global())
source(here::here("scripts", "Plotting_Functions.R"), local = knitr::knit_global())
SiteID=Park
source(here::here("scripts", "Plot_Table_Creation.R"), local = knitr::knit_global()) # Requires "PARK_init_parsed.RData"; Output = "PARK_lat_long_Final_Environment.RData".
SiteID=SiteName
source(here::here("scripts", "Scatter_and_diagnostic.R"), local = knitr::knit_global()) # Creates scatter and diagnostic plots. Outputs to Figs MACA folder.
```
```{r WarmWet/HotDry, message=FALSE, warning=FALSE, include = FALSE}
# Specify Climate Futures
## Run this section if already downloaded data objects
# OutDir <- "C:/Users/arunyon/3D Objects/Local-files/Git-repos/CCRP_automated_climate_futures/PARK/NIOB_21/"
DataDir = paste0(OutDir,'input-data/') # for .csv's
#####################################################
DataFile <- list.files(path = DataDir, pattern = 'Final_Environment.RData', full.names = TRUE) # Environment needs to be added if not parsing MACA data
load(DataFile)
SiteID <- SiteName
FutureSubset <- CFs_all[c(1,5)]; CFs = FutureSubset # Pick pair of climate futures.
CF_abbreviation <- "WW-HD"
WB_GCMs <- subset(WB_GCMs, CF %in% CFs)
colors2<- colors5[c(1,4)] # Select pair of climate futures - WarmWet/HotDry
#colors2<- c("#F3D3CB","#12045C") # Select pair of climate futures - HotWet/WarmDry
colors3<-c("white",colors2)
col<- c("darkgray",colors2) # WarmWet/HotDry
#col<- c("darkgray","#F3D3CB","#12045C") # HotWet/WarmDry
CFDir = paste0(OutDir,"WarmWet_HotDry/") # for .csv's
if(dir.exists(CFDir) == FALSE){
dir.create(CFDir)
}
TableDir = paste0(CFDir,"tables/") # for .csv's
if(dir.exists(TableDir) == FALSE){
dir.create(TableDir)
}
FigDir = paste0(CFDir,"figures/") # for .csv's
if(dir.exists(FigDir) == FALSE){
dir.create(FigDir)
}
if (exists("FutureSubset") == FALSE) stop("Please specify Climate Futures") # At the top of the script, please enter a combination of futures, e.g. Warm Wet/Hot Dry
source(here::here("scripts", "Threshold_Bar_Charts.R")) # Requires "PARK_lat_long_Final_Environment.RData". Outputs plots and Excel Workbook
source(here::here("scripts","Daily_WB_Model.R"))
source(here::here("scripts", "Drought_characteristics.R"))
# source(here::here("scripts", "WBgrid_plotting.R")) # Run the Water Balance Model
source(here::here("scripts", "Return_Events.R"))
source(here::here("scripts", "Summary plots.R"))
source(here::here("scripts", "Report_plots.R"))
```
```{r WarmDry/HotWet, message=FALSE, warning=FALSE, include = FALSE}
# Specify Climate Futures
## Run this section if already downloaded data objects
# OutDir <- "C:/Users/arunyon/3D Objects/Local-files/Git-repos/CCRP_automated_climate_futures/PARK/NIOB_21/"
DataDir = paste0(OutDir,'input-data/') # for .csv's
######################################################
DataFile <- list.files(path = DataDir, pattern = 'Final_Environment.RData', full.names = TRUE) # Environment needs to be added if not parsing MACA data
load(DataFile)
SiteID <- SiteName
FutureSubset <- CFs_all[c(4,2)]; CFs = FutureSubset # Pick pair of climate futures.
CF_abbreviation <- "WD-HW"
WB_GCMs <- subset(WB_GCMs, CF %in% CFs)
# colors2<- c("#9A9EE5","#E10720") # Select pair of climate futures - WarmWet/HotDry
colors2<- colors5[c(3,2)] # Select pair of climate futures - HotWet/WarmDry
colors3<-c("white",colors2)
# col<- c("darkgray","#9A9EE5","#E10720") # WarmWet/HotDry
col<- c("darkgray", colors2) # HotWet/WarmDry
CFDir = paste0(OutDir,"WarmDry_HotWet/") # for .csv's
if(dir.exists(CFDir) == FALSE){
dir.create(CFDir)
}
TableDir = paste0(CFDir,"tables/") # for .csv's
if(dir.exists(TableDir) == FALSE){
dir.create(TableDir)
}
FigDir = paste0(CFDir,"figures/") # for .csv's
if(dir.exists(FigDir) == FALSE){
dir.create(FigDir)
}
if (exists("FutureSubset") == FALSE) stop("Please specify Climate Futures") # At the top of the script, please enter a combination of futures, e.g. Warm Wet/Hot Dry
source(here::here("scripts", "Threshold_Bar_Charts.R")) # Requires "PARK_lat_long_Final_Environment.RData". Outputs plots and Excel Workbook
source(here::here("scripts","Daily_WB_Model.R"))
source(here::here("scripts", "Drought_characteristics.R"))
# source(here::here("scripts", "WBgrid_plotting.R")) # Run the Water Balance Model
source(here::here("scripts", "Return_Events.R"))
source(here::here("scripts", "Summary plots.R"))
source(here::here("scripts", "Report_plots.R"))
```
```{r Copy-and-delete-files, message=FALSE, warning=FALSE, include = FALSE}
SiteID <- SiteName
source(here::here("scripts", "write_metadata.R"))
source(here::here("scripts", "copy_paste_delete_files.R")) # copies files and folders to specified local folder
```