-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_targets.Rmd
94 lines (67 loc) · 3 KB
/
run_targets.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
---
title: "Run Targets - Landsat Collection 2 SR Acquisition"
subtitle: "GLORIA and Maciel data pull"
date: "`r Sys.Date()`"
author: "ROSSyndicate"
output:
html_document: default
pdf_document: default
---
# Purpose
This script loads all necessary packages to run the targets pipeline, then runs it! This particular instance pulls the historical Landsat record for the collated locations from the GLORIA dataset and the matched Maciel, et al dataset.
Running this pipeline requires access to the ROSSyndicate Google Account as written, but can easily be updated to a different Google Account and eeProject by altering the config file ('gloria_config.yml').
## Install necessary packages
```{r package_installer, echo = F}
package_installer <- function(x) {
if (x %in% installed.packages()) {
print(paste0('{', x ,'} package is already installed.'))
} else {
install.packages(x)
print(paste0('{', x ,'} package has been installed.'))
}
}
```
List packages that need to be checked for install, and walk the function along them all.
```{r walk_package_installer, message = F}
packages <- c('tidyverse',
'reticulate',
'targets',
'tarchetypes',
'yaml',
'readr',
'sf')
invisible(lapply(packages, package_installer))
```
## Authenticate and initialize Earth Engine
You will need to have [installed and initialized the `gcloud CLI`](https://cloud.google.com/sdk/docs/install) and have a [Google Earth Engine account](https://code.earthengine.google.com/register) prior to running this workflow. Some common troubleshooting solutions [can be found here]<https://github.com/rossyndicate/ROSS_RS_mini_tools/blob/main/helps/CommonIssues.md>).
### Set up your Python environment
```{r eval = F}
library(reticulate)
if (!dir.exists("env")) {
source("data_acquisition/src/pySetup.R")
} else {
use_condaenv(file.path(getwd(), "env"))
}
```
### Authentication
To authenticate your GEE account, you must execute the following command and follow the prompts in your browser:
```{python eval = F}
ee.Authenticate()
```
When complete, your your terminal will read:
`Successfully saved authorization token.`
This token is valid for 7 days from the time of authentication.
### Initializing your instance of GEE
Initialization through the Python command `ee.Initialize()` is automatically completed in the workflow.
## Run the targets pipeline and output a network graph.
The `gloria_config.yml` file has been populated with the information for the Landsat Surface Reflectance Collection 2 product stack pull.
```{r run_targets, echo = F}
library(targets)
# run the pipeline
tar_make()
```
Only errors that prematurely end the pipeline need to be addressed. Check the network diagram in the next section to confirm you've successfully run the pipeline. As long as your dialog box reads 'end pipeline' after 'built pattern eeRun', this workflow has successfully completed.
### Create a network diagram of the workflow.
```{r}
tar_visnetwork()
```