Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/check-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN || secrets.NASA_EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.NASA_EARTHDATA_TOKEN || secrets.EARTHDATA_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-coverage-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN || secrets.NASA_EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.NASA_EARTHDATA_TOKEN || secrets.EARTHDATA_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-live.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Scheduled live-API test workflow.
#
# Runs every Monday at 06:00 UTC, plus on-demand (with optional `filter`
# Runs nightly at 06:00 UTC, plus on-demand (with optional `filter`
# input). Sets AMADEUS_LIVE_TESTS=true so that `skip_if_no_live_tests()`
# does not skip the `test-*-live.R` files. On failure, an issue is
# auto-opened (label: live-test-failure) so repo watchers receive an
# email notification.
on:
schedule:
- cron: '0 6 * * 1'
- cron: '0 6 * * *'
workflow_dispatch:
Comment on lines 8 to 11
inputs:
filter:
Expand All @@ -25,8 +25,8 @@ jobs:
issues: write
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN }}
EARTHDATA_TOKEN: ${{ secrets.EARTHDATA_TOKEN || secrets.NASA_EARTHDATA_TOKEN }}
NASA_EARTHDATA_TOKEN: ${{ secrets.NASA_EARTHDATA_TOKEN || secrets.EARTHDATA_TOKEN }}
AMADEUS_LIVE_TESTS: "true"
NOT_CRAN: "true"

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: amadeus
Title: Accessing and Analyzing Large-Scale Environmental Data
Version: 2.0.0
Version: 2.0.1
Comment on lines 1 to +3
Authors@R: c(
Comment on lines 1 to 4
person(given = "Mitchell", family = "Manware", role = c("aut", "ctb"), comment = c(ORCID = "0009-0003-6440-6106")),
person(given = "Insang", family = "Song", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-8732-3256")),
Expand Down
35 changes: 27 additions & 8 deletions R/download_auxiliary.R
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ check_url_status <- function(
) {
http_status_ok <- c(200, 206)

tryCatch(
status_head <- tryCatch(
{
status <- url |>
url |>
httr2::request() |>
httr2::req_method("HEAD") |>
httr2::req_error(is_error = \(resp) FALSE) |>
Expand All @@ -854,15 +854,34 @@ check_url_status <- function(
) |>
httr2::req_perform() |>
httr2::resp_status()
},
error = function(e) NA_integer_
)

if (!is.na(status_head) && status_head %in% http_status_ok) {
Sys.sleep(1)
return(TRUE)
}

Sys.sleep(1)
return(status %in% http_status_ok)
# Some hosts reject/flake on HEAD; probe with a tiny ranged GET.
status_get <- tryCatch(
{
url |>
httr2::request() |>
httr2::req_headers(Range = "bytes=0-0") |>
httr2::req_error(is_error = \(resp) FALSE) |>
httr2::req_retry(
max_tries = max_tries,
retry_on_failure = TRUE
) |>
httr2::req_perform() |>
httr2::resp_status()
},
error = function(e) {
# Return FALSE for any errors (network, DNS, SSL, etc.)
return(FALSE)
}
error = function(e) NA_integer_
)

Sys.sleep(1)
!is.na(status_get) && status_get %in% http_status_ok
}

#' Import download commands
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-edgar-live.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ testthat::test_that(
{
skip_if_no_live_tests()
dir <- withr::local_tempdir()
amadeus::download_edgar(
amadeus::download_edgar(
species = "CO",
version = "8.1",
temp_res = "yearly",
Expand All @@ -35,7 +35,7 @@ testthat::test_that(
{
skip_if_no_live_tests()
dir <- withr::local_tempdir()
amadeus::download_edgar(
amadeus::download_edgar(
species = "SO2",
version = "8.1",
temp_res = "monthly",
Expand All @@ -53,15 +53,15 @@ amadeus::download_edgar(

testthat::test_that(
paste0(
"download_edgar(version='8.1_voc', voc='01'): ",
"download_edgar(version='8.1_voc', voc='1'): ",
"downloads VOC speciation file"
),
{
skip_if_no_live_tests()
dir <- withr::local_tempdir()
amadeus::download_edgar(
amadeus::download_edgar(
version = "8.1_voc",
voc = "01",
voc = "1",
format = "nc",
Comment on lines 63 to 65
Comment on lines +62 to 65
output = "emi",
directory_to_save = dir,
Expand Down
36 changes: 22 additions & 14 deletions tests/testthat/test-modis-live.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ testthat::test_that(
),
{
skip_if_no_live_tests()
testthat::skip_if(!nzchar(Sys.getenv("EARTHDATA_TOKEN")),
"no Earthdata token")
testthat::skip_if(
!nzchar(Sys.getenv("NASA_EARTHDATA_TOKEN")),
"no Earthdata token"
)
dir <- withr::local_tempdir()
amadeus::download_modis(
product = "MOD09GA",
version = "061",
nasa_earth_data_token = Sys.getenv("EARTHDATA_TOKEN"),
nasa_earth_data_token = Sys.getenv("NASA_EARTHDATA_TOKEN"),
date = c("2024-01-01", "2024-01-01"),
extent = c(-79, 35, -78, 36),
directory_to_save = dir,
Expand All @@ -34,13 +36,15 @@ testthat::test_that(
),
{
skip_if_no_live_tests()
testthat::skip_if(!nzchar(Sys.getenv("EARTHDATA_TOKEN")),
"no Earthdata token")
testthat::skip_if(
!nzchar(Sys.getenv("NASA_EARTHDATA_TOKEN")),
"no Earthdata token"
)
dir <- withr::local_tempdir()
amadeus::download_modis(
product = "MOD11A1",
version = "061",
nasa_earth_data_token = Sys.getenv("EARTHDATA_TOKEN"),
nasa_earth_data_token = Sys.getenv("NASA_EARTHDATA_TOKEN"),
date = c("2022-01-01", "2022-01-01"),
extent = c(-79, 35, -78, 36),
directory_to_save = dir,
Expand All @@ -59,13 +63,15 @@ testthat::test_that(
),
{
skip_if_no_live_tests()
testthat::skip_if(!nzchar(Sys.getenv("EARTHDATA_TOKEN")),
"no Earthdata token")
testthat::skip_if(
!nzchar(Sys.getenv("NASA_EARTHDATA_TOKEN")),
"no Earthdata token"
)
dir <- withr::local_tempdir()
amadeus::download_modis(
product = "MCD19A2",
version = "061",
nasa_earth_data_token = Sys.getenv("EARTHDATA_TOKEN"),
nasa_earth_data_token = Sys.getenv("NASA_EARTHDATA_TOKEN"),
date = c("2022-01-01", "2022-01-01"),
extent = c(-79, 35, -78, 36),
directory_to_save = dir,
Expand All @@ -79,18 +85,20 @@ testthat::test_that(

testthat::test_that(
paste0(
"download_modis(product='MOD06_L2', date=<single day>, extent=<NC>): ",
"download_modis(product='MOD06_L2', date=<month range>, extent=<NC>): ",
"downloads cloud product file"
),
{
skip_if_no_live_tests()
testthat::skip_if(!nzchar(Sys.getenv("EARTHDATA_TOKEN")),
"no Earthdata token")
testthat::skip_if(
!nzchar(Sys.getenv("NASA_EARTHDATA_TOKEN")),
"no Earthdata token"
)
dir <- withr::local_tempdir()
amadeus::download_modis(
product = "MOD06_L2",
nasa_earth_data_token = Sys.getenv("EARTHDATA_TOKEN"),
date = c("2022-01-01", "2022-01-01"),
nasa_earth_data_token = Sys.getenv("NASA_EARTHDATA_TOKEN"),
date = c("2022-01-01", "2022-01-31"),
extent = c(-79, 35, -78, 36),
Comment on lines 98 to 102
directory_to_save = dir,
acknowledgement = TRUE
Expand Down
Loading