-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-LoadManipTrend.Rmd
116 lines (68 loc) · 3.03 KB
/
03-LoadManipTrend.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
---
output: html_document
editor_options:
chunk_output_type: console
---
# Trends
```{r tidyr3, echo = FALSE, message = FALSE, warning = FALSE}
library(knitr)
opts_chunk$set(tidy.opts=list(width.cutoff=50), tidy = FALSE)
editor_options:
chunk_output_type: console
```
These scripts set up the data for each site, run the seasonal species-specific analysis, and plot the output for review. Most of the heavy lifting is done in the background. However, if something breaks or doesn't work, the analysis may haul.
## Setup
The setup files will get you ready for your analysis. It loads you libraries, needed tables, created directories for your outputs, and assigns some parameter values.
Also assign max year of the analysis. Generally, the data in NatureCounts are 2 years behind.
```{r setup}
max.yr <- 2023 #needs changes with each analysis
ID<- "dethier" #change this to your user ID. You will be prompted for a password.
```
## Choose your RPI station
The number assigned to `t` will correspond to the row in the analysis parameters file ('anal.param') you want to analyze (each site has a separate row).
View the file to identify the row you want to select
```{r view}
## Import site-specific analysis parameters
##This will need checked and updated before each analysis
anal.param <- read.csv("Data/RPI_Analysis_Parameters.csv")
##Keep just the site number
#anal.param$SiteCode<-as.numeric(gsub("HawkCount-", "", anal.param$SiteCode))
#View(anal.param)
```
Select your station/season.
```{r chooseSite}
t <- 76
```
## Data manipulations
Now that you have selected the RPI site/ season, we are going to clean the data. The cleaning scripts do the following:
- Load the data from the naturecounts database. You will be prompted for your password. The code will first look to see if the data have been downloaded and stored.
- Subset data to min and max year based on analysis parameters file.
- Calculate season-specific station windows (when a station normally operates).
- Make list of sampling dates for zero-filling
- Generates a species list for the analysis
- Create output tables for the analysis
First, assign 'u' your NatureCounts username and run the `prepare` scripts.
```{r data manip}
source("i_outputs.R")
```
## Data Analysis
From this point forward, we loop through species and season:
1) Zero-fill the data using the `events` matrix
2) Apply species-specific filters to abundance (mean 10 individuals/year), occurrence (mean 5 observation days/year), and drop years with no observations.
3) Run the trend analysis by looping through year periods (all years, 10-years, and 3-generations)
```{r analysis}
source("ii_analysis.R")
```
## Plot Trends
```{r Plot trends}
source("iii_plottrend.R")
```
## Plot Station Coverage
```{r Plot coverage}
source("iv_plotcoverage.R")
```
## Analysis Loop
Once you are happy with how everything is going, you may choose to run all the 3 steps by looping through each row in the analysis parameters file. This is a unsupervised process.
```{r Loop}
source("v_loop.R")
```