diff --git a/DESCRIPTION b/DESCRIPTION
index 226171f..1a523cc 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: resourcecode
Title: Access to the 'RESOURCECODE' Hindcast Database
-Version: 0.5.3.9000
+Version: 0.5.4
Authors@R:
person("Nicolas", "Raillard", , "nicolas.raillard@ifremer.fr", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-3385-5104"))
@@ -13,7 +13,6 @@ Description: Utility functions to download data from the 'RESOURCECODE'
surface elevation variance spectral density.
License: GPL (>= 3)
URL: https://github.com/Resourcecode-project/r-resourcecode,
- https://resourcecode-project.github.io/r-resourcecode/,
https://resourcecode-project.r-universe.dev/resourcecode
BugReports: https://github.com/Resourcecode-project/r-resourcecode/issues
Depends:
@@ -47,10 +46,10 @@ LinkingTo:
RcppArmadillo
VignetteBuilder:
knitr
+Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
-RoxygenNote: 7.3.3
diff --git a/NEWS.md b/NEWS.md
index b6d9086..e280563 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,4 @@
-# resourcecode (development version)
+# resourcecode 0.5.4
- `get_parameters` now correctly handles `Date` format as inputs by spanning on the right period;
- Update `rscd_casandra_end_date` with new data availability: 2025-12-31 23:00:00.
diff --git a/R/data.R b/R/data.R
index f73c886..a163f1e 100644
--- a/R/data.R
+++ b/R/data.R
@@ -1,27 +1,3 @@
-#' Resourcecode frequency vector of 1D and 2D spectra
-#'
-#' The wave spectrum discretization considers 36 frequencies, starting from
-#' 0.0339 Hz up to 0.9526 Hz with a frequency increment factor of 1.1
-#'
-#' @format ## `rscd_freq`
-#' An array 36 elements with the frequencies values
-#'
-#' @source User Manual of the RESOURCECODE database
-#'
-"rscd_freq"
-
-#' Resourcecode directional bins
-#'
-# In terms of directional discretization, 36 directions were used
-#' (equivalent to a directional resolution of 10°;
-#'
-#' @format ## `rscd_dir`
-#' An array of length 36 with the directionnal bins
-#'
-#' @source User Manual of the RESOURCECODE database
-#'
-"rscd_dir"
-
#' Resourcecode data extract
#'
#' An extract of the Resourcecode Hindcast database, at node 123456, spanning from
diff --git a/R/orbital_speed.R b/R/orbital_speed.R
index b746452..7b6d2d0 100644
--- a/R/orbital_speed.R
+++ b/R/orbital_speed.R
@@ -16,7 +16,7 @@
#' S <- t(sapply(1:10, function(h) {
#' jonswap(h)$spec
#' }))
-#' orb_speeds <- compute_orbital_speeds(S, rscd_freq, depth = 100, z = 10)
+#' orb_speeds <- compute_orbital_speeds(S, resourcecodedata::rscd_freq, depth = 100, z = 10)
#' plot(1:10, orb_speeds[, 1],
#' type = "l",
#' ylim = range(orb_speeds),
@@ -25,11 +25,12 @@
#' )
#' lines(1:10, orb_speeds[, 2], type = "l", col = "red")
compute_orbital_speeds <- function(
- spec,
- freq,
- z = 0,
- depth = Inf,
- output_speeds = FALSE) {
+ spec,
+ freq,
+ z = 0,
+ depth = Inf,
+ output_speeds = FALSE
+) {
# z: distance above sea floor
dims <- dim(spec)
@@ -69,8 +70,8 @@ compute_orbital_speeds <- function(
if (output_speeds) {
out <- array(NA, dim = c(dim(spectral_u_component), 2))
- out[, , 1] <- spectral_u_component
- out[, , 2] <- spectral_v_component
+ out[,, 1] <- spectral_u_component
+ out[,, 2] <- spectral_v_component
out
} else {
u_rms <- sqrt(2 * resourcecode::fastTrapz(freq, spectral_u_component, 2))
diff --git a/R/plots.R b/R/plots.R
index b0eea7c..8a29ba3 100644
--- a/R/plots.R
+++ b/R/plots.R
@@ -17,12 +17,13 @@
#' rscd_mapplot(resourcecodedata::rscd_field$depth)
#'
rscd_mapplot <- function(
- z,
- name = "Depth (m)",
- zlim = NULL,
- palette = "YlOrRd",
- direction = 1,
- transform = "identity") {
+ z,
+ name = "Depth (m)",
+ zlim = NULL,
+ palette = "YlOrRd",
+ direction = 1,
+ transform = "identity"
+) {
xyzgz <- tibble::tibble(
x = resourcecodedata::rscd_field$longitude[
resourcecodedata::rscd_triangles
diff --git a/R/resourcecode-package.R b/R/resourcecode-package.R
index 64d1813..5cb093d 100644
--- a/R/resourcecode-package.R
+++ b/R/resourcecode-package.R
@@ -3,7 +3,7 @@
## usethis namespace: start
#' @importFrom ggplot2 ggplot aes geom_path coord_sf theme_void geom_polygon scale_fill_distiller
-#' scale_color_distiller theme margin element_rect element_blank geom_rect
+#' @importFrom ggplot2 scale_color_distiller theme margin element_rect element_blank geom_rect
#' @importFrom Rcpp sourceCpp evalCpp
#' @importFrom rlang .data
#' @useDynLib resourcecode, .registration = TRUE
diff --git a/R/specta_data_ploting.R b/R/specta_data_ploting.R
index 7dd3bd4..67869d8 100644
--- a/R/specta_data_ploting.R
+++ b/R/specta_data_ploting.R
@@ -13,8 +13,8 @@
#' @examples
#' plot_2d_specta(resourcecodedata::rscd_2d_spectra, 1)
#' @importFrom ggplot2 ggplot geom_rect scale_x_continuous scale_y_continuous
-#' theme_linedraw coord_polar scale_color_distiller scale_fill_distiller
-#' labs expansion
+#' @importFrom ggplot2 theme_linedraw coord_polar scale_color_distiller scale_fill_distiller
+#' @importFrom ggplot2 labs expansion
plot_2d_specta <- function(
spec,
time = 1L,
@@ -36,7 +36,7 @@ plot_2d_specta <- function(
df_freq$frequency2 <- spec$frequency2[df_freq$frequency1]
df_freq$frequency1 <- spec$frequency1[df_freq$frequency1]
- df <- tibble::tibble(df_freq, ef = c(spec$efth[, , time]))
+ df <- tibble::tibble(df_freq, ef = c(spec$efth[,, time]))
legend_text <- "Power spectrum\n(m^2.s)"
@@ -116,8 +116,7 @@ plot_2d_specta <- function(
#' @examples
#' plot_1d_specta(resourcecodedata::rscd_1d_spectra, 1)
#' @importFrom ggplot2 ggplot geom_line scale_x_continuous scale_y_continuous
-#' theme_linedraw
-#' labs expansion
+#' @importFrom ggplot2 theme_linedraw labs expansion
plot_1d_specta <- function(
spec,
time = 1L,
@@ -136,7 +135,7 @@ plot_1d_specta <- function(
warning(
"Frequency vector not provided: using the default Resourcecode frequency vector."
)
- freq_plot <- rscd_freq
+ freq_plot <- resourcecodedata::rscd_freq
} else {
freq_plot <- spec$freq
}
diff --git a/R/sysdata.rda b/R/sysdata.rda
index 36f61de..102dc85 100644
Binary files a/R/sysdata.rda and b/R/sysdata.rda differ
diff --git a/R/utils.R b/R/utils.R
index 7574549..51aaa0e 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -235,7 +235,13 @@ metconv2zmcomp <- function(speed, direction, names = c("uwnd", "vwnd")) {
#' plot(S1, type = "l", ylim = c(0, 72))
#' lines(S2, col = "red")
#' abline(v = 1 / 15)
-jonswap <- function(hs = 5, tp = 15, fmax = rscd_freq, df = NULL, gam = 3.3) {
+jonswap <- function(
+ hs = 5,
+ tp = 15,
+ fmax = resourcecodedata::rscd_freq,
+ df = NULL,
+ gam = 3.3
+) {
if (length(fmax) > 1) {
# Case when the frequency vector if given
freq <- fmax
diff --git a/R/weather_windows.R b/R/weather_windows.R
index e6b722b..e444695 100644
--- a/R/weather_windows.R
+++ b/R/weather_windows.R
@@ -12,7 +12,12 @@
#'
#' @return POSIXct vector of detected window start times.
#' @export
-weather_windows <- function(valid_periods, window_length, allow_overlap = TRUE, time_step = 3600) {
+weather_windows <- function(
+ valid_periods,
+ window_length,
+ allow_overlap = TRUE,
+ time_step = 3600
+) {
if ("time" %nin% names(valid_periods)) {
stop("'valid_periods' must be a data frame with a 'time' column (POSIXct)")
}
diff --git a/data/rscd_dir.rda b/data/rscd_dir.rda
deleted file mode 100644
index e90532e..0000000
Binary files a/data/rscd_dir.rda and /dev/null differ
diff --git a/data/rscd_freq.rda b/data/rscd_freq.rda
deleted file mode 100644
index 7a1f154..0000000
Binary files a/data/rscd_freq.rda and /dev/null differ
diff --git a/devtools_history.R b/devtools_history.R
index 8ec2298..1249c4d 100644
--- a/devtools_history.R
+++ b/devtools_history.R
@@ -28,6 +28,7 @@ rscd_data_example = resourcecode::get_parameters(
parameters = c("hs", "tp", "dp", "uwnd", "vwnd", "dpt")
)
usethis::use_data(rscd_data_example, version = 3, overwrite = TRUE)
+tools::resaveRdaFiles("data/")
rcd_cassandra_url = "https://resourcecode-datacharts.ifremer.fr/"
rscd_hindcast_start_date = as.POSIXct("1994-01-01 00:00:00", tz = 'UTC')
@@ -36,9 +37,6 @@ rscd_hindcast_end_date = as.POSIXct("2024-12-31 23:00:00", tz = 'UTC')
rscd_casandra_start_date = as.POSIXct("1994-01-01 00:00:00", tz = 'UTC')
rscd_casandra_end_date = as.POSIXct("2025-12-31 23:00:00", tz = 'UTC')
-rscd_freq <- array(0.0339 * 1.1^(0:35))
-rscd_dir <- array(seq(from = 0, to = 350, by = 10))
-
usethis::use_data(
rcd_cassandra_url,
rscd_hindcast_start_date,
@@ -51,7 +49,8 @@ usethis::use_data(
version = 3,
overwrite = TRUE
)
-tools::resaveRdaFiles("data/")
+tools::resaveRdaFiles("R/")
+
#set up automatic "check" on several plateforms
usethis::use_github_action()
@@ -135,7 +134,7 @@ devtools::check_mac_release()
# Upgrade version number
-usethis::use_version(which = c("patch", "minor", "major", "dev")[3])
+usethis::use_version(which = c("patch", "minor", "major", "dev")[1])
usethis::use_release_issue()
diff --git a/man/compute_orbital_speeds.Rd b/man/compute_orbital_speeds.Rd
index 5f45b78..17de5b6 100644
--- a/man/compute_orbital_speeds.Rd
+++ b/man/compute_orbital_speeds.Rd
@@ -30,7 +30,7 @@ Compute the orbital speed at a given depth from the wave elevation 1D spectra
S <- t(sapply(1:10, function(h) {
jonswap(h)$spec
}))
-orb_speeds <- compute_orbital_speeds(S, rscd_freq, depth = 100, z = 10)
+orb_speeds <- compute_orbital_speeds(S, resourcecodedata::rscd_freq, depth = 100, z = 10)
plot(1:10, orb_speeds[, 1],
type = "l",
ylim = range(orb_speeds),
diff --git a/man/jonswap.Rd b/man/jonswap.Rd
index 8df1f02..2be76f6 100644
--- a/man/jonswap.Rd
+++ b/man/jonswap.Rd
@@ -4,7 +4,13 @@
\alias{jonswap}
\title{JONWSAP spectrum}
\usage{
-jonswap(hs = 5, tp = 15, fmax = rscd_freq, df = NULL, gam = 3.3)
+jonswap(
+ hs = 5,
+ tp = 15,
+ fmax = resourcecodedata::rscd_freq,
+ df = NULL,
+ gam = 3.3
+)
}
\arguments{
\item{hs}{Hs (default: 5m)}
diff --git a/man/resourcecode-package.Rd b/man/resourcecode-package.Rd
index 8cc8677..c9a8055 100644
--- a/man/resourcecode-package.Rd
+++ b/man/resourcecode-package.Rd
@@ -23,5 +23,10 @@ Useful links:
\author{
\strong{Maintainer}: Nicolas Raillard \email{nicolas.raillard@ifremer.fr} (\href{https://orcid.org/0000-0003-3385-5104}{ORCID})
+Authors:
+\itemize{
+ \item Nicolas Raillard \email{nicolas.raillard@ifremer.fr} (\href{https://orcid.org/0000-0003-3385-5104}{ORCID})
+}
+
}
\keyword{internal}
diff --git a/man/rscd_dir.Rd b/man/rscd_dir.Rd
deleted file mode 100644
index a4078ea..0000000
--- a/man/rscd_dir.Rd
+++ /dev/null
@@ -1,23 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/data.R
-\docType{data}
-\name{rscd_dir}
-\alias{rscd_dir}
-\title{Resourcecode directional bins}
-\format{
-\subsection{\code{rscd_dir}}{
-
-An array of length 36 with the directionnal bins
-}
-}
-\source{
-User Manual of the RESOURCECODE database
-\url{https://archimer.ifremer.fr/doc/00751/86306/}
-}
-\usage{
-rscd_dir
-}
-\description{
-(equivalent to a directional resolution of 10°;
-}
-\keyword{datasets}
diff --git a/man/rscd_freq.Rd b/man/rscd_freq.Rd
deleted file mode 100644
index 69bbe20..0000000
--- a/man/rscd_freq.Rd
+++ /dev/null
@@ -1,24 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/data.R
-\docType{data}
-\name{rscd_freq}
-\alias{rscd_freq}
-\title{Resourcecode frequency vector of 1D and 2D spectra}
-\format{
-\subsection{\code{rscd_freq}}{
-
-An array 36 elements with the frequencies values
-}
-}
-\source{
-User Manual of the RESOURCECODE database
-\url{https://archimer.ifremer.fr/doc/00751/86306/}
-}
-\usage{
-rscd_freq
-}
-\description{
-The wave spectrum discretization considers 36 frequencies, starting from
-0.0339 Hz up to 0.9526 Hz with a frequency increment factor of 1.1
-}
-\keyword{datasets}
diff --git a/tests/testthat/test-test_closest_point.R b/tests/testthat/test-test_closest_point.R
index e61e57c..fe27124 100644
--- a/tests/testthat/test-test_closest_point.R
+++ b/tests/testthat/test-test_closest_point.R
@@ -2,7 +2,6 @@
# Test Suite 1: Input Validation
# ==============================================================================
-
test_that("Input validation works correctly", {
# Test ill-formed coordinates input
expect_error(
@@ -52,14 +51,16 @@ test_that("Unique node selection works", {
node_test
)
expect_equal(closest_point_spec(point_test)$point, spec_test)
- expect_equal(closest_point_spec(point_test[1], point_test[2])$point, spec_test)
+ expect_equal(
+ closest_point_spec(point_test[1], point_test[2])$point,
+ spec_test
+ )
})
# ==============================================================================
# Test Suite 3: Multiple nodes selection
# ==============================================================================
-
test_that("Multiple nodes selection works", {
skip_if(!requireNamespace("resourcecodedata", quietly = TRUE))
@@ -73,7 +74,6 @@ test_that("Multiple nodes selection works", {
node_test <- matrix(c(100, 1000), ncol = 2)
spec_test <- matrix(c(23045, 22274), ncol = 2)
-
output <- closest_point_field(point_test)
expect_named(output, c("points", "distances"))
expect_identical(dim(output$points), c(1L, 2L))
@@ -98,7 +98,6 @@ test_that("Multiple nodes selection works", {
# Test Suite 4: Several closest points selection
# ==============================================================================
-
test_that("List of closest nodes selection works", {
skip_if(!requireNamespace("resourcecodedata", quietly = TRUE))
@@ -119,7 +118,11 @@ test_that("List of closest nodes selection works", {
expect_equal(output$point, node_test)
expect_true(all(output$distance[, 1] == 0))
- output2 <- closest_point_field(point_test[, 1], point_test[, 2], closest = closest)
+ output2 <- closest_point_field(
+ point_test[, 1],
+ point_test[, 2],
+ closest = closest
+ )
expect_equal(output2, output)
output_spec <- closest_point_spec(point_test, closest = 3)
@@ -127,6 +130,10 @@ test_that("List of closest nodes selection works", {
expect_identical(dim(output_spec$points), c(2L, 3L))
expect_identical(dim(output_spec$distances), c(2L, 3L))
- output2_spec <- closest_point_spec(point_test[, 1], point_test[, 2], closest = 3)
+ output2_spec <- closest_point_spec(
+ point_test[, 1],
+ point_test[, 2],
+ closest = 3
+ )
expect_equal(output2_spec, output_spec)
})
diff --git a/tests/testthat/test_ww_calc.R b/tests/testthat/test_ww_calc.R
index 57d1bb0..b7eb68d 100644
--- a/tests/testthat/test_ww_calc.R
+++ b/tests/testthat/test_ww_calc.R
@@ -1,7 +1,9 @@
# Helper: create hourly sequence with optional gaps
make_times <- function(start, end, by = "hour", gaps = NULL) {
t <- seq.POSIXt(as.POSIXct(start), as.POSIXct(end), by = by)
- if (!is.null(gaps)) t <- t[-gaps]
+ if (!is.null(gaps)) {
+ t <- t[-gaps]
+ }
data.frame(time = t)
}
@@ -9,7 +11,12 @@ test_that("'weather_windows()' detects windows correctly with overlap", {
df <- make_times("2020-01-01 00:00:00", "2020-01-02 23:00:00")
# 24-hour windows, allow overlap
- res <- weather_windows(df, window_length = 24, allow_overlap = TRUE, time_step = 3600)
+ res <- weather_windows(
+ df,
+ window_length = 24,
+ allow_overlap = TRUE,
+ time_step = 3600
+ )
expect_true(length(res) > 0)
expect_true(all(res >= df$time[1]))
@@ -20,7 +27,11 @@ test_that("'weather_windows()' respects allow_overlap = FALSE", {
df <- make_times("2020-01-01 00:00:00", "2020-01-03 23:00:00")
res_overlap <- weather_windows(df, window_length = 24, allow_overlap = TRUE)
- res_no_overlap <- weather_windows(df, window_length = 24, allow_overlap = FALSE)
+ res_no_overlap <- weather_windows(
+ df,
+ window_length = 24,
+ allow_overlap = FALSE
+ )
expect_true(length(res_overlap) <= length(res_no_overlap))
expect_true(all(diff(res_overlap, units = "hours") >= 24)) # no overlapping windows
@@ -28,7 +39,11 @@ test_that("'weather_windows()' respects allow_overlap = FALSE", {
test_that("'weather_windows()' handles gaps correctly", {
# Remove some timestamps to simulate gaps
- df <- make_times("2020-01-01 00:00:00", "2020-01-02 23:00:00", gaps = c(10, 11, 12))
+ df <- make_times(
+ "2020-01-01 00:00:00",
+ "2020-01-02 23:00:00",
+ gaps = c(10, 11, 12)
+ )
res <- weather_windows(df, window_length = 5, allow_overlap = TRUE)
# Ensure all returned starts are within the original data
@@ -47,6 +62,11 @@ test_that("'weather_windows()' returns empty for insufficient data", {
test_that("'weather_windows()' handles non-hourly time_step", {
df <- make_times("2020-01-01 00:00:00", "2020-01-01 06:00:00", by = "2 hours")
- res <- weather_windows(df, window_length = 4, allow_overlap = TRUE, time_step = 2 * 3600)
+ res <- weather_windows(
+ df,
+ window_length = 4,
+ allow_overlap = TRUE,
+ time_step = 2 * 3600
+ )
expect_true(length(res) > 0)
})