-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
118 lines (88 loc) · 3.21 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
---
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%"
)
```
# snapr
<img src="man/figures/snapr-hex.png" align="right" height="300" style="float:right; height:300px;">
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
```{r, include = FALSE}
library(snapr)
```
snapr is a proof of concept R package to interact with [The ESA Sentinel
Applications Platform (SNAP)](https://step.esa.int/main/toolboxes/snap/)
from R. SNAP provides an impressive set of tools for processing
satellite data, many of which are not available in the wider R
ecosystem. snapr is a wrapper for SNAP’s Graph Processing Tool (command line
interface) and shares similar ambitions to the
[SNAPISTA](https://github.com/snap-contrib/snapista) python library.
*Known Issues:*
* The package has only been tested on Linux. It should theoretically work on
Windows and MacOS but the automated installation of SNAP is not yet supported on
MacOS. On MacOS, snap will have to be installed manually and the path to
the SNAP bin folder will have to be set with the `SNAPR_BIN` environment variable.
* The following snap operators are currently not supported:
`r paste(snapr::get_operators()[is.na(snapr::get_operators()$r_function), ]$operator, collapse=", ")`.
To see supported oprators run `snapr::get_operators()`.
* There is little to no validation or checking on the R side for operators and
constructing snap graphs. This is something that I believe R will be very well
suited to but it is not yet implemented. Therefore we must rely on the somewhat
alarming/cryptic messages for the SNAP command line interface.
## Installation
You can install the development version of snapr like so:
``` r
#install.packages("pak")
pak::pkg_install("Permian-Global-Research/snapr")
library(snapr)
install_snap()
# This is only needed for pacakge development but also if you want access to the
# snappy python library with {reticulate} for example.
# configure_snappy_python()
```
## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(snapr)
library(terra)
mt_st_helens_s1 <- system.file("s1/mt_st_helens_s1.tif", package = "snapr")
out_file <- tempfile(fileext = ".tif")
sg <- snap_graph(
op_read(
operator_id = "Reader",
file = mt_st_helens_s1
),
op_speckle_filter(
operator_id = "SpeckleFilter",
sourceProduct = "Reader",
filter = "Refined Lee"
),
op_write(
operator_id = "Writer",
sourceProduct = "SpeckleFilter",
file = out_file,
formatName = "GeoTIFF"
)
)
show_xml(sg)
suppressMessages(run_graph(sg))
all_bands <- c(rast(mt_st_helens_s1), rast(out_file))
names(all_bands) <- c(
"Original-VH", "Original-VV",
"speckle-filter-VH", "speckle-filter-VV"
)
par(mfrow = c(2, 2))
p <- lapply(all_bands, \(x){
title <- names(x)
range <- terra::minmax(x, compute = TRUE)
plot(x, main = title, col = hcl.colors(100, "mako", rev = TRUE), range = range)
})
```