-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMW_Microclimate.Rmd
89 lines (78 loc) · 3.31 KB
/
MW_Microclimate.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
---
title: "Microclimate"
author: "Meera Lee Sethi, based on code by Ian Breckheimer"
date: "11/10/2020"
output: html_document
---
#Setup for R script and R markdown
1. Load all libraries
2. Specify string behavior
3. Load packages
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(stringsAsFactors = FALSE)
```
```{r workspace, eval=FALSE}
####Set up workspace####
source("./HRL_microclim_functions.R")
library(data.table)
library(xts)
library(psych)
library(lubridate)
```
#Data wrangling
1. Imports raw data (csv files)
2. Formats individual year-plot files
3. Cleans and checks data
4. Extracts snow cover attributes
5. Writes formatted/processed snow cover attributes to .csv
```{r paths, eval=FALSE}
##For MeadoWatch Data
input_paths_soil <- c("./data/Microclimate/2014 RL",
"./data/Microclimate/2015 GB",
"./data/Microclimate/2015 RL",
"./data/Microclimate/2016 GB",
"./data/Microclimate/2016 RL",
"./data/Microclimate/2017 GB",
"./data/Microclimate/2017 RL",
"./data/Microclimate/2018 GB",
"./data/Microclimate/2018 RL",
"./data/Microclimate/2019 GB",
"./data/Microclimate/2019 RL",
"./data/Microclimate/2020 GB",
"./data/Microclimate/2020 RL")
##For Forest Demography data
#input_paths_soil <- c("./data/Microclimate/ForestDemo2013",
# "./data/Microclimate/ForestDemo2014",
# "./data/Microclimate/ForestDemo2015",
# "./data/Microclimate/ForestDemo2016",
# "./data/Microclimate/ForestDemo2017",
# "./data/Microclimate/ForestDemo2018",
# "./data/Microclimate/ForestDemo2019")
```
```{r csv processing1, eval=FALSE}
snow_formatted <- batch_format_micro_csv(input_paths=input_paths_soil,
output_path="./temp/soil",
#file_prefixes=c("FD13_soil", "FD14_soil", "FD15_soil",
# "FD16_soil", "FD17_soil", "FD18_soil",
# "FD19_soil"),
file_prefixes=c("MW_soil", "MW_soil", "MW_soil", "MW_soil",
"MW_soil", "MW_soil", "MW_soil", "MW_soil",
"MW_soil", "MW_soil", "MW_soil", "MW_soil",
"MW_soil"),
output_metadata_filename="metadata_soil.txt",
overwrite=FALSE)
```
```{r snow processing, eval=FALSE}
snow_processed <- batch_extract_snow_vars(input_path="./temp/soil",
input_metadata_filename="metadata_soil.txt",
output_path="./output/soil",
output_metadata_filename="metadata_snow.txt",
range_threshold=1,max_threshold=2,overwrite=FALSE)
snow_processed$SDDDOY <-yday(snow_processed$snow_disappearance_date)+1
snow_attributes <- snow_processed[, c(16:24)]
#Uncomment for MeadoWatch data
write.csv(snow_attributes, "MW_snow.csv")
#Uncomment for forest demo
#write.csv(snow_attributes, "ForestDemo_snow.csv")
```