-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
196 lines (134 loc) · 6.37 KB
/
README.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
sapply(c("sim_data_01.rda", "sim_result_01.rda"), function(x) {
load(file.path(system.file("extdata", package = "rangr"), x),
envir = globalenv()
)
})
library(rangr)
```
# rangr
<!-- badges: start -->
[![Status at rOpenSci Software Peer Review](https://badges.ropensci.org/595_status.svg)](https://github.com/ropensci/software-review/issues/595) [![Project Status: Active -- The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![R-CMD-check](https://github.com/ropensci/rangr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/rangr/actions/workflows/R-CMD-check.yaml) [![codecov](https://codecov.io/gh/ropensci/rangr/graph/badge.svg?token=noq7E0HSe2)](https://codecov.io/gh/ropensci/rangr) [![DOI](https://zenodo.org/badge/645848364.svg)](https://zenodo.org/doi/10.5281/zenodo.10569367)
<!-- badges: end -->
The **rangr** package is designed to simulate a species range dynamics. This new tool mimics the essential processes that shape population numbers and spatial distribution: local dynamics and dispersal. Simulations can be run in a spatially explicit and dynamic environment, facilitating population projections in response to climate or land-use changes. By using different sampling schemes and observational error distributions, the structure of the original survey data can be reproduced, or pure random sampling can be mimicked.
The study is supported by the National Science Centre, Poland, grant no. 2018/29/B/NZ8/00066 and the Poznań Supercomputing and Networking Centre (grant no. 403).
# Installation
## Development version
You can install the development version from R-universe or GitHub with:
```{r instalation_dev, eval=FALSE}
install.packages("rangr", repos = "https://ropensci.r-universe.dev")
# or
devtools::install_github("ropensci/rangr")
```
# Basic simulation
Here's an example of how to use the `rangr` package.
## Input maps
Example maps available in rangr in the Cartesian coordinate system:
- `n1_small.tif`
- `n1_big.tif`
- `K_small.tif`
- `K_small_changing.tif`
- `K_big.tif`
Example maps available in rangr in the longitude/latitude coordinate system:
- `n1_small_lon_lat.tif`
- `n1_big_lon_lat.tif`
- `K_small_lon_lat.tif`
- `K_small_changing_lon_lat.tif`
- `K_big_lon_lat.tif`
```{r SP1.0, eval=FALSE, include=FALSE}
#' @srrstats {SP1.0} Specified domain of applicability
```
You can find additional information about these data sets in help files:
```{r help_input_maps, eval=FALSE}
library(rangr)
?n1_small.tif
?K_small.tif
```
Two of the available datasets, `n1_small.tif` and `K_small.tif`, represent the abundance of a virtual species at the starting point of a simulation and the carrying capacity of the environment, respectively. Both of these objects refer to the same relatively small area, so they are ideal for demonstrating the usage of the package. To view these maps and their dimensions, you can use the following commands:
```{r small_data, warning=FALSE}
library(terra)
n1_small <- rast(system.file("input_maps/n1_small.tif", package = "rangr"))
K_small <- rast(system.file("input_maps/K_small.tif", package = "rangr"))
```
You can also use the `plot` function from the `terra` package to visualize these maps:
```{r vis_input_maps, fig.align='center', message=FALSE, out.width='70%'}
plot(c(n1_small, K_small))
```
## Initialise
To create a `sim_data` object containing the necessary information to run a simulation, use the `initialise()` function. For example:
```{r init}
sim_data_01 <- initialise(
n1_map = n1_small,
K_map = K_small,
r = log(2),
rate = 1 / 1e3
)
```
Here, we set the intrinsic population growth rate to `log(2)` and the rate parameter that is related to the kernel function describing dispersal to `1/1e3`.
To see the summary of the `sim_data` object:
```{r summary_sim_data}
summary(sim_data_01)
```
## Simulation
To run a simulation, use the `sim()` function, which takes a `sim_data` object and the specified number of time steps as input parameters. For example:
```{r sim, eval=FALSE}
sim_result_01 <- sim(obj = sim_data_01, time = 100)
```
To see the summary of the `sim_result_01` object:
```{r summary_sim_res, fig.align='center', message=FALSE, out.width='70%'}
summary(sim_result_01)
```
Note that this is a simple example and there are many more parameters that can be set for `initialise()` and `sim()`. See the documentation for the `rangr` package for more information.
## Visualisation
You can use `rangr` to visualise selected time steps from the simulation. The `plot()` method is used to generate the plot. Here's an example:
```{r vis_sim_res_01, warning=FALSE, fig.align='center', message=FALSE, out.width='70%'}
# generate visualisation
plot(sim_result_01,
time_points = c(1, 10, 25, 50),
template = sim_data_01$K_map
)
```
You can adjust the `breaks` parameter to get more breaks on the colorscale:
```{r vis_sim_res_02, warning=FALSE, fig.align='center', message=FALSE, out.width='70%'}
# generate visualisation with more breaks
plot(sim_result_01,
time_points = c(1, 10, 25, 50),
breaks = seq(0, max(sim_result_01$N_map + 5, na.rm = TRUE), by = 5),
template = sim_data_01$K_map
)
```
If you prefer working on raster you can also transform any `sim_result` object into `SpatRaster` using `to_rast()` function:
```{r vis_sim_res_03, warning=FALSE, fig.align='center', message=FALSE, out.width='70%'}
# raster construction
my_rast <- to_rast(
sim_result_01,
time_points = 1:sim_result_01$simulated_time,
template = sim_data_01$K_map
)
# print raster
print(my_rast)
```
And then visualise it using `plot()` function:
```{r vis_sim_res_04, warning=FALSE, fig.align='center', message=FALSE, out.width='70%'}
# plot selected time points
plot(my_rast, c(1, 10, 25, 50))
```
# Vignettes
- [Workflow examples](https://docs.ropensci.org/rangr/articles/rangr.html)
# Citation
To cite `rangr` use `citation()` function:
```{r citation, eval=FALSE}
library(rangr)
citation("rangr")
```
# Code of Conduct
Please note that this package is released with a [Contributor Code of Conduct](https://ropensci.org/code-of-conduct/). By contributing to this project, you agree to abide by its terms.