Skip to content

Commit

Permalink
version 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ranghetti authored and cran-robot committed Jan 7, 2021
1 parent c48bd83 commit fa13190
Show file tree
Hide file tree
Showing 154 changed files with 1,495 additions and 1,091 deletions.
9 changes: 4 additions & 5 deletions DESCRIPTION
@@ -1,13 +1,12 @@
Package: sen2r
Type: Package
Title: Find, Download and Process Sentinel-2 Data
Version: 1.3.9
Version: 1.4.0
Authors@R: c(person("Luigi", "Ranghetti",
email = "luigi@ranghetti.info",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-6207-5188")),
person("Lorenzo", "Busetto",
email = "lbusett@gmail.com",
role = c("aut"),
comment = c(ORCID = "0000-0001-9634-6038")))
Description: Functions to download Sentinel-2 optical images
Expand All @@ -33,12 +32,12 @@ SystemRequirements: GDAL (>= 2.1.2), PROJ (>= 4.9.1), GEOS (>= 3.4.2),
Cairo, Curl, NetCDF, jq, Protocol Buffers, V8, OpenSSL,
Libxml2.
VignetteBuilder: knitr
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Language: en-GB
NeedsCompilation: no
Packaged: 2020-10-13 22:21:42 UTC; lranghetti
Packaged: 2021-01-06 19:28:00 UTC; lranghetti
Author: Luigi Ranghetti [aut, cre] (<https://orcid.org/0000-0001-6207-5188>),
Lorenzo Busetto [aut] (<https://orcid.org/0000-0001-9634-6038>)
Maintainer: Luigi Ranghetti <luigi@ranghetti.info>
Repository: CRAN
Date/Publication: 2020-10-14 04:20:02 UTC
Date/Publication: 2021-01-07 18:10:02 UTC
303 changes: 153 additions & 150 deletions MD5

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -111,6 +111,7 @@ importFrom(sf,st_as_sfc)
importFrom(sf,st_as_text)
importFrom(sf,st_bbox)
importFrom(sf,st_cast)
importFrom(sf,st_centroid)
importFrom(sf,st_collection_extract)
importFrom(sf,st_combine)
importFrom(sf,st_convex_hull)
Expand Down
38 changes: 38 additions & 0 deletions NEWS.md
@@ -1,3 +1,41 @@
# Version 1.4.0

## Major changes
- `gdal_warp()` was partially rewritten: now reshaped rasters conserve square
pixels also after warping operations. _This change also affects `sen2r()`
products if reshaping features (reprojection or custom resolution)
are required._
This update was necessary due to changes performed in GDAL since version
3.2.0 (see [OSGeo/gdal&#x266F;3294](https://github.com/OSGeo/gdal/issues/3294)),
which did not grant homogeneity between outputs produced with different
GDAL versions.
Note that, in case the user wants to update an existing sen2r archive
produced with `{sen2r}` < 1.4.0, the old existing grid is maintained
so that product grids are equal (in order to produce outputs with the new
grid, users must create a new archive).
- Manage images split in two SAFE products, to avoid producing black areas
in these [uncommon] cases (see #353 for an explanation).
As effects:
1. now pixels outside footprints (including nodata outside orbits coverage)
are always set to nodata;
2. now `s2_download()` is no more able to use existing products equivalent
to found ones.

## Minor changes
- Add templates for GitHub issues.
- Do not return error in tests in case of SciHub server down (#354).

## Changes in default values
- Pixels outside footprints (because of previous point, or - more frequently -
because outside orbits coverage) are always set to NA even
if no cloud masking is performed.
- `s2_download()` no more uses existing SAFE products instead than downloading
new equivalent ones (this in order to manage images split in two SAFE archives).

## Documentation
- Update vignette data (granting using online data) (#360).


# Version 1.3.9

## Bug fixes
Expand Down
5 changes: 2 additions & 3 deletions R/abs2rel.R
Expand Up @@ -18,9 +18,8 @@
#' @author Luigi Ranghetti, phD (2017) \email{luigi.ranghetti@@gmail.com}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @export
#'
Expand Down
5 changes: 2 additions & 3 deletions R/add_rgb_image.R
Expand Up @@ -5,9 +5,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0

add_rgb_image <- function(s2_bands) {
Expand Down
105 changes: 105 additions & 0 deletions R/add_tile_suffix.R
@@ -0,0 +1,105 @@
#' @title Add/remove suffixes for split tiles
#' @description `add_tile_suffix()` adds specific suffixes to tile IDs
#' in order to distinguish tiled filenames referring to different original
#' SAFE products.
#' @details In some sporadic cases, a tiled Sentinel-2 image is split in two
#' SAFE products (see e.g. products
#' [`S2A_MSIL1C_20200408T101021_N0209_R022_T32TNL_20200408T153254`](https://storage.cloud.google.com/gcp-public-data-sentinel-2/tiles/32/T/NL/S2A_MSIL1C_20200408T101021_N0209_R022_T32TNL_20200408T153254.SAFE/GRANULE/L1C_T32TNL_A025044_20200408T101022/QI_DATA/T32TNL_20200408T101021_PVI.jp2) and
#' [`S2A_MSIL1C_20200408T101021_N0209_R022_T32TNL_20200408T171107`](https://storage.cloud.google.com/gcp-public-data-sentinel-2/tiles/32/T/NL/S2A_MSIL1C_20200408T101021_N0209_R022_T32TNL_20200408T171107.SAFE/GRANULE/L1C_T32TNL_A025044_20200408T101923/QI_DATA/T32TNL_20200408T101021_PVI.jp2)).
#' This split, probably a consequence of the division of the whole orbit image,
#' creates ambiguity in the association among SAFE images and `sen2r` products,
#' since the sen2r naming convention is not sufficient to manage them as separate
#' products.
#' So, in the definition of the filenames of intermediate tiled products
#' (output of `s2_translate()`) it is necessary to add a suffix to be able to
#' manage them separately and then merge them in `s2_merge()`.
#' A lowercase letter ("a" and "b", but potentially "a" to "z") is used.
#' Functions `add_tile_suffix()` and `remove_tile_suffix()` are used in the
#' `sen2r()` main code as a workaround.
#' @param paths Paths of the input tiled products
#' @param suffix Character (1-length): if provided, the specified suffix is
#' appended to the tile ID of each path;
#' if not provided (default), a sequential suffix is appended only to the tile
#' ID of the duplicated paths.
#' @return The input paths with/without the tile suffix.
#'
#' @author Luigi Ranghetti, phD (2020) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @examples
#' safe_names <- c(
#' "S2A_MSIL2A_20200408T101021_N0214_R022_T32TNK_20200408T175711.SAFE",
#' "S2A_MSIL2A_20200408T101021_N0214_R022_T32TNL_20200408T175711.SAFE",
#' "S2A_MSIL2A_20200408T101021_N0214_R022_T32TNL_20200408T161405.SAFE"
#' )
#' prod_names <- safe_shortname(safe_names, ext = ".tif", allow_duplicated = TRUE)
#' ( prod_names_univoc <- sen2r:::add_tile_suffix(prod_names) )
#' ( prod_names_custom <- sen2r:::add_tile_suffix(prod_names, "a") )
#' sen2r:::remove_tile_suffix(prod_names_univoc)

add_tile_suffix <- function(paths, suffix) {
if (missing(suffix)) {
# Default behaviour: add default suffixes to duplicated paths
for (sel_upath in names(table(paths))[table(paths)>1]) {
n_paths <- sum(paths==sel_upath)
paths[paths==sel_upath] <- sapply(seq_len(n_paths), function(i) {
gsub(
"(S2[AB][12][AC]\\_[0-9]{8}\\_[0-9]{3})\\_([0-9]{2}[A-Z]{3})\\_([^\\_\\.]+\\_[126]0\\.?[^\\_]*$)",
paste0("\\1_\\2",letters[i],"_\\3"),
sel_upath
)
})
}
paths
} else {
# Custom behaviour: add specific suffix to all the paths
gsub(
"(S2[AB][12][AC]\\_[0-9]{8}\\_[0-9]{3})\\_([0-9]{2}[A-Z]{3})\\_([^\\_\\.]+\\_[126]0\\.?[^\\_]*$)",
paste0("\\1_\\2",suffix,"_\\3"),
paths
)
}
}


#' @name remove_tile_suffix
#' @rdname add_tile_suffix
#' @description `remove_tile_suffix()` removes existing suffixes from tile IDs.

remove_tile_suffix <- function(paths) {
accepted_suffixes <- "[a-z]?" # Define here the accepted suffixes
sapply(paths, function(p) {
gsub(
paste0(
"(S2[AB][12][AC]\\_[0-9]{8}\\_[0-9]{3})\\_([0-9]{2}[A-Z]{3})",
accepted_suffixes,
"\\_([^\\_\\.]+\\_[126]0\\.?[^\\_]*$)"
),
"\\1_\\2_\\3",
p
)
}, simplify = TRUE, USE.NAMES = FALSE)
}


#' @name extract_tile_suffix
#' @rdname add_tile_suffix
#' @description `extract_tile_suffix()` extracts suffixes from input paths.

extract_tile_suffix <- function(paths) {
accepted_suffixes <- "[a-z]?" # Define here the accepted suffixes
sapply(paths, function(p) {
gsub(
paste0(
"^.*S2[AB][12][AC]\\_[0-9]{8}\\_[0-9]{3}\\_[0-9]{2}[A-Z]{3}",
"(",accepted_suffixes,")",
"\\_[^\\_\\.]+\\_[126]0\\.?[^\\_]*$"
),
"\\1",
p
)
}, simplify = TRUE, USE.NAMES = FALSE)
}
5 changes: 2 additions & 3 deletions R/build_example_param_file.R
Expand Up @@ -11,9 +11,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @importFrom jsonlite toJSON
#' @export
Expand Down
7 changes: 3 additions & 4 deletions R/calcindex.R
Expand Up @@ -27,10 +27,9 @@
#'
#' @author Luigi Ranghetti, phD (2020) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0

calcindex_raster <- function(
Expand Down
5 changes: 2 additions & 3 deletions R/check_gdal.R
Expand Up @@ -24,9 +24,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @importFrom jsonlite toJSON
#' @export
Expand Down
5 changes: 2 additions & 3 deletions R/check_gui_deps.R
Expand Up @@ -13,9 +13,8 @@
#' @author Luigi Ranghetti, phD (2020) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @export
#' @examples
Expand Down
5 changes: 2 additions & 3 deletions R/check_param_list.R
Expand Up @@ -22,9 +22,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0


Expand Down
5 changes: 2 additions & 3 deletions R/check_sen2r_deps.R
Expand Up @@ -14,9 +14,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @importFrom utils capture.output
#' @importFrom httr RETRY write_disk progress
Expand Down
36 changes: 28 additions & 8 deletions R/compute_s2_paths.R
Expand Up @@ -46,9 +46,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note License: GPL 3.0
#' @import data.table

Expand Down Expand Up @@ -382,7 +381,7 @@ compute_s2_paths <- function(pm,
# tiles
if (steps_todo["tiles"]) {
exp_paths[["tiles"]] <- sapply(list_prods, function(prod){
remove_duplicates(nn(
nn(
unlist(c(
sapply(
if (prod %in% l1c_prods) {file.path(pm$path_l1c,names(s2_list_l1c))} else
Expand Down Expand Up @@ -414,8 +413,14 @@ compute_s2_paths <- function(pm,
),
exi_paths$tiles[[prod]]
))
))
)
}, simplify = FALSE, USE.NAMES = TRUE)
# Add suffixes in case of splitted tiles (#353)
if (any(duplicated(exp_paths[["tiles"]][[1]]))) {
exp_paths[["tiles"]] <- sapply(exp_paths[["tiles"]], function(p) {
add_tile_suffix(p)
}, simplify = FALSE, USE.NAMES = TRUE)
}
}

# merged
Expand Down Expand Up @@ -810,7 +815,7 @@ compute_s2_paths <- function(pm,
level,"_",
strftime(sensing_date,"%Y%m%d"),"_",
id_orbit,"_",
"[0-9]{2}[A-Z]{3}_",
"[0-9]{2}[A-Z]{3}[a-z]?_",
prod,"_",
substr(res,1,2),".",
out_ext[output_dep["merged"]]
Expand Down Expand Up @@ -850,10 +855,25 @@ compute_s2_paths <- function(pm,
"[126]0\\.",
out_ext["tiles"]
)]
# add proper suffixes in case of multiple SAFE for the same date-tile (#353)
if (any(duplicated(tiles_basenames_av))) {
for (sel_basename_av in names(table(tiles_basenames_av))[table(tiles_basenames_av)>1]) {
tiles_basenames_av[tiles_basenames_av==sel_basename_av] <- sapply(
letters[seq_len(sum(tiles_basenames_av==sel_basename_av))],
function(l) {
gsub(
"_([0-9]{2}[A-Z]{3})_",
paste0("_\\1",l,"_"),
sel_basename_av
)
}
)
}
}
list(
"L1C" = file.path(
pm$path_l1c,
names(s2_list_l1c)[unlist(
basename(names(s2_list_l1c))[unlist(
lapply(
tiles_basenames_av[safe_dt_av$level=="1C"],
function(x){length(grep(x,unlist(new_paths[["tiles"]]))) > 0}
Expand All @@ -862,7 +882,7 @@ compute_s2_paths <- function(pm,
),
"L2A" = file.path(
pm$path_l2a,
names(s2_list_l2a)[unlist(
basename(names(s2_list_l2a))[unlist(
lapply(
tiles_basenames_av[safe_dt_av$level=="2A"],
function(x){length(grep(x,unlist(new_paths[["tiles"]]))) > 0}
Expand Down
5 changes: 2 additions & 3 deletions R/comsub.R
Expand Up @@ -11,9 +11,8 @@
#' @author Luigi Ranghetti, phD (2019) \email{luigi@@ranghetti.info}
#' @references L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020).
#' "sen2r": An R toolbox for automatically downloading and preprocessing
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473. DOI:
#' \href{https://doi.org/10.1016/j.cageo.2020.104473}{10.1016/j.cageo.2020.104473},
#' URL: \url{http://sen2r.ranghetti.info/}.
#' Sentinel-2 satellite data. _Computers & Geosciences_, 139, 104473.
#' \doi{10.1016/j.cageo.2020.104473}, URL: \url{http://sen2r.ranghetti.info/}.
#' @note Modified from a suggestion taken from
#' [stackoverflow](https://stackoverflow.com/questions/28273716/r-implementation-for-finding-the-longest-common-starting-substrings-in-a-set-of).
#' @export
Expand Down

0 comments on commit fa13190

Please sign in to comment.