The following code contains the workflow for organizing annualized growth for MRS 1, though all plots follow the same structure.
# libraries
library(tidyverse)
library(sf)
# pathways
path.shp <- "data/shapefiles_raw"
path.tab <- "D:/Dissertation/Analysis/Chapter_2/data/PermPlots"
list.files(path.shp)
## character(0)
list.files(path.tab)
## [1] "gap_plots_all.csv" "perm_plots_all.csv"
# load
mrs_tab <- read.csv("D:/Dissertation/Analysis/Chapter_2/data/PermPlots/perm_plots_all.csv")
# Examine dataset
head(mrs_tab, 2)
## Plot Tree Spec dbh1 dbh3 dbh4 YrCHt hc1 hc2 hc3 hc4 recruitYr dead deadPeriod
## 1 MRS1 1 PICO 6 8.8 <NA> 1914 3 3 3 3 NA 1 8
## 2 MRS1 2 PICO 21 24.1 25.4 1883 1 1 1 1 NA 0 0
## dp.start dp.end fallen fallPeriod decayClass orientation bioticAttack
## 1 2011 2013 NA 3 1
## 2 #N/A #N/A NA NA
## bioticAgent1 bioticAgent2 bioticAgent3 MechAgents oldTag
## 1 IPS NA
## 2 NA
## notes X X.1 X.2 X.3 X.4 X.5 X.6
## 1 2011: Ips - small diameter (Dead-Still standing) NA NA NA NA NA NA NA
## 2 NA NA NA NA NA NA NA
## X.7
## 1 NA
## 2 NA
# subset to only needed columns
names(mrs_tab)
## [1] "Plot" "Tree" "Spec" "dbh1" "dbh3"
## [6] "dbh4" "YrCHt" "hc1" "hc2" "hc3"
## [11] "hc4" "recruitYr" "dead" "deadPeriod" "dp.start"
## [16] "dp.end" "fallen" "fallPeriod" "decayClass" "orientation"
## [21] "bioticAttack" "bioticAgent1" "bioticAgent2" "bioticAgent3" "MechAgents"
## [26] "oldTag" "notes" "X" "X.1" "X.2"
## [31] "X.3" "X.4" "X.5" "X.6" "X.7"
mrs_tab <- mrs_tab[c(1:6, 8:14, 17:18, 21:22, 25)]
# Examine update
names(mrs_tab)
## [1] "Plot" "Tree" "Spec" "dbh1" "dbh3"
## [6] "dbh4" "hc1" "hc2" "hc3" "hc4"
## [11] "recruitYr" "dead" "deadPeriod" "fallen" "fallPeriod"
## [16] "bioticAttack" "bioticAgent1" "MechAgents"
# table
table(mrs_tab$Plot)
##
## BL6 BW2 BW3 MRS1 MRS10 MRS11 MRS12 MRS13 MRS4 MRS5 MRS7 MRS8 MRS9
## 538 499 350 879 265 526 570 305 752 565 722 430 241
# create mrs1_tab
mrs1_tab <- mrs_tab %>%
filter(Plot == "MRS1")
Below the process is:
Load Spatial Data
Grab Coordinates for each tree
Set data types for each column in dataset
Remove the NA values (which would be trees that were missed)
Merge the tabular and spatial data
Add plot characteristics
Examine
# MRS 1
mrs1_shp <- sf::st_read("D:/Dissertation/Analysis/Chapter_2/data/shapefiles_raw/MRS1_tree_stem_map_2019.shp")
## Reading layer `MRS1_tree_stem_map_2019' from data source
## `D:\Dissertation\Analysis\Chapter_2\data\shapefiles_raw\MRS1_tree_stem_map_2019.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 874 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 454690.4 ymin: 4431774 xmax: 454711.4 ymax: 4431827
## Projected CRS: NAD83 / UTM zone 13N
# examine dataset
names(mrs1_shp)
## [1] "TreeNum" "TreeN_str" "geometry"
# grab shp coords
tree_coords <- sf::st_coordinates(mrs1_shp) %>% as.data.frame()
mrs1_shp$X <- tree_coords$X
mrs1_shp$Y <- tree_coords$Y
# make numeric or factor
mrs1_tab$Plot <- as.factor(mrs1_tab$Plot) # tree = factor
mrs1_tab$Tree <- as.integer(mrs1_tab$Tree) # tree = factor
mrs1_tab$Spec <- as.factor(mrs1_tab$Spec) # tree = factor
mrs1_tab$dbh1 <- as.numeric(mrs1_tab$dbh1) # dbh = numeric
mrs1_tab$dbh3 <- as.numeric(mrs1_tab$dbh3) # dbh = numeric
mrs1_tab$dbh4 <- as.numeric(mrs1_tab$dbh4) # dbh = numeric
mrs1_tab$hc1 <- as.numeric(mrs1_tab$hc1) # hc = numeric
mrs1_tab$hc3 <- as.numeric(mrs1_tab$hc3) # hc = numeric
mrs1_tab$hc4 <- as.numeric(mrs1_tab$hc4) # hc = numeric
mrs1_tab$dead <- as.factor(mrs1_tab$dead) # tree = factor
mrs1_tab$fallen <- as.factor(mrs1_tab$fallen) # fallen = factor
mrs1_tab$bioticAttack <- as.factor(mrs1_tab$bioticAttack) # agent presence = factor
# Remove NAs
mrs1_tab$dbh1 <- ifelse(is.na(mrs1_tab$dbh1) == TRUE, 0, mrs1_tab$dbh1) # dbh3
mrs1_tab$dbh3 <- ifelse(is.na(mrs1_tab$dbh3) == TRUE, mrs1_tab$dbh1, mrs1_tab$dbh3) # dbh3
mrs1_tab$dbh4 <- ifelse(is.na(mrs1_tab$dbh4) == TRUE, mrs1_tab$dbh3, mrs1_tab$dbh4) # dbh4
mrs1_tab$hc3 <- ifelse(is.na(mrs1_tab$hc3) == TRUE, mrs1_tab$hc1, mrs1_tab$hc3) # hc3
mrs1_tab$hc4 <- ifelse(is.na(mrs1_tab$hc4) == TRUE, mrs1_tab$hc3, mrs1_tab$hc4) # hc4
mrs1_tab$dead <- ifelse(is.na(mrs1_tab$dead) == TRUE, 0, mrs1_tab$dead) # dead
# check
table(is.na(mrs1_tab$dbh1))
##
## FALSE
## 879
table(is.na(mrs1_tab$dbh3))
##
## FALSE
## 879
table(is.na(mrs1_tab$dbh4))
##
## FALSE
## 879
table(mrs1_tab$dead)
##
## 1 2 3
## 1 647 231
# spatial names - match tab dataset
names(mrs1_shp)[1] <- "Tree"
mrs1_shp <- mrs1_shp[c(1,3:5)]
mrs1_shp <- mrs1_shp[c(1, 3:4, 2)]
names(mrs1_shp)
## [1] "Tree" "X" "Y" "geometry"
# Create spatial dataset
mrs_1_spatial <- merge(mrs1_tab, mrs1_shp, by = "Tree")
names(mrs_1_spatial); head(mrs_1_spatial); nrow(mrs_1_spatial)
## [1] "Tree" "Plot" "Spec" "dbh1" "dbh3"
## [6] "dbh4" "hc1" "hc2" "hc3" "hc4"
## [11] "recruitYr" "dead" "deadPeriod" "fallen" "fallPeriod"
## [16] "bioticAttack" "bioticAgent1" "MechAgents" "X" "Y"
## [21] "geometry"
## Tree Plot Spec dbh1 dbh3 dbh4 hc1 hc2 hc3 hc4 recruitYr dead deadPeriod
## 1 1 MRS1 PICO 6 8.8 8.8 3 3 3 3 NA 3 8
## 2 2 MRS1 PICO 21 24.1 25.4 1 1 1 1 NA 2 0
## 3 3 MRS1 PICO 12 14.3 15.2 1 1 1 1 NA 2 0
## 4 4 MRS1 PICO 24 25.5 25.8 1 1 1 1 NA 2 0
## 5 5 MRS1 PICO 17 18.5 19.5 1 1 1 1 NA 2 0
## 6 6 MRS1 PICO 10 11.3 11.8 2 2 2 2 NA 2 0
## fallen fallPeriod bioticAttack bioticAgent1 MechAgents X Y
## 1 <NA> 1 IPS 454691.9 4431826
## 2 <NA> 454691.4 4431824
## 3 <NA> 454690.7 4431822
## 4 <NA> 454691.3 4431822
## 5 <NA> 454691.3 4431822
## 6 <NA> 454691.8 4431819
## geometry
## 1 POINT (454691.9 4431826)
## 2 POINT (454691.4 4431824)
## 3 POINT (454690.7 4431822)
## 4 POINT (454691.3 4431822)
## 5 POINT (454691.3 4431822)
## 6 POINT (454691.8 4431819)
## [1] 870
# add plot characteristics
mrs_1_spatial$elev <- 2900
mrs_1_spatial$aspect <- 90
mrs_1_spatial$moist <- "Xeric"
mrs_1_spatial$age <- "Young Post-fire Monotypic Lodgepole"
mrs_1_spatial <- mrs_1_spatial[c(1:20, 22:25, 21)]
# check
table(is.na(mrs_1_spatial$dbh1))
##
## FALSE
## 870
table(is.na(mrs_1_spatial$dbh3))
##
## FALSE
## 870
table(is.na(mrs_1_spatial$dbh4))
##
## FALSE
## 870
Right now we only have the DBH collected for Census 1 (1982 or 1983), Census 3 (2016), and Census 4 (2022). Census 2 (2007) is thrown out.
I wanted to calculate the annualized growth between census periods both in the DBH values and basal area.
Growth is calculated as follows:
Setting Growth for census 1 as 0 (The start)
Subtracting the size of the tree at census 1 from census 3.
Subtracting the size of the tree at census 3 from census 4.
Dividing those values by the number of years between data collection periods. 34 years for 1 to 3, 6 years for 3 to 4.
# growth
mrs_1_spatial$growth_0 <- 0
mrs_1_spatial$growth_0_annual <- 0
mrs_1_spatial$growth_1 <- as.numeric((mrs_1_spatial$dbh3 - mrs_1_spatial$dbh1))
mrs_1_spatial$growth_1 <- ifelse(mrs_1_spatial$growth_1 < 0, 0, mrs_1_spatial$growth_1)
mrs_1_spatial$growth_1_annual <- (mrs_1_spatial$growth_1 / 34)
mrs_1_spatial$growth_2 <- as.numeric((mrs_1_spatial$dbh4 - mrs_1_spatial$dbh3))
mrs_1_spatial$growth_2 <- ifelse(mrs_1_spatial$growth_2 < 0, 0, mrs_1_spatial$growth_2)
mrs_1_spatial$growth_2_annual <- (mrs_1_spatial$growth_2 / 6)
Basal area for each tree was caluclated using the foresters constant multipled by the diameter squared
0.005454 × DBH^2
After that was calculated, the values were also annualized as shown above.
# BA
mrs_1_spatial$BA_1 <- (mrs_1_spatial$dbh1^2 * 0.005454)
mrs_1_spatial$BA_3 <- (mrs_1_spatial$dbh3^2 * 0.005454)
mrs_1_spatial$BA_4 <- (mrs_1_spatial$dbh4^2 * 0.005454)
mrs_1_spatial$BA_1_growth <- 0
mrs_1_spatial$BA_1_growth_annual <- 0
mrs_1_spatial$BA_3_growth <- (mrs_1_spatial$BA_3 - mrs_1_spatial$BA_1)
mrs_1_spatial$BA_3 <- ifelse(mrs_1_spatial$BA_3_growth < 0, 0, mrs_1_spatial$BA_3_growth)
mrs_1_spatial$BA_3_growth_annual <- (mrs_1_spatial$BA_3_growth / 34)
mrs_1_spatial$BA_4_growth <- (mrs_1_spatial$BA_4 - mrs_1_spatial$BA_3)
mrs_1_spatial$BA_4_growth <- ifelse(mrs_1_spatial$BA_4_growth < 0, 0, mrs_1_spatial$BA_4_growth)
mrs_1_spatial$BA_4_growth_annual <- (mrs_1_spatial$BA_4_growth / 6)
head(mrs_1_spatial)
## Tree Plot Spec dbh1 dbh3 dbh4 hc1 hc2 hc3 hc4 recruitYr dead deadPeriod
## 1 1 MRS1 PICO 6 8.8 8.8 3 3 3 3 NA 3 8
## 2 2 MRS1 PICO 21 24.1 25.4 1 1 1 1 NA 2 0
## 3 3 MRS1 PICO 12 14.3 15.2 1 1 1 1 NA 2 0
## 4 4 MRS1 PICO 24 25.5 25.8 1 1 1 1 NA 2 0
## 5 5 MRS1 PICO 17 18.5 19.5 1 1 1 1 NA 2 0
## 6 6 MRS1 PICO 10 11.3 11.8 2 2 2 2 NA 2 0
## fallen fallPeriod bioticAttack bioticAgent1 MechAgents X Y elev
## 1 <NA> 1 IPS 454691.9 4431826 2900
## 2 <NA> 454691.4 4431824 2900
## 3 <NA> 454690.7 4431822 2900
## 4 <NA> 454691.3 4431822 2900
## 5 <NA> 454691.3 4431822 2900
## 6 <NA> 454691.8 4431819 2900
## aspect moist age geometry
## 1 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454691.9 4431826)
## 2 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454691.4 4431824)
## 3 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454690.7 4431822)
## 4 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454691.3 4431822)
## 5 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454691.3 4431822)
## 6 90 Xeric Young Post-fire Monotypic Lodgepole POINT (454691.8 4431819)
## growth_0 growth_0_annual growth_1 growth_1_annual growth_2 growth_2_annual
## 1 0 0 2.8 0.08235294 0.0 0.00000000
## 2 0 0 3.1 0.09117647 1.3 0.21666667
## 3 0 0 2.3 0.06764706 0.9 0.15000000
## 4 0 0 1.5 0.04411765 0.3 0.05000000
## 5 0 0 1.5 0.04411765 1.0 0.16666667
## 6 0 0 1.3 0.03823529 0.5 0.08333333
## BA_1 BA_3 BA_4 BA_1_growth BA_1_growth_annual BA_3_growth
## 1 0.196344 0.2260138 0.4223578 0 0 0.2260138
## 2 2.405214 0.7625237 3.5187026 0 0 0.7625237
## 3 0.785376 0.3299125 1.2600922 0 0 0.3299125
## 4 3.141504 0.4049595 3.6304006 0 0 0.4049595
## 5 1.576206 0.2904255 2.0738835 0 0 0.2904255
## 6 0.545400 0.1510213 0.7594150 0 0 0.1510213
## BA_3_growth_annual BA_4_growth BA_4_growth_annual
## 1 0.006647464 0.1963440 0.0327240
## 2 0.022427169 2.7561789 0.4593631
## 3 0.009703308 0.9301797 0.1550299
## 4 0.011910574 3.2254411 0.5375735
## 5 0.008541926 1.7834580 0.2972430
## 6 0.004441802 0.6083937 0.1013989