forked from nationalparkservice/WRST-climate-futures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Variable_calculations.Rmd
103 lines (67 loc) · 3.14 KB
/
Variable_calculations.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
---
title: "Calculate variables"
author: "Amber Runyon"
date: "7/23/2021"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Initials
0. Run after CF-selection.Rmd and selection of CFs
1. Change the initials with area name and CFs selected
2.
```{r Initials, echo=FALSE, message=FALSE, warning=FALSE}
rm(list = ls())
SiteID <- "CAKR" #*UPDATE*
library(stars);library(dplyr);library(ggplot2);library(ggthemes);library(viridis);library(here);library(ggrepel);library(rlang);library(units)
met.dir <- "E:/NCAR_AK/met"
vic.dir <- "E:/NCAR_AK/vic_hydro"
# working.dir <- paste0("C:/Users/arunyon/3D Objects/Local-files/RCF_Testing/",SiteID) #*UPDATE*
working.dir <- paste0("C:/Users/arunyon/OneDrive - DOI/AKR-CFs/",SiteID) #*UPDATE*
data.dir <- paste(working.dir, "Data", sep="/")
historical.period <- as.character(seq(1950,1999,1))
future.period <- as.character(seq(2035,2065,1))
daymet.period <- as.character(seq(1980,2016,1))
GCMs <- c("MRI-CGCM3.rcp45","CCSM4.rcp85")
CFs <- c("Climate Future 1", "Climate Future 2")
cols <- c("#6EB2D4","#CA0020")
CF_GCM <- data.frame(CF=CFs,GCM=GCMs,CF_col=cols)
```
## Load Spatial Data
```{r Load spatial data}
# Spatial
nps_boundary <- st_read('./Data/nps_boundary/nps_boundary.shp')
park <- filter(nps_boundary, UNIT_CODE == SiteID)
shp <- st_transform(park, 3338)
# huc <- st_read("C:/Users/arunyon/OneDrive - DOI/Documents/GIS/AK_HUC8/Kachemak_Tuxedni.shp")
# shp <- st_transform(huc, 3338)
```
## Met monthly parse and variable creation
Loop through met GCM.rcp and summarize each variable
```{r Create met monthly variables, results=hide, eval=TRUE}
memory.limit(size = 60000)
source(here::here("Code", "Metric-development", "met","met-monthly-stars.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","met-monthly-variables.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","Annual.tmeanF.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","Annual.precipIn.R"),echo = FALSE)
```
## Vic monthly parse and variable creation
```{r Create vic monthly variables, results=hide, eval=TRUE}
memory.limit(size = 60000)
source(here::here("Code", "Metric-development", "vic","vic-monthly-stars.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "vic","max.SWE.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "vic","MAMSON.SWE.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "vic","water.balance.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "vic","SWE.precip.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "vic","soil.temp.R"),echo = FALSE)
```
## Daily variable creation
```{r Create daily variables, results=hide, eval=TRUE}
gc()
memory.limit(60000)
source(here::here("Code", "Metric-development", "met","met-daily-stars_by_year.R"),echo = FALSE) #Takes ~1 hrs to run
source(here::here("Code", "Metric-development", "vic","SWE-runoff-Pr99.R"),echo = FALSE)
source(here::here("Code", "Metric-development", "met","Pr99v2.R"),echo = FALSE)
# source(here::here("Code", "Metric-development","daily-all-geographies.R"),echo = FALSE,eval=FALSE)
```