-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.Rmd
180 lines (123 loc) · 8.29 KB
/
analysis.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
---
title: "Plant Phenology"
author: "Maxwell Patterson"
date: "`r Sys.Date()`"
---
### Overview
This project presents a comprehensive workflow for investigating plant phenology in the context of climate change, focusing on the Santa Clara River area. Plant phenology, the study of the timing of life cycle events, is an important ecological field that helps us understand how plant species synchronize their growth, flowering, and senescence with local climate conditions. As climate change changes these conditions, phenological shifts can disrupt ecosystem balances that affect plant and animal species in a harmful way.
This code explores phenology in three distinct plant communities along the Santa Clara River: riparian forests, grasslands, and chaparral shrublands, each characterized by different survival strategies. Riparian forests, which are winter deciduous, shed leaves in winter and regrow them in spring. Grasslands, dominated by drought deciduous grasses, lose leaves in summer due to water scarcity. Chaparral shrublands consist of evergreen shrubs that maintain leaves year-round.
### Data
The study utilizes a time series of Landsat imagery to assess vegetation productivity using the Normalized Difference Vegetation Index (NDVI), which indicates the presence and health of green vegetation. Eight pre-processed Landsat scenes, specifically Level 2 surface reflectance products with scale factors adjusted, form the basis of the analysis. These scenes have been cleaned of erroneous values and encompass bands 2-7, with dates embedded in the filenames.
Furthermore, study site polygons are provided, representing various plant community locations. These sites are labeled with the type of plant community they represent, which includes the riparian forests, grasslands, and chaparral shrublands.
Landsat data: “Operational Land Imager.” NASA, December 9, 2021. https://landsat.gsfc.nasa.gov/satellites/landsat-8/spacecraft-instruments/operational-land-imager/.
### Approach
The approach involves the conversion of spectral reflectance data into NDVI. This involves calculating NDVI values throughout the year and summarizing these values within the identified vegetation types. The last phase of the workflow is the visualization of the NDVI changes within these ecosystems, allowing for a comparison of phenological patterns and adaptations across the different vegetation types.
The resulting visualizations illustrate the seasonal cycles of vegetation productivity, offering insights into the phenological strategies of the plant communities. This analysis serves as a measure for gauging the impact of climate change on local ecosystems and provides a foundation for further ecological management and conservation efforts.
First. let's import the necessary libraries.
```{r, message=FALSE}
library(terra)
library(sf)
library(dplyr)
library(tidyr)
library(stringr)
library(ggplot2)
library(here)
library(tmap)
library(cowplot)
rm(list = ls())
```
### NDVI Computation
The first step entails creating a function to calculate NDVI.
```{r}
ndvi_fun = function(nir, red){
(nir - red) / (nir + red)
}
```
#### Processing Individual Scenes
Load and process the Landsat scenes, updating the band names to reflect the actual spectral bands and applying the NDVI function.
```{r}
# loading Landsat from June 12 2018
landsat_20180612 <- rast(here("data/landsat_20180612.tif"))
names(landsat_20180612) <- c("blue", "green", "red", "NIR", "SWIR1", "SWIR2")
# apply NDVI function to compute the index
ndvi_20180612 <- lapp(landsat_20180612[[c(4, 3)]], fun = ndvi_fun)
# show results
ndvi_20180612
```
#### Automating NDVI Across All Scenes
To enhance efficiency, we automate the NDVI calculations across all available scenes using a more streamlined approach.
```{r}
# generate a list of file paths for Landsat
files <- list.files(here("data"), pattern = "*.tif", full.names = TRUE)
# update function to create NDVI layers and stack them
create_ndvi_layer <- function(i){
landsat <- rast(files[i])
names(landsat) <- c("blue", "green", "red", "NIR", "SWIR1", "SWIR2")
ndvi <- lapp(landsat[[c(4, 3)]], fun = ndvi_fun)
}
# apply function across all files to create a stack of NDVI layers
all_ndvi <- c(create_ndvi_layer(1),
create_ndvi_layer(2),
create_ndvi_layer(3),
create_ndvi_layer(4),
create_ndvi_layer(6),
create_ndvi_layer(7),
create_ndvi_layer(8),
create_ndvi_layer(9))
# update layer names to match date
names(all_ndvi) <- c("2018-06-12",
"2018-08-15",
"2018-10-18",
"2018-11-03",
"2019-01-22",
"2019-02-23",
"2019-04-12",
"2019-07-01")
```
#### Compare NDVI Across Vegetation Communities
Now that we have the NDVI for each date, we will compare changes in NDVI across different types of vegetation.
First, we want to read in the study site shapefile and plot it for inspection.
```{r}
# read in file
sites <- st_read(here("data", "study_sites.shp"))
# plot study sites on a single NDVI layer
tm_shape(all_ndvi[[1]]) +
tm_raster() +
tm_shape(sites) +
tm_polygons()
```
Great. The next step of the analysis involves extracting the average NDVI for each study site. This information will be added to the sites dataset that was just loaded in.
```{r}
# extract average NDVI for each site
sites_ndvi <- terra::extract(all_ndvi, sites, fun = "mean")
# append result to site data
sites_annotated <- cbind(sites, sites_ndvi)
```
### Cleaning and Results
Almost there! Next, let's clean up the data and make it easier to visualize by converting it to a dataframe, turning it from wide to long format, and changing layer names into dateformat format for convenience.
```{r}
sites_clean <- sites_annotated %>%
st_drop_geometry() %>%
select(-ID) %>%
pivot_longer(!study_site) %>%
rename("NDVI" = value) %>%
mutate("year" = str_sub(name, 2, 5),
"month" = str_sub(name, 7, 8),
"day" = str_sub(name, -2, -1)) %>%
unite("date", 4:6, sep = "-") %>%
mutate("date" = lubridate::as_date(date))
```
Great! Finally, let's plot the visual.
```{r}
ggplot(sites_clean,
aes(x = date, y = NDVI,
group = study_site, col = study_site)) +
geom_line() +
scale_color_manual(values = c("#1F77B4", "#FF7F0E", "#2CA02C", "#D62728", "#9467BD")) +
theme_minimal() +
labs(x = "", y = "Normalized Difference Vegetation Index (NDVI)", col = "Vegetation type",
title = "Seasonal Cycles of Vegetation Productivity")
```
The final visualization provides a summary of how different vegetation types along the Santa Clara River area respond to seasonal changes, a phenomenon linked to plant phenology and indicative of broader ecological responses to climate change. Using the NDVI to track vegetation productivity, we observed distinct seasonal patterns in vegetation types, including riparian forests, grasslands, and chaparral shrublands, over a one-year period from July 2018 to July 2019.
Chaparral areas, characterized by their evergreen shrubbery, demonstrated the least variation in NDVI values. This suggests a resilience to seasonal changes in chaparrals, likely due to their adaptation to arid conditions. In contrast, riparian forests, which follow a winter deciduous pattern, showed a strong decline in NDVI during the colder fall and winter months, and followed by a resurgence in the spring, aligning with their life cycle of leaf loss and regrowth. Grasslands, predominantly composed of drought deciduous grasses, presented the most notable seasonal fluctuation, plunging in productivity during the dry seasons and rebounding during the wetter months, revealing their adaptation to water availability.
This analysis not only highlights the phenological strategies employed by each plant community, but also points towards potential changes that may be occurring because of climate change. The synchronization of life cycle events with seasonal climatic patterns is critical for the successful reproduction of all plant species and, consequently, for the survival of dependent animal species that rely on these plants for food and shelter. As climate conditions shift, these phenological events may become out of sync, potentially leading to mismatches in food availability and affecting the entire ecosystem.