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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^vignettes/articles$
^cran-comments\.md$
^CRAN-SUBMISSION$
^[.]?air[.]toml$
^\.vscode$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
46 changes: 46 additions & 0 deletions .github/workflows/format-suggest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples

on:
# Using `pull_request_target` over `pull_request` for elevated `GITHUB_TOKEN`
# privileges, otherwise we can't set `pull-requests: write` when the pull
# request comes from a fork, which is our main use case (external contributors).
#
# `pull_request_target` runs in the context of the target branch (`main`, usually),
# rather than in the context of the pull request like `pull_request` does. Due
# to this, we must explicitly checkout `ref: ${{ github.event.pull_request.head.sha }}`.
# This is typically frowned upon by GitHub, as it exposes you to potentially running
# untrusted code in a context where you have elevated privileges, but they explicitly
# call out the use case of reformatting and committing back / commenting on the PR
# as a situation that should be safe (because we aren't actually running the untrusted
# code, we are just treating it as passive data).
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
pull_request_target:

name: format-suggest.yaml

jobs:
format-suggest:
name: format-suggest
runs-on: ubuntu-latest

permissions:
# Required to push suggestion comments to the PR
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install
uses: posit-dev/setup-air@v1

- name: Format
run: air format .

- name: Suggest
uses: reviewdog/action-suggester@v1
with:
level: error
fail_level: error
tool_name: air
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"Posit.air-vscode"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"[r]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "Posit.air-vscode"
},
"[quarto]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "quarto.quarto"
}
}
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# getRad (development version)

* Start using the air formatter (#128).

# getRad 0.2.2

* Support downloading Slovakian polar volume data (#124).
Expand Down
30 changes: 18 additions & 12 deletions R/get_pvol.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,27 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
}
if (inherits(datetime, "POSIXct") && length(datetime) == 2) {
if (any(duplicated(datetime))) {
cli::cli_abort("When providing two {.cls POSIXct} as a {.arg datetime}
cli::cli_abort(
"When providing two {.cls POSIXct} as a {.arg datetime}
they should differ to represent an inverval.",
class = "getRad_error_duplicated_timestamps"
)
}
datetime <- lubridate::interval(min(datetime), max(datetime))
}
if (is.null(datetime) ||
!inherits(datetime, c("POSIXct", "Interval")) ||
!rlang::is_scalar_vector(datetime)
if (
is.null(datetime) ||
!inherits(datetime, c("POSIXct", "Interval")) ||
!rlang::is_scalar_vector(datetime)
) {
cli::cli_abort("The argument {.arg datetime} to the {.fn get_pvol} function
cli::cli_abort(
"The argument {.arg datetime} to the {.fn get_pvol} function
should be a single {.cls POSIXct} or a {.cls interval}.
The later can also be specified by two {.cls POSIXct}.",
class = "getRad_error_time_not_correct"
)
}


safe_get_pvol <- purrr::possibly(get_pvol, otherwise = NULL, quiet = TRUE)

# First start mapping over radars so later one only one radar is present. I
Expand All @@ -81,12 +83,12 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
return(pvols)
}


fn <- select_get_pvol_function(radar)

if (lubridate::is.interval(datetime)) {
if (lubridate::as.duration(datetime) > lubridate::hours(1)) {
cli::cli_warn("The interval specified for {.arg datetime} ({.val {lubridate::int_start(datetime)}}-{.val {lubridate::int_end(datetime)}}) likely results
cli::cli_warn(
"The interval specified for {.arg datetime} ({.val {lubridate::int_start(datetime)}}-{.val {lubridate::int_end(datetime)}}) likely results
in many polar volumes, when loading that may polar
volumes at the same time computational issues frequently
occur.",
Expand All @@ -99,7 +101,8 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
if (lubridate::is.interval(datetime)) {
timerange <-
lubridate::floor_date(
seq(lubridate::int_start(datetime),
seq(
lubridate::int_start(datetime),
lubridate::int_end(datetime) + lubridate::minutes(5),
by = "5 mins"
),
Expand All @@ -109,7 +112,12 @@ get_pvol <- function(radar = NULL, datetime = NULL, ...) {
polar_volumes <- purrr::map(datetime, safe_get_pvol, radar = radar, ...)
return(polar_volumes)
} else {
rlang::exec(fn, radar = radar, lubridate::floor_date(datetime, "5 mins"), ...)
rlang::exec(
fn,
radar = radar,
lubridate::floor_date(datetime, "5 mins"),
...
)
}
} else {
# For now then US data is request the interval if forwarded
Expand Down Expand Up @@ -147,5 +155,3 @@ select_get_pvol_function <- function(radar, ..., call = rlang::caller_env()) {
}
return(fun)
}


9 changes: 7 additions & 2 deletions R/get_pvol_cz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ get_pvol_cz <- function(radar, time, ..., call = rlang::caller_env()) {
# All parameters are retrieved from separate files
# Here all urls are generated
params <- c("z", "u", "v", "w", "zdr", "rhohv", "phidp")
urls <- glue::glue("http://opendata.chmi.cz/meteorology/weather/radar/sites/{substr(radar,3,5)}/vol_{params}/hdf5/")
urls <- glue::glue(
"http://opendata.chmi.cz/meteorology/weather/radar/sites/{substr(radar,3,5)}/vol_{params}/hdf5/"
)
rlang::check_installed(
c("lubridate", "tidyr", "xml2", "rhdf5"),
"to read Czech radar data",
Expand Down Expand Up @@ -36,6 +38,9 @@ get_pvol_cz <- function(radar, time, ..., call = rlang::caller_env()) {
time + lubridate::minutes(5)
)
))
pvol<-read_pvol_from_url_per_param(paste0(files_to_get$base, files_to_get$file))
pvol <- read_pvol_from_url_per_param(paste0(
files_to_get$base,
files_to_get$file
))
pvol
}
Loading