-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
104 lines (78 loc) · 2.84 KB
/
README.Rmd
File metadata and controls
104 lines (78 loc) · 2.84 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# spInterp: Spatial Interpolation
<!-- badges: start -->
[](https://github.com/rpkgs/spInterp/actions)
[](https://app.codecov.io/gh/rpkgs/spInterp)
[](https://cran.r-project.org/package=spInterp)
<!-- [](https://www.rpackages.io/package/spInterp)
[](https://www.rpackages.io/package/spInterp) -->
<!-- badges: end -->
## Installation
You can install the development version of spInterp from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("rpkgs/spInterp")
```
## On top of
1. <https://github.com/PanfengZhang/adw>
2. <https://github.com/rrodrigojrr/ADW>
## TODO
- [ ] Thin Plate Spline
- [ ] P-Spline
- [ ] Krige
## Performance
```{r}
library(spInterp)
library(adw)
data(TempBrazil) # Temperature for some poins of Brazil
X <- TempBrazil[, 1:2] %>% set_names(c("lon", "lat"))
Y <- TempBrazil[, 3] %>% as.matrix() # Vector with observations in points
range <- c(-78, -34, -36, 5)
res = 1
# Compare with the R package adw
dd = cbind(X, value = Y[,1])
```
```{r}
system.time({
r_adw <- adw::adw(dd, range, cdd = 450 * 1e3, gridsize = res)
})
# profvis::profvis({
system.time({
r <- spInterp_adw(X, Y, range, res = res, cdd = 450)
})
```
```{r, message=FALSE}
df = rbind(
r %$% cbind(coord, value = predicted[, 1], method = "spInterp"),
cbind(r_adw, method = "adw"))
library(ggplot2)
ggplot(df, aes(lon, lat)) +
geom_raster(aes(fill = value)) +
geom_point(data = X, size = 1, shape = 3, color = "red") +
facet_wrap(~method) +
lims(x = range[1:2], y = range[3:4]) -> p
p
# Ipaper::write_fig(p, "figure1.pdf", 10, 6)
```
`spInterp` used the exactly same algrithm as that of `adw` package.
But unlike `adw`, `spInterp` avoids using `sf` for spatial data processing such as
buffer, intersect. Surprisingly, `spInterp` is dozens of times faster.
There is a slight difference from `adw` in the calculation of the distance between
two points on the sphere, because `spInterp` uses self defined function, while
`adw` uses `sf::st_distance`. But the difference is tiny (might about 1%), can be
ignored at most situation.
## References
1. Xavier, A. C., King, C. W., & Scanlon, B. R. (2016). Daily gridded
meteorological variables in Brazil (1980–2013). International Journal of
Climatology, 36(6), 2644–2659. <doi:10.1002/joc.4518>