Skip to content

new devel branch #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 147 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d1219cd
Update develop version
ranghetti Dec 16, 2020
53f95d4
DOI preferrer resolver (#131)
ranghetti Dec 27, 2020
84788da
Try fixing #226
ranghetti Jan 13, 2021
8a24bcb
Merge branch 'master' into devel
ranghetti Jan 15, 2021
8fdb474
Merge branch 'master' into devel
ranghetti Jan 15, 2021
f5e3ee8
Update develop version
ranghetti Jan 15, 2021
a73c02b
Patch for bbox loaded from json in case of drawn extent (#228)
ranghetti Jan 18, 2021
ccd4a53
Fix #232
ranghetti Feb 17, 2021
c22cc96
Fix #234
ranghetti Apr 14, 2021
c2d7c80
Merge branch 'master' into devel
ranghetti Apr 14, 2021
2669966
Merge branch 'master' into devel
ranghetti Jul 8, 2021
5fa93cc
Add M*D17A2HGF and M*D17A3HGF
ranghetti Jul 8, 2021
e796a37
Merge branch 'master' into devel
ranghetti Jul 9, 2021
6d0ba9a
Update develop version
ranghetti Jul 9, 2021
c474efd
Merge branch 'devel' of https://github.com/lbusett/MODIStsp into devel
ranghetti Aug 2, 2021
36b9434
Avoid NOTE on CRAN check
ranghetti Aug 2, 2021
794e718
Avoid errors in case of missing internet connection
ranghetti Aug 2, 2021
ae20d6c
Fix tests
ranghetti Aug 2, 2021
3e668aa
Update documentation and version
ranghetti Aug 2, 2021
49f78a1
Fix CRAN note
ranghetti Aug 3, 2021
88650d8
Merge branch 'master' into devel
ranghetti Aug 3, 2021
360ab7d
Update develop version
ranghetti Aug 3, 2021
e70731a
Add product version 061 for existing products (#238)
ranghetti Oct 28, 2021
2297922
Edit tests for checking some 061 products
ranghetti Oct 29, 2021
f56643f
Update documentation
ranghetti Oct 29, 2021
d990042
Merge branch 'master' into devel
ranghetti Oct 29, 2021
172d05d
Update develop version
ranghetti Oct 29, 2021
8e5159d
Typo (#245)
ranghetti Nov 2, 2021
8017480
Merge branch 'master' into devel
ranghetti Nov 2, 2021
72d1189
Update develop version
ranghetti Nov 2, 2021
c2f97d9
Merge branch 'master' into devel
ranghetti Dec 20, 2021
c5d4475
Update documentation
ranghetti Dec 20, 2021
1dde2da
Merge branch 'master' into devel
ranghetti Dec 20, 2021
2c2b880
Update develop version
ranghetti Dec 20, 2021
b09d9e6
Merge branch 'master' into devel
ranghetti Apr 5, 2022
60f2195
Update NEWS
ranghetti Apr 5, 2022
295eb28
Avoid NOTE
ranghetti Apr 5, 2022
cfaa6e8
Replace context() with message() and fix tests
ranghetti Apr 5, 2022
a828e0e
Update documentation to v. 2.0.7
ranghetti Apr 6, 2022
d443ed7
Merge branch 'master' into devel
ranghetti Apr 21, 2022
4e7998a
Update develop version
ranghetti Apr 21, 2022
b4c8579
Reducing package size due to note 'installed size is 5.1Mb'
ranghetti Apr 21, 2022
1919b16
State that GDAL with support for HDF4 format is needed
ranghetti Apr 21, 2022
78e4298
Update documentation and version
ranghetti Apr 21, 2022
5ff165d
Exit from the code if HDF4 is not supported.
ranghetti Apr 21, 2022
95a6a48
Update documentation
ranghetti Apr 21, 2022
c893c97
Don't run examples and tests if HDF4 is not supported
ranghetti Apr 21, 2022
9a39878
Update documentation
ranghetti Apr 21, 2022
975d366
Merge branch 'master' into devel
ranghetti Aug 22, 2022
729933e
Remove useshinyalert() to avoid warnings
ranghetti Aug 22, 2022
66f9777
Update shinyalert required version
ranghetti Aug 26, 2022
d7f0772
Update version and news
ranghetti Aug 26, 2022
31331dc
Update documentation
ranghetti Aug 26, 2022
d951834
Update documentation
ranghetti Aug 26, 2022
ff3f4f4
Specify CRAN note
ranghetti Aug 26, 2022
3018438
Merge branch 'master' into devel
ranghetti Aug 27, 2022
739cf9d
Update develop version
ranghetti Aug 27, 2022
651c2ff
Remove explicit rgdal dependency
ranghetti Dec 16, 2022
c44940a
Remove email from functions
ranghetti Mar 2, 2023
10708a6
Update version, news and documentation
ranghetti Mar 2, 2023
5523951
Avoid NOTE (redirecting URL)
ranghetti Mar 2, 2023
b1020fa
Update cran-comments
ranghetti Mar 2, 2023
1180cee
Merge branch 'master' into devel
ranghetti Jun 9, 2023
bb8bcdd
Update cran-comments and NEWS
ranghetti Jun 9, 2023
ed73c38
Replace old-style citEntry() with bibentry().
ranghetti Jun 11, 2023
1a9222d
Update documentation
ranghetti Jun 12, 2023
caabee5
Update checks in cran-comments
ranghetti Jun 12, 2023
996320a
Merge branch 'master' into devel
ranghetti Jun 12, 2023
7eabaf9
Update develop version
ranghetti Jun 12, 2023
81c3c6b
Fix default version (latest of each product instead than 006)
ranghetti Aug 14, 2023
80efcb2
Fix version retrieval in manual mode
ranghetti Aug 16, 2023
f8ea3ac
Changing default version from 006 to 061
ranghetti Aug 16, 2023
7d0ebc5
Product updates. Removed 060 versions.
pkautio Oct 1, 2023
6026015
Product updates. Removed 060 versions.
pkautio Oct 1, 2023
e004eba
Merge pull request #268 from pkautio/devel
ranghetti Oct 7, 2023
7643889
Fix wrong filename
ranghetti Oct 7, 2023
870463b
Merge remote-tracking branch 'origin/master' into devel
ranghetti Oct 7, 2023
982f68c
Update develop version
ranghetti Oct 7, 2023
b4cea3d
Switch test/doc versions to 6.1
ranghetti Oct 12, 2023
185ada3
Update documentation
ranghetti Oct 12, 2023
a8d1c2c
RC 2.1.0
ranghetti Oct 12, 2023
cba0d85
cran-comments
ranghetti Oct 12, 2023
0ecafd1
Local test errors
ranghetti Oct 13, 2023
c04e615
Fix tests after removing v.006
ranghetti Oct 13, 2023
8dd4f19
Fix tests locally
ranghetti Oct 13, 2023
1de10bd
Merge branch 'v21' into devel
ranghetti Oct 13, 2023
0ed8d14
Merge branch 'master' into devel
ranghetti Oct 13, 2023
f88d109
Update develop version
ranghetti Oct 13, 2023
788fe9f
Update MODIStsp_download.R to use httr2 package
pkautio May 13, 2024
701a0ef
Update get_mod_dirs.R httr2
pkautio May 13, 2024
f1dca4c
Update DESCRIPTION
pkautio May 13, 2024
f528feb
Update NEWS.md
pkautio May 13, 2024
f7bd5e2
Update faq.Rmd
pkautio May 13, 2024
d858694
Update mstp_helpmess_srv.R
pkautio May 13, 2024
2ee236c
Update README.Rmd
pkautio May 13, 2024
28a26cb
Create get_earthdata_token.R
pkautio May 14, 2024
852445d
Update get_earthdata_token.R
pkautio May 14, 2024
d257e7e
Update get_earthdata_token.R
pkautio May 14, 2024
4d65fb0
Update get_earthdata_token.R
pkautio May 14, 2024
f0e0d9e
Update get_earthdata_token.R
pkautio May 14, 2024
84853b1
Update get_earthdata_token.R
pkautio May 14, 2024
250e583
Update get_earthdata_token.R
pkautio May 14, 2024
257aefb
Update MODIStsp_download.R
pkautio May 14, 2024
9538cfc
Update MODIStsp_download.R
pkautio May 14, 2024
52f52eb
Update get_earthdata_token.R
pkautio May 14, 2024
e140f86
Update get_mod_dirs.R
pkautio May 14, 2024
f3a8ed6
Update get_mod_filenames.R
pkautio May 14, 2024
c85c308
Update get_mod_filenames.R
pkautio May 14, 2024
71dff94
Update get_mod_dirs.R
pkautio May 14, 2024
c8ac4f8
Update get_earthdata_token.R
pkautio May 14, 2024
b16c05e
Update get_mod_dirs.R
pkautio May 14, 2024
af438a1
Update get_mod_dirs.R
pkautio May 14, 2024
b7f2ab8
Update get_mod_dirs.R
pkautio May 14, 2024
2f08da3
Update MODIStsp_download.R
pkautio May 14, 2024
d834efb
Update get_mod_dirs.R
pkautio May 14, 2024
776bf41
Update get_mod_filenames.R
pkautio May 14, 2024
67dc889
Update get_mod_filenames.R
pkautio May 14, 2024
6886bd9
Update get_mod_filenames.R
pkautio May 14, 2024
5fa9410
Update MODIStsp_download.R
pkautio May 14, 2024
4b4023e
Update get_mod_dirs.R
pkautio May 14, 2024
6db73c5
Update get_mod_dirs.R
pkautio May 14, 2024
44ac8b2
Update MODIStsp-package.R
pkautio May 14, 2024
eb04e69
Update get_mod_filenames.R
pkautio May 14, 2024
e8e5ce4
Update get_mod_filenames.R
pkautio May 14, 2024
d7332dd
Update get_mod_filenames.R
pkautio May 14, 2024
593b2c9
Update README.md
pkautio May 14, 2024
9bc25d8
Update README.md
pkautio May 14, 2024
8175c0f
Update get_mod_filenames.R
pkautio May 14, 2024
4a8fd45
Update get_mod_filenames.R
pkautio May 14, 2024
8a26344
Update get_mod_filenames.R
pkautio May 14, 2024
6cfc1a2
Update get_mod_filenames.R
pkautio May 17, 2024
02a4ad7
Update get_mod_filenames.R
pkautio May 17, 2024
34d443a
Update get_mod_filenames.R
pkautio May 17, 2024
0ce3d9e
Update MODIStsp_process.R
pkautio May 17, 2024
1e98845
Update MODIStsp_download.R
pkautio May 17, 2024
7eab871
Update get_mod_dirs.R
pkautio May 17, 2024
887b0bb
Update get_mod_filenames.R
pkautio May 17, 2024
7370b87
Update get_mod_filenames.R
pkautio May 17, 2024
56a4188
Update get_mod_dirs.R
pkautio May 17, 2024
4142d45
Update get_mod_filenames.R
pkautio May 17, 2024
69954b4
Update get_mod_filenames.R
pkautio May 17, 2024
0ea443a
Update MODIStsp_download.R
pkautio Jul 27, 2024
893c3ab
Update MODIStsp_download.R
pkautio Jul 27, 2024
419b0bd
Update MODIStsp_process.R
pkautio Jul 28, 2024
92aae16
Update MODIStsp_process.R
pkautio Jul 28, 2024
7510033
blergeh
mdsumner May 16, 2025
314111f
small attempt
mdsumner May 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
^doc$
^Meta$
^CRAN-SUBMISSION$
^MODIStsp\.Rproj$
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ Description: Allows automating the creation of time series of rasters derived
Busetto and Ranghetti (2016) <doi:10.1016/j.cageo.2016.08.020>.
License: GPL-3
Depends:
R (>= 3.5.0)
R (>= 4.2.0)
Imports:
assertthat,
bitops (>= 1.0-6),
data.table (>= 1.9.6),
gdalUtilities,
geojsonio,
httr (>= 1.4.2),
httr2,
jsonlite,
parallel,
raster (>= 3.3.13),
Expand Down Expand Up @@ -90,7 +90,7 @@ URL: https://github.com/ropensci/MODIStsp/, https://docs.ropensci.org/MODIStsp/
BugReports: https://github.com/ropensci/MODIStsp/issues
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Language: en-US
15 changes: 10 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ importFrom(gdalUtilities,gdal_translate)
importFrom(gdalUtilities,gdalbuildvrt)
importFrom(gdalUtilities,gdalwarp)
importFrom(gdalUtilities,ogr2ogr)
importFrom(httr,GET)
importFrom(httr,RETRY)
importFrom(httr,authenticate)
importFrom(httr,content)
importFrom(httr,write_disk)
importFrom(httr2,req_auth_basic)
importFrom(httr2,req_auth_bearer_token)
importFrom(httr2,req_headers)
importFrom(httr2,req_method)
importFrom(httr2,req_perform)
importFrom(httr2,req_retry)
importFrom(httr2,request)
importFrom(httr2,resp_body_string)
importFrom(httr2,resp_body_xml)
importFrom(httr2,resp_status)
importFrom(jsonlite,read_json)
importFrom(jsonlite,write_json)
importFrom(parallel,detectCores)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

- interim mods to record maintainer change (mdsumner), tagged at master branch v2.1.0.9001

## Major changes
- Major product update: Fix broken authentication to NASA Earthdata sites.
- Migrate to httr2 package and remove dependencies to obsolete httr package

## Minor changes
- Change maintainer's email in order to follow CRAN requirements.

# MODIStsp 2.1.0

## Major changes
Expand Down
1 change: 1 addition & 0 deletions R/MODIStsp-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @name MODIStsp-package
#' @author Lorenzo Busetto, phD (2014-2017)
#' @author Luigi Ranghetti, phD (2015-2017)
#' @author Pasi Autio (2024)
#' @seealso [https://docs.ropensci.org/MODIStsp/](https://docs.ropensci.org/MODIStsp/)
#' @seealso [https://github.com/ropensci/MODIStsp](https://github.com/ropensci/MODIStsp)
#'
Expand Down
53 changes: 26 additions & 27 deletions R/MODIStsp_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#' @param verbose `logical` If FALSE, suppress processing messages, Default: TRUE
#' @return The function is called for its side effects
#' @rdname MODIStsp_download
#' @author Lorenzo Busetto, phD (2014-2017)
#' @author Luigi Ranghetti, phD (2015)
#' @importFrom httr RETRY authenticate content GET write_disk
#' @importFrom httr2 request req_perform req_auth_bearer_token req_headers resp_body_xml
#' @importFrom xml2 as_list

MODIStsp_download <- function(modislist,
Expand All @@ -45,6 +43,13 @@ MODIStsp_download <- function(modislist,
gui,
verbose) {

# Fetch Bearer token to be used for further authentication
if (exists("earthdata_token")) {
token <- earthdata_token
} else {
token <- get_earthdata_token(user, password)
}

# Cycle on the different files to download for the current date
for (file in seq_along(modislist)) {
modisname <- modislist[file]
Expand All @@ -71,25 +76,20 @@ MODIStsp_download <- function(modislist,
if (download_server == "http") {
while (success == FALSE) {

size_string <- httr::RETRY("GET",
paste0(remote_filename, ".xml"),
httr::authenticate(user, password, type = "any"),
times = n_retries,
pause_base = 0.1,
pause_cap = 10,
quiet = verbose)
size_req <- httr2::request(paste0(remote_filename, ".xml")) %>%
httr2::req_auth_bearer_token(token)

size_resp <- httr2::req_perform(size_req)

# if user/password are not valid, notify
if (size_string["status_code"] == 401) {
stop("Username and/or password are not valid. Please provide
valid ones!")
if (httr2::resp_status(size_resp) == 401) {
stop("Username and/or password are not valid. Please provide valid ones!")
}

if (size_string$status_code == 200) {
if (httr2::resp_status(size_resp) == 200) {
remote_filesize <- as.integer(
xml2::as_list(
httr::content(
size_string, encoding = "UTF-8"))[["GranuleMetaDataFile"]][["GranuleURMetaData"]][["DataFiles"]][["DataFileContainer"]][["FileSize"]] #nolint
httr2::resp_body_xml(size_resp))[["GranuleMetaDataFile"]][["GranuleURMetaData"]][["DataFiles"]][["DataFileContainer"]][["FileSize"]] #nolint
)
success <- TRUE
} else {
Expand Down Expand Up @@ -140,29 +140,28 @@ MODIStsp_download <- function(modislist,
download <- try(system(aria_string,
intern = Sys.info()["sysname"] == "Windows"))
} else {
# http download - httr
download <- try(httr::GET(remote_filename,
httr::authenticate(user, password, type = "any"),
# httr::progress(),
httr::write_disk(local_filename,
overwrite = TRUE)))
# http download - httr2
download_req <- httr2::request(remote_filename) %>%
httr2::req_auth_bearer_token(token) %>%
httr2::req_retry(max_tries = n_retries, backoff = ~ 10)

download <- httr2::req_perform(download_req, path = local_filename)
}
}

# Check for errors on download try
if (inherits(download, "try-error") |
!is.null(attr(download, "status"))) {
!file.exists(local_filename)) {
attempt <- attempt + 1
if (verbose) message("[", date(), "] Download Error - Retrying...")
unlink(local_filename) # On download error, delete incomplete files
Sys.sleep(1) # sleep for a while....
} else {
if (download_server == "http" & use_aria == FALSE) {
download_resp <- httr2::resp_status(download)

if (download$status_code != 200 &
length(httr::content(download,
"text",
encoding = "UTF-8")) == 1) {
if (download_resp != 200 &
file.info(local_filename)$size == 0) {
# on error, delete last HDF file (to be sure no incomplete
# files are left behind and send message)
if (verbose) {
Expand Down
8 changes: 8 additions & 0 deletions R/MODIStsp_process.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ MODIStsp_process <- function(proc_opts,
check_aria <- Sys.which("aria2c")
if (check_aria == "") use_aria <- FALSE

# __________________________________________________________________________
# Fetch Bearer token to be used for further authentication
## this exist of earthdata_token can't work, WIP mdsumner
if (exists("earthdata_token")) {
token <- earthdata_token
} else {
token <- get_earthdata_token(proc_opts$user, proc_opts$password)
}

# __________________________________________________________________________
# Start Working. ####
Expand Down
30 changes: 30 additions & 0 deletions R/get_earthdata_token.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#' @title Get Earthdata Bearer access token function
#' @description Internal function to fetch Earthdata access token
#' @details The function is used to:
#' - Fetch Bearer token if there is one already defined;
#' - Request new token if no token is defined
#' - Update token if the token is expired
#' - Bearer token is used for authentication by other functions
#' @param user `character` Username for Earthdata servers
#' @param password `character` Password for Earthdata servers
#' @return The function is called for its side effects
#' @rdname get_earthdata_token
#' @importFrom httr2 request req_perform req_auth_basic req_headers resp_body_xml req_method

get_earthdata_token <- function(user, password) {
endpoint = "https://urs.earthdata.nasa.gov/api/users/tokens"
resp <- httr2::request(endpoint) |> httr2::req_auth_basic(user, password) |> httr2::req_perform()
token_one <- httr2::resp_body_json(resp)[[1]]

# Check if no token available; if not, request one
if(length(token_one) < 1)
{
endpoint = "https://urs.earthdata.nasa.gov/api/users/token"
resp <- httr2::request(endpoint) |> req_method("PUT") |> httr2::req_auth_basic(user, password) |> httr2::req_perform()
}
token_one <- httr2::resp_body_json(resp)[[1]]
access_token <- token_one$access_token
# Return token
access_token
}

43 changes: 22 additions & 21 deletions R/get_mod_dirs.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' be identified
#' @param n_retries `numeric` number of times the access to the http server
#' should be retried in case of error before quitting, Default: 20
#' @param gui `logical`` indicates if processing was called from the GUI
#' @param gui `logical` indicates if processing was called from the GUI
#' environment or not. If not, processing messages are sent to a log file
#' instead than to the console/GTK progress windows.
#' @param out_folder_mod `character` output folder for MODIS HDF storage
Expand All @@ -25,18 +25,28 @@
#' FTP) by:
#' @author Lorenzo Busetto, phD (2014-2017)
#' @author Luigi Ranghetti, phD (2016-2017)
#' @author Pasi Autio (2024)
#' @note License: GPL 3.0
#' @importFrom stringr str_sub str_split
#' @importFrom httr RETRY authenticate content
#' @importFrom httr2 request req_perform req_auth_bearer_token req_headers resp_body_string req_retry resp_status

get_mod_dirs <- function(http,
download_server,
user, password,
yy,
n_retries,
n_retries = 20,
gui,
out_folder_mod) {

# Fetch Bearer token to be used for further authentication
if (is.null(earthdata_token))
{
token <- earthdata_token
} else
{
token <- get_earthdata_token(user, password)
}

# make sure that the http address terminates with a "/" (i.e., it is a
# folder, not a file)
if (stringr::str_sub(http, -1) != "/") {
Expand All @@ -47,24 +57,16 @@ get_mod_dirs <- function(http,
# retrieve list of folders in case of http download ####

if (download_server == "http") {
response <- data.frame(status_code = "")
response <- list(status_code = "")
while (response$status_code != 200) {
# send request to server
response <- try(
httr::RETRY("GET",
http,
httr::authenticate(user, password),
times = n_retries,
pause_base = 0.1,
pause_cap = 3,
quiet = FALSE),
silent = TRUE
)
req <- httr2::request(http) %>%
httr2::req_auth_bearer_token(token) %>%
httr2::req_retry(max_tries = n_retries, backoff = ~ 10)
response <- httr2::req_perform(req)

# On interactive execution, after n_retries attempt ask if quit or ----
# retry

if (inherits(response, "try-error") || response$status_code != 200) {
# On interactive execution, after n_retries attempt ask if quit or retry
if (inherits(response, "try-error") || httr2::resp_status(response) != 200) {
message(
"[", date(), "] Error: http server seems to be down! ",
"Please try again later. Aborting!"
Expand All @@ -74,9 +76,8 @@ get_mod_dirs <- function(http,
return(date_dirs)
}
}
# On httr success get the directory names (available dates) ----
items <- strsplit(httr::content(response, "text", encoding = "UTF-8"),
"\r*\n")[[1]]
# On httr2 success get the directory names (available dates) ----
items <- strsplit(httr2::resp_body_string(response), "\r*\n")[[1]]
date_dirs <- gsub(
".*>(20[0-9]{2}\\.[01][0-9]\\.[0-3][0-9])\\/<.*", "\\1", items
)
Expand Down
32 changes: 21 additions & 11 deletions R/get_mod_filenames.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
#' FTP) by:
#' @author Lorenzo Busetto, phD (2014-2016)
#' @author Luigi Ranghetti, phD (2016)
#' @author Pasi Autio (2024)
#' @note License: GPL 3.0
#' @importFrom httr RETRY authenticate content
#' @importFrom httr2 request req_perform req_auth_bearer_token req_headers resp_body_xml req_retry resp_body_string
#' @importFrom stringr str_split str_pad
get_mod_filenames <- function(http,
used_server,
Expand All @@ -44,7 +45,15 @@ get_mod_filenames <- function(http,
out_folder_mod,
gui) {


# Fetch Bearer token to be used for further authentication
if (is.null(earthdata_token))
{
token <- earthdata_token
} else
{
token <- get_earthdata_token(user, password)
}

success <- FALSE
if (used_server == "http") {
# ________________________________________________________________________
Expand All @@ -53,13 +62,12 @@ get_mod_filenames <- function(http,
# http folders are organized by date subfolders containing all tiles
while (!success) {

response <- httr::RETRY("GET",
paste0(http, date_dir, "/"),
httr::authenticate(user, password),
times = n_retries,
pause_base = 0.1,
pause_cap = 10,
quiet = FALSE)
# Create a request object using httr2
req <- httr2::request(paste0(http, date_dir, "/")) %>%
httr2::req_auth_bearer_token(token) %>%
httr2::req_retry(max_tries = n_retries, backoff = ~ 10)

response <- httr2::req_perform(req)

# On interactive execution, after n_retries attempt ask if quit or ----
# retry
Expand All @@ -68,15 +76,16 @@ get_mod_filenames <- function(http,
"Please try again later. Aborting!", call. = FALSE)

} else {
getlist <- strsplit(httr::content(response, "text", encoding = "UTF-8"),
"\r*\n")[[1]]
content <- httr2::resp_body_string(response)
getlist <- strsplit(content, "\r*\n")[[1]]
getlist <- getlist[grep(
".*>([A-Z0-9]+\\.A[0-9]+(?:\\.h[0-9]{2}v[0-9]{2})?\\.[0-9]+\\.[0-9]+\\.hdf)<.*", #nolint
getlist)]
getlist <- gsub(
".*>([A-Z0-9]+\\.A[0-9]+(?:\\.h[0-9]{2}v[0-9]{2})?\\.[0-9]+\\.[0-9]+\\.hdf)<.*", "\\1", #nolint
getlist)
success <- TRUE
print(getlist)

}
}
Expand Down Expand Up @@ -126,5 +135,6 @@ get_mod_filenames <- function(http,
} else {
Modislist <- grep(".hdf$", getlist, value = TRUE)
}
print(Modislist)
return(Modislist)
}
3 changes: 3 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ For more information, documentation and examples of use, __see also the `{MODISt

## Important News

- 13/05/2023 - `{MODIStsp}` (GitHub version 2.1.1)
Update MODIStsp to use httr2 package instead of obsolete httr to access Earthdata site while fixing the authentication issues at the same time.

- 29/10/2021 - `{MODIStsp}` (GitHub version 2.0.6.9000) supports products with version 061.
Version 006 will remain the default product version until its decommission
will be announced.
Expand Down
Loading