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
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
Expand All @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 0 additions & 24 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -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
#' <https://archimer.ifremer.fr/doc/00751/86306/>
"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
#' <https://archimer.ifremer.fr/doc/00751/86306/>
"rscd_dir"

#' Resourcecode data extract
#'
#' An extract of the Resourcecode Hindcast database, at node 123456, spanning from
Expand Down
17 changes: 9 additions & 8 deletions R/orbital_speed.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
13 changes: 7 additions & 6 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/resourcecode-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions R/specta_data_ploting.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)"

Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
8 changes: 7 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion R/weather_windows.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down
Binary file removed data/rscd_dir.rda
Binary file not shown.
Binary file removed data/rscd_freq.rda
Binary file not shown.
9 changes: 4 additions & 5 deletions devtools_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion man/compute_orbital_speeds.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/jonswap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/resourcecode-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 0 additions & 23 deletions man/rscd_dir.Rd

This file was deleted.

24 changes: 0 additions & 24 deletions man/rscd_freq.Rd

This file was deleted.

21 changes: 14 additions & 7 deletions tests/testthat/test-test_closest_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Test Suite 1: Input Validation
# ==============================================================================


test_that("Input validation works correctly", {
# Test ill-formed coordinates input
expect_error(
Expand Down Expand Up @@ -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))

Expand All @@ -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))
Expand All @@ -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))

Expand All @@ -119,14 +118,22 @@ 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)
expect_named(output_spec, c("points", "distances"))
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)
})
Loading
Loading