-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsec3.qmd
124 lines (100 loc) · 4.41 KB
/
sec3.qmd
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
# Spatial analysis for remote sensing data
We demonstrate a spatial analysis workflow using the 2024 climate and bushfire data as an example.
We will perform spatial hot spot and cold spot analysis using the **rgeoda** package and conduct spatial stratified heterogeneity analysis using the **gdverse** package.
You can install the required packages using the following commands in the R console:
```r
install.packages(c("sf","terra","tidyverse","rgeoda","gdverse","gpboost"),dep = TRUE)
```
Now we read the data to R and perform some basic data exploration:
```{r fig-data-exploration, cache = FALSE, message = FALSE, echo=!knitr::is_latex_output()}
#| fig.cap: "Maps of the 2024 climate and bushfire data"
#| code-fold: true
#| fig.height: 3.5
library(terra)
burnedarea = rast('./data/1. Data collection/BurnedArea/BurnedArea_2024.tif')
burnedarea
pre = rast('./data/1. Data collection/Pre/Pre2024.tif')
pre
tem = rast('./data/1. Data collection/Tem/Tem2024.tif')
tem
par(mfrow = c(1, 3))
plot(burnedarea, main = 'Burned area')
plot(pre, main = 'Precipitation')
plot(tem, main = 'Temperature')
par(mfrow = c(1, 1))
```
Since the row and column numbers of the three rasters are not aligned, we first convert the non-NA cells of the temperature raster into a spatial polygon format. Then, we perform zonal statistics on temperature and wildfire data, and finally, remove all NA values corresponding to the three variables.
```{r fig-map-sf-format, cache = FALSE, message = FALSE, echo=!knitr::is_latex_output()}
#| fig.cap: "Maps of the 2024 climate and bushfire data in sf format"
#| code-fold: true
#| fig.height: 3.5
tem.polygon = terra::as.polygons(tem,aggregate = FALSE)
names(tem.polygon) = "tem"
tem.polygon$pre = terra::zonal(pre,tem.polygon,fun = "mean",na.rm = TRUE)[,1]
tem.polygon$burnedarea = terra::zonal(burnedarea,tem.polygon,fun = "sum",na.rm = TRUE)[,1]
burnedarea.sf = sf::st_as_sf(tem.polygon) |>
dplyr::filter(dplyr::if_all(1:3,\(.x) !is.na(.x)))
burnedarea.sf
library(sf)
plot(burnedarea.sf)
```
save the data to a shapefile:
```{r, eval = FALSE}
#| code-fold: true
sf::write_sf(burnedarea.sf,'./data/3. Spatial analysis/burnedarea_2024.shp',overwrite = TRUE)
```
## Spatial hotspot identification
::: {.callout-tip title="Aim"}
This step is designed to identify the spatial hot and cold spots of bushfire burned areas, which will be performed using the **rgeoda** package.
:::
::: {.callout-caution title="Description of steps"}
1. Load necessary libraries (sf for spatial data, rgeoda for spatial analysis, ggplot2 for data visualization).
2. Read the burned area and climate data.
3. Create the spatial weight matrix.
4. Run spatial hotspot analysis.
5. Plot the result.
:::
```{r fig-spatial-hotspot, cache = FALSE, message = FALSE, echo=!knitr::is_latex_output()}
#| fig.cap: "Bushfire burned area spatial hotspot analysis"
#| code-fold: true
#| fig.height: 4.5
library(sf)
library(rgeoda)
library(ggplot2)
burnedarea = read_sf('./data/3. Spatial analysis/burnedarea_2024.shp')
queen_w = queen_weights(burnedarea)
lisa = local_gstar(queen_w, burnedarea["burnedarea"])
cats = lisa_clusters(lisa,cutoff = 0.05)
burnedarea$hcp = factor(lisa_labels(lisa)[cats + 1],level = lisa_labels(lisa))
p_color = lisa_colors(lisa)
names(p_color) = lisa_labels(lisa)
p_label = lisa_labels(lisa)[sort(unique(cats + 1))]
ggplot(burnedarea) +
geom_sf(aes(fill = hcp)) +
scale_fill_manual(
values = p_color,
labels = p_label) +
theme_minimal() +
labs(fill = "Cluster Type")
```
## Geographical detector for spatial heterogeneity and factor analysis
::: {.callout-tip title="Aim"}
This step is designed to identify the climatic driving factors of bushfire burned area. We will use the **gdverse** package to analyze the power of determinant of climatic drivers on bushfire burned area based on the optimal parameter geographical detector model.
:::
::: {.callout-caution title="Description of steps"}
1. Load necessary libraries (sf for spatial data and gdverse for geographical detector analysis).
2. Read the burned area and climate data.
3. Run the OPGD model.
4. Plot the result.
:::
```{r fig-opgd, cache = FALSE, message = FALSE, echo=!knitr::is_latex_output()}
#| fig.cap: "Climatic driving factors of bushfire burned area"
#| code-fold: true
#| fig.height: 3.5
library(sf)
library(gdverse)
burnedarea = read_sf('./data/3. Spatial analysis/burnedarea_2024.shp')
opgd.m = opgd(burnedarea~tem+pre, data = burnedarea, discnum = 3:15)
opgd.m
plot(opgd.m)
```