Skip to content

Commit

Permalink
Prep release
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 committed Jan 22, 2025
1 parent e0f8133 commit dacabe2
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 74 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rsi
Title: Efficiently Retrieve and Process Satellite Imagery
Version: 0.3.2
Version: 0.3.1.9001
Authors@R: c(
person("Michael", "Mahoney", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2402-304X")),
Expand Down
23 changes: 12 additions & 11 deletions R/calculate_indices.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#' @param output_filename The filename to write the computed metrics to.
#' @inheritParams rlang::args_dots_empty
#' @inheritParams terra::predict
#' @param extra_objects A named list of additional objects to pass to the
#' @param extra_objects A named list of additional objects to pass to the
#' minimal environment that formulas are executed in. For instance, if you
#' need to use the `pmax` function in order to calculate an index, you can
#' make it available in the environment by setting
#' `extra_objects = list("pmax" = pmax)`. Providing extra functionality is
#' inherently less safe than the default minimal environment, and as such always
#' need to use the `pmax` function in order to calculate an index, you can
#' make it available in the environment by setting
#' `extra_objects = list("pmax" = pmax)`. Providing extra functionality is
#' inherently less safe than the default minimal environment, and as such always
#' emits a warning, which you can suppress with `suppressWarnings()`.
#' @param names_suffix If not `NULL`, will be used (with [paste()]) to add a
#' suffix to each of the band names returned.
Expand Down Expand Up @@ -63,7 +63,7 @@
#' tempfile(fileext = ".tif")
#' )
#' )
#'
#'
#' # Because of this, formulas which try to use most R functions
#' # will wind up erroring as well:
#' example_indices$formula <- "pmax(VH, VV)"
Expand All @@ -74,7 +74,7 @@
#' tempfile(fileext = ".tif")
#' )
#' )
#'
#'
#' # To fix this, pass the objects you want to use to `extra_objects`
#' calculate_indices(
#' system.file("rasters/example_sentinel1.tif", package = "rsi"),
Expand Down Expand Up @@ -145,10 +145,11 @@ calculate_indices <- function(raster,
)

if (length(extra_objects)) {
rlang::warn(c(
"Providing extra objects can potentially make it easier for malicious code to impact your system.",
i = "Make sure you closely inspect the formulas you're running, before running them, and understand why they need extra objects!",
i = "This warning can be silenced using `suppressWarnings(..., classes = 'rsi_extra_objects')`"
rlang::warn(
c(
"Providing extra objects can potentially make it easier for malicious code to impact your system.",
i = "Make sure you closely inspect the formulas you're running, before running them, and understand why they need extra objects!",
i = "This warning can be silenced using `suppressWarnings(..., classes = 'rsi_extra_objects')`"
),
class = "rsi_extra_objects"
)
Expand Down
2 changes: 1 addition & 1 deletion R/get_stac_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ rsi_composite_bands <- function(download_locations,
)
)
} else {
capture.output({
utils::capture.output({
do.call(
terra::mosaic,
list(
Expand Down
1 change: 0 additions & 1 deletion R/mask_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ landsat_mask_function <- function(raster,
if (any(c("water", "both") %in% include)) {
masked_bits <- c(masked_bits, list(c(0:5, 9, 11, 13, 15)))
}

} else if (!missing(include)) {
rlang::abort(
"Only one of `include` and `masked_bits` can be specified.",
Expand Down
8 changes: 4 additions & 4 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ build_progressr <- function(n) {
}

#' Default options for GDAL
#'
#'
#' These functions provide useful default options for GDAL functions,
#' making downloading and warping (hopefully!) more efficient for
#' most use cases.
#'
#' most use cases.
#'
#' @returns A vector of options for GDAL commands.
#'
#'
#' @name rsi_gdal_options
#' @export
rsi_gdal_config_options <- function() {
Expand Down
6 changes: 3 additions & 3 deletions R/query_and_sign.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#' available for your AOI, or to perform cloud filtering prior to downloading
#' assets.
#'
#' @param bbox A `bbox` or `sfc` object, from the sf package, representing the
#' spatial bounding box of your area of interest. This must be in EPSG:4326
#' coordinates (and, if this function is called from within `get_stac_data()`,
#' @param bbox A `bbox` or `sfc` object, from the sf package, representing the
#' spatial bounding box of your area of interest. This must be in EPSG:4326
#' coordinates (and, if this function is called from within `get_stac_data()`,
#' it will be) or else it will be automatically reprojected.
#' @inheritParams get_stac_data
#' @param start_date,end_date Character strings of length 1 representing the
Expand Down
2 changes: 1 addition & 1 deletion R/stack_rasters.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#' when given a character vector of band names, returns a character vector of
#' the same length containing new band names.
#' @param check_crs Logical: Should this function check that all `rasters` share
#' the same CRS? Set to `FALSE` only if you are entirely confident that rasters
#' the same CRS? Set to `FALSE` only if you are entirely confident that rasters
#' have equivalent CRS definitions, but not identical WKT strings.
#' @param gdalwarp_options Options passed to `gdalwarp` through the `options`
#' argument of [sf::gdal_utils()]. This argument is ignored (with a warning)
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ terra::plot(terra::rast(landsat_image))
Note that we've been plotting each band individually so far by calling `terra::plot()`. We could also use `terra::plotRGB()` (after `terra::stretch()`ing the band values) to see what this mosaic of images would look like to the human eye:

```{r}
landsat_image |>
terra::rast(lyrs = c("R", "G", "B")) |>
landsat_image |>
terra::rast(lyrs = c("R", "G", "B")) |>
terra::stretch() |>
terra::plotRGB()
```
Expand Down
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[![R-CMD-check](https://github.com/Permian-Global-Research/rsi/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Permian-Global-Research/rsi/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/Permian-Global-Research/rsi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/Permian-Global-Research/rsi?branch=main)
[![License:
Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/license/apache-2-0)
[![License: Apache
2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/license/apache-2-0)
[![Lifecycle:
maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing)
[![Project Status: Active – The project has reached a stable, usable
Expand All @@ -27,20 +27,17 @@ The goal of rsi is to address several **r**epeated **s**patial
and help avoid **r**epetitive **s**tress **i**njuries. Specifically, rsi
provides:

- An interface to the **R**some – excuse me, [*Awesome* Spectral
Indices
project](https://github.com/awesome-spectral-indices/awesome-spectral-indices),
providing the list of indices directly in R as a friendly tibble,
- A method for efficiently *calculating* those awesome spectral
indices using local rasters, enabling **r**apid **s**pectral
**i**nference,
- A method for downloading STAC data – excuse me, **r**etriving
**S**TAC **i**nformation – from any STAC server, with additional
helpers for downloading Landsat, Sentinel-1, and Sentinel-2 data
from free and public STAC servers providing **r**apid **s**atellite
**i**magery,
- A **r**aster **s**tack **i**ntegration method for combining multiple
rasters containing distinct data sets into a single raster stack.
- An interface to the **R**some – excuse me, [*Awesome* Spectral Indices
project](https://github.com/awesome-spectral-indices/awesome-spectral-indices),
providing the list of indices directly in R as a friendly tibble,
- A method for efficiently *calculating* those awesome spectral indices
using local rasters, enabling **r**apid **s**pectral **i**nference,
- A method for downloading STAC data – excuse me, **r**etriving **S**TAC
**i**nformation – from any STAC server, with additional helpers for
downloading Landsat, Sentinel-1, and Sentinel-2 data from free and
public STAC servers providing **r**apid **s**atellite **i**magery,
- A **r**aster **s**tack **i**ntegration method for combining multiple
rasters containing distinct data sets into a single raster stack.

The functions in rsi are designed around letting you use the tools
you’re familiar with to process raster data using compute that you
Expand Down Expand Up @@ -78,7 +75,7 @@ project](https://github.com/awesome-spectral-indices/awesome-spectral-indices):
library(rsi)

spectral_indices()
#> # A tibble: 243 × 9
#> # A tibble: 245 × 9
#> application_domain bands contributor date_of_addition formula long_name
#> <chr> <list> <chr> <chr> <chr> <chr>
#> 1 vegetation <chr [2]> https://gith… 2021-11-17 (N - 0… Aerosol …
Expand All @@ -91,7 +88,7 @@ spectral_indices()
#> 8 vegetation <chr [2]> https://gith… 2022-04-08 (N * (… Advanced…
#> 9 water <chr [4]> https://gith… 2021-09-18 4.0 * … Automate…
#> 10 water <chr [5]> https://gith… 2021-09-18 B + 2.… Automate…
#> # ℹ 233 more rows
#> # ℹ 235 more rows
#> # ℹ 3 more variables: platforms <list>, reference <chr>, short_name <chr>
```

Expand Down Expand Up @@ -158,8 +155,8 @@ Note that we’ve been plotting each band individually so far by calling
would look like to the human eye:

``` r
landsat_image |>
terra::rast(lyrs = c("R", "G", "B")) |>
landsat_image |>
terra::rast(lyrs = c("R", "G", "B")) |>
terra::stretch() |>
terra::plotRGB()
```
Expand Down Expand Up @@ -197,6 +194,7 @@ indices <- calculate_indices(
available_indices,
output_filename = tempfile(fileext = ".tif")
)
#> |---------|---------|---------|---------|=========================================

# Plot the first handful of spatial indices
terra::plot(terra::rast(indices))
Expand Down Expand Up @@ -228,7 +226,7 @@ other multi-band rasters from various data sources.

## Contributing

We love contributions\! See our [contribution
We love contributions! See our [contribution
guide](https://github.com/Permian-Global-Research/rsi/blob/main/.github/CONTRIBUTING.md)
for pointers on how to make your contribution as easy to accept as
possible – in particular, consider [opening an
Expand Down
5 changes: 3 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
This is the seventh CRAN release of rsi, fixing a test error that
arose on CRAN.
This is the eigth CRAN release of rsi, fixing how downloads
handle duplicated asset timestamps and how errors are
handled during merging.

## R CMD check results

Expand Down
Binary file modified man/figures/README-unnamed-chunk-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-4-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-8-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions man/get_stac_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/rsi_download_rasters.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-mask_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ test_that("landsat_mask_function arguments work", {
sum(
terra::values(
landsat_mask_function(
terra::rast(boston_landsat),
terra::rast(boston_landsat),
masked_bits = list(
clear_land = c(0:5, 7, 9, 11, 13, 15),
clear_water = c(0:5, 9, 11, 13, 15)
)
)
)
)
)
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ test_that("c works", {
c(rsi::sentinel2_band_mapping$planetary_computer_v1, scl = "scl"),
c(rsi::sentinel2_band_mapping$planetary_computer_v1, "scl")
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ ashe_landsat <- get_landsat_imagery(
start_date = "2021-06-01",
end_date = "2021-06-30",
output_filename = tempfile(fileext = ".tif")
)
)
ashe_landsat |>
terra::rast() |>
Expand Down Expand Up @@ -265,7 +265,7 @@ ashe_no_composite <- get_landsat_imagery(
output_filename = tempfile(fileext = ".tif"),
composite_function = NULL,
mask_function = NULL # otherwise half of these images are blank
)
)
ashe_no_composite |>
lapply(terra::rast) |>
lapply(terra::plot) |>
Expand Down
36 changes: 18 additions & 18 deletions vignettes/articles/How-can-I-.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ aoi <- sf::st_point(c(-74.912131, 44.080410))
aoi <- sf::st_set_crs(sf::st_sfc(aoi), 4326)
aoi <- sf::st_buffer(sf::st_transform(aoi, 5070), 1000)
custom_query_function <- function(bbox,
stac_source,
collection,
start_date,
end_date,
limit,
custom_query_function <- function(bbox,
stac_source,
collection,
start_date,
end_date,
limit,
...) {
geometry <- rstac::cql2_bbox_as_geojson(bbox)
geometry <- rstac::cql2_bbox_as_geojson(bbox)
datetime <- rstac::cql2_interval(start_date, end_date)
request <- rstac::ext_filter(
rstac::stac(stac_source),
collection == {{collection}} &&
t_intersects(datetime, {{datetime}}) &&
s_intersects(geometry, {{geometry}}) &&
collection == {{ collection }} &&
t_intersects(datetime, {{ datetime }}) &&
s_intersects(geometry, {{ geometry }}) &&
`eo:cloud_cover` < 50
)
rstac::items_fetch(rstac::post_request(request))
Expand Down Expand Up @@ -179,7 +179,7 @@ You want to calculate some indices from this imagery. Specifically, you want to
To do that using `calculate_indices()`, you're going to need to only provide formulas for the indices that can be calculated from your particular data source. We might look at the columns available for filtering from `spectral_indices()`:

```{r}
spectral_indices() |>
spectral_indices() |>
head(1)
```

Expand All @@ -204,18 +204,18 @@ However, if you're looking to automatically calculate just the indices that don'
Assuming you used one of the wrapper functions in rsi, like `get_landsat_data()` or `get_sentinel2_data()`, your raster bands should automatically be named to match the band names used in the ASI project. That means we can pass the names of your raster directly to `filter_bands()`:

```{r}
filter_bands(bands = names(terra::rast(our_imagery))) |>
filter_bands(bands = names(terra::rast(our_imagery))) |>
head(1)
```

And we can pass the outputs of that function to `calculate_indices()` to only calculate this subset of indices:

```{r}
calculate_indices(
our_imagery,
filter_bands(bands = names(terra::rast(our_imagery))),
output_filename = tempfile(fileext = ".tif")
) |>
terra::rast() |>
our_imagery,
filter_bands(bands = names(terra::rast(our_imagery))),
output_filename = tempfile(fileext = ".tif")
) |>
terra::rast() |>
terra::plot()
```

0 comments on commit dacabe2

Please sign in to comment.