Title: | Access to the 'RESOURCECODE' Hindcast Database |
---|---|
Description: | Utility functions to download data from the 'RESOURCECODE' hindcast database of sea-states, time series of sea-state parameters and time series of 1D and 2D wave spectra. See <https://resourcecode.ifremer.fr> for more details about the available data. Also provides facilities to plot and analyse downloaded data, such as computing the sea-state parameters from both the 1D and 2D surface elevation variance spectral density. |
Authors: | Nicolas Raillard [aut, cre] |
Maintainer: | Nicolas Raillard <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.1.9000 |
Built: | 2024-12-05 11:20:19 UTC |
Source: | https://github.com/resourcecode-project/r-resourcecode |
Value Matching
x %nin% table
x %nin% table
x |
value to search |
table |
table of values |
the opposite of x %in% table
1:10 %in% c(1, 3, 5, 9) 1:10 %nin% c(1, 3, 5, 9)
1:10 %in% c(1, 3, 5, 9) 1:10 %nin% c(1, 3, 5, 9)
Find the closest point of the FIELD grid to the specified position
closest_point_field(x, lat = NULL, closest = 1L, ...)
closest_point_field(x, lat = NULL, closest = 1L, ...)
x |
vector of coordinates in the form longitude/latitude data frame |
lat |
alternatively, x and lat can be vector of the same length |
closest |
an integer to specify the number of point to output. |
... |
currently unused |
a list with two components: the closest point(s) of the grid and the distance (s).
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { semrev_west <- closest_point_field(c(-2.786, 47.239)) semrev_west }
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { semrev_west <- closest_point_field(c(-2.786, 47.239)) semrev_west }
Find the closest point of the SPEC grid to the specified position
closest_point_spec(x, lat = NULL, closest = 1L, ...)
closest_point_spec(x, lat = NULL, closest = 1L, ...)
x |
vector of coordinates in the form longitude/latitude data frame |
lat |
alternatively, x and lat can be vector of the same length |
closest |
an integer to specify the number of point to output. |
... |
currently unused |
a list with two components: the closest point(s) of the grid and the distance (s).
semrev_west <- closest_point_spec(c(-2.786, 47.239)) semrev_west
semrev_west <- closest_point_spec(c(-2.786, 47.239)) semrev_west
Compute the orbital speed at a given depth from the wave elevation 1D spectra
compute_orbital_speeds(spec, freq, z = 0, depth = Inf, output_speeds = FALSE)
compute_orbital_speeds(spec, freq, z = 0, depth = Inf, output_speeds = FALSE)
spec |
1D spectral data: TxM matrix |
freq |
the M frequencies |
z |
distance above the floor at which we want the orbital speed (single numeric) |
depth |
depth time series (vector length T. Recycled if a single value is given) |
output_speeds |
TRUE if the spectral speed are needed. Otherwise, returns the RMS (default) |
depending on spec, a list with the spectral velocities for each component (if output_speeds==FALSE) or a data.frame with a time series of horizontal and vertical components of (spectral) orbital speed.
# Compute orbital speed for varying Hs S <- t(sapply(1:10, \(h) jonswap(h)$spec)) orb_speeds <- compute_orbital_speeds(S, rscd_freq, depth = 100, z = 10) plot(1:10, orb_speeds[, 1], type = "l", ylim = range(orb_speeds), xlab = "Hs (m)", ylab = "Orbital speed RMS (m/s)" ) lines(1:10, orb_speeds[, 2], type = "l", col = "red")
# Compute orbital speed for varying Hs S <- t(sapply(1:10, \(h) jonswap(h)$spec)) orb_speeds <- compute_orbital_speeds(S, rscd_freq, depth = 100, z = 10) plot(1:10, orb_speeds[, 1], type = "l", ylim = range(orb_speeds), xlab = "Hs (m)", ylab = "Orbital speed RMS (m/s)" ) lines(1:10, orb_speeds[, 2], type = "l", col = "red")
Compute sea_state parameter from wave spectrum
compute_sea_state_1d_spectrum(spec, ...)
compute_sea_state_1d_spectrum(spec, ...)
spec |
1D spectrum data, e.g. from |
... |
currently unused |
a tibble with the sea-state parameters computed from the time series of 2D spectrum
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp", "cge", "t01", "dp", "dir") ) spec <- resourcecodedata::rscd_1d_spectra param_calc <- compute_sea_state_1d_spectrum(spec) oldpar <- par(mfcol = c(2, 2)) plot(param_calc$time, param_calc$hs, type = "l", xlab = "Time", ylab = "Hs (m)") lines(rscd_params$time, rscd_params$hs, col = "red") plot(param_calc$time, param_calc$cge, type = "l", xlab = "Time", ylab = "CgE (kW/m)") lines(rscd_params$time, rscd_params$cge, col = "red") plot(param_calc$time, param_calc$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") plot(param_calc$time, param_calc$dp, type = "l", xlab = "Time", ylab = "Peak direction (°)") lines(rscd_params$time, rscd_params$dp, col = "red") par(oldpar) }
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp", "cge", "t01", "dp", "dir") ) spec <- resourcecodedata::rscd_1d_spectra param_calc <- compute_sea_state_1d_spectrum(spec) oldpar <- par(mfcol = c(2, 2)) plot(param_calc$time, param_calc$hs, type = "l", xlab = "Time", ylab = "Hs (m)") lines(rscd_params$time, rscd_params$hs, col = "red") plot(param_calc$time, param_calc$cge, type = "l", xlab = "Time", ylab = "CgE (kW/m)") lines(rscd_params$time, rscd_params$cge, col = "red") plot(param_calc$time, param_calc$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") plot(param_calc$time, param_calc$dp, type = "l", xlab = "Time", ylab = "Peak direction (°)") lines(rscd_params$time, rscd_params$dp, col = "red") par(oldpar) }
Compute sea_state parameter from wave directional spectrum
compute_sea_state_2d_spectrum(spec, ...)
compute_sea_state_2d_spectrum(spec, ...)
spec |
2D spectrum data, e.g. from |
... |
currently unused |
a tibble with the sea-state parameters computed from the time series of 2D spectrum
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp", "cge", "t01", "dp", "dir") ) spec <- resourcecodedata::rscd_2d_spectra param_calc <- compute_sea_state_2d_spectrum(spec) oldpar <- par(mfcol = c(2, 2)) plot(param_calc$time, param_calc$hs, type = "l", xlab = "Time", ylab = "Hs (m)") lines(rscd_params$time, rscd_params$hs, col = "red") plot(param_calc$time, param_calc$cge, type = "l", xlab = "Time", ylab = "CgE (kW/m)") lines(rscd_params$time, rscd_params$cge, col = "red") plot(param_calc$time, param_calc$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") plot(param_calc$time, param_calc$dp, type = "l", xlab = "Time", ylab = "Dp (°)") lines(rscd_params$time, rscd_params$dp, col = "red") par(oldpar) }
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp", "cge", "t01", "dp", "dir") ) spec <- resourcecodedata::rscd_2d_spectra param_calc <- compute_sea_state_2d_spectrum(spec) oldpar <- par(mfcol = c(2, 2)) plot(param_calc$time, param_calc$hs, type = "l", xlab = "Time", ylab = "Hs (m)") lines(rscd_params$time, rscd_params$hs, col = "red") plot(param_calc$time, param_calc$cge, type = "l", xlab = "Time", ylab = "CgE (kW/m)") lines(rscd_params$time, rscd_params$cge, col = "red") plot(param_calc$time, param_calc$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") plot(param_calc$time, param_calc$dp, type = "l", xlab = "Time", ylab = "Dp (°)") lines(rscd_params$time, rscd_params$dp, col = "red") par(oldpar) }
Converts a 2D spectrum time series to a 1D spectrum
convert_spectrum_2d1d(spec, ...)
convert_spectrum_2d1d(spec, ...)
spec |
a structure with the needed fields, as an output from 'get_2Dspectrum' for example |
... |
unused yet |
a structure comparable to 'get_1Dspectrum'.
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { spec <- resourcecodedata::rscd_2d_spectra spec1D_RSCD <- resourcecodedata::rscd_1d_spectra spec1D <- convert_spectrum_2d1d(spec) # Check the differences, should be low max(abs(spec1D_RSCD$ef - spec1D$ef)) # Plot the different spectrum plot(spec1D$freq, spec1D$ef[, 1], type = "l", log = "xy") lines(spec1D_RSCD$freq, spec1D_RSCD$ef[, 1], col = "red") # Images lims <- c(0, 360) r <- as.POSIXct(round(range(spec1D$forcings$time), "hours")) oldpar <- par(mfcol = c(2, 1)) image(spec1D$forcings$time, spec1D$freq, t(spec1D$th1m), zlim = lims, xlab = "Time", ylab = "Freq (Hz)", xaxt = "n", main = "Directionnal spreading" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 ) image(spec1D_RSCD$forcings$time, spec1D_RSCD$freq, t(spec1D_RSCD$th1m), zlim = lims, xlab = "Time", ylab = "Freq (Hz)", xaxt = "n" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 ) par(oldpar) }
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { spec <- resourcecodedata::rscd_2d_spectra spec1D_RSCD <- resourcecodedata::rscd_1d_spectra spec1D <- convert_spectrum_2d1d(spec) # Check the differences, should be low max(abs(spec1D_RSCD$ef - spec1D$ef)) # Plot the different spectrum plot(spec1D$freq, spec1D$ef[, 1], type = "l", log = "xy") lines(spec1D_RSCD$freq, spec1D_RSCD$ef[, 1], col = "red") # Images lims <- c(0, 360) r <- as.POSIXct(round(range(spec1D$forcings$time), "hours")) oldpar <- par(mfcol = c(2, 1)) image(spec1D$forcings$time, spec1D$freq, t(spec1D$th1m), zlim = lims, xlab = "Time", ylab = "Freq (Hz)", xaxt = "n", main = "Directionnal spreading" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 ) image(spec1D_RSCD$forcings$time, spec1D_RSCD$freq, t(spec1D_RSCD$th1m), zlim = lims, xlab = "Time", ylab = "Freq (Hz)", xaxt = "n" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 ) par(oldpar) }
Compute the dispersion relation of waves Find k s.t. (2.pi.f)^2 = g.k.tanh(k.d)
dispersion(frequencies, depth, iter_max = 200, tol = 1e-06)
dispersion(frequencies, depth, iter_max = 200, tol = 1e-06)
frequencies |
frequency vector |
depth |
depth (m) |
iter_max |
maximum number of iterations in the solver |
tol |
tolerance for termination. |
the wave numbers (same size as frequencies)
freq <- seq(from = 0, to = 1, length.out = 100) k1 <- dispersion(freq, depth = 1) k10 <- dispersion(freq, depth = 10) kInf <- dispersion(freq, depth = Inf) plot(freq, k1, type = "l") lines(freq, k10, col = "red") lines(freq, kInf, col = "green")
freq <- seq(from = 0, to = 1, length.out = 100) k1 <- dispersion(freq, depth = 1) k10 <- dispersion(freq, depth = 10) kInf <- dispersion(freq, depth = Inf) plot(freq, k1, type = "l") lines(freq, k10, col = "red") lines(freq, kInf, col = "green")
Compute the area of a multivariate function with (matrix) values Y at the points x.
fastTrapz(x, Y, dim = 1L)
fastTrapz(x, Y, dim = 1L)
x |
x-coordinates of points on the x-axis (vector) |
Y |
y-coordinates of function values (matrix) |
dim |
an integer giving the subscripts which the function will be applied over. 1 indicates rows, 2 indicates columns |
a vector with one dimension less than Y
x = 1:10 Y = sin(pi/10*matrix(1:10,ncol=10,nrow=10)) fastTrapz(x*pi/10,Y,2)
x = 1:10 Y = sin(pi/10*matrix(1:10,ncol=10,nrow=10)) fastTrapz(x*pi/10,Y,2)
Download the 1D spectrum data from IFREMER ftp
get_1d_spectrum(point, start = "1994-01-01", end = "1994-02-28")
get_1d_spectrum(point, start = "1994-01-01", end = "1994-02-28")
point |
the location name (string) requested. Alternatively, the node number. The consistency is checked internally. |
start |
the starting date (as a string). The consistency is checked internally. |
end |
the ending date as a string |
A list with 12 elements:
Longitude
Latitude
Lower frequency
Upper frequency
Surface elevation variance spectral density
Mean direction from first spectral moment
Mean direction from second spectral moment
Mean directional spreading from first spectral moment
Mean directional spreading from second spectral moment
Central frequency
A data.frame with 14 variables:
Time
Depth, positive downward
Wind intensity, at 10m above sea level
Wind direction, comes from
Current intensity, at the surface
Current direction, going to
Significant wave height
Peak wave frequency
Mean wave frequency
Mean wave frequency at spectral moment minus one
Mean wave direction at spectral peak
Directional spreading at spectral peak
Mean wave direction
Mean directional spreading
Station name
spec1D <- get_1d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-02-28") r <- as.POSIXct(round(range(spec1D$forcings$time), "month")) image(spec1D$forcings$time, spec1D$freq, t(spec1D$ef), xaxt = "n", xlab = "Time", ylab = "Frequency (Hz)" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 )
spec1D <- get_1d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-02-28") r <- as.POSIXct(round(range(spec1D$forcings$time), "month")) image(spec1D$forcings$time, spec1D$freq, t(spec1D$ef), xaxt = "n", xlab = "Time", ylab = "Frequency (Hz)" ) axis.POSIXct(1, spec1D$forcings$time, at = seq(r[1], r[2], by = "week"), format = "%Y-%m-%d", las = 2 )
Download the 2D spectrum data from IFREMER ftp
get_2d_spectrum(point, start = "1994-01-01", end = "1994-02-28")
get_2d_spectrum(point, start = "1994-01-01", end = "1994-02-28")
point |
the location name (string) requested. Alternatively, the node number. The consistency is checked internally. |
start |
the starting date (as a string). The consistency is checked internally. |
end |
the ending date as a string |
A list with 9 elements:
Longitude
Latitude
Lower frequency
Upper frequency
Surface elevation variance spectral density
Mean direction from first spectral moment
Mean direction from second spectral moment
Mean directional spreading from first spectral moment
Mean directional spreading from second spectral moment
Central frequency
Directionnal bins
A data.frame with 6 variables:
Time
Depth, positive downward
Wind intensity, at 10m above sea level
Wind direction, comes from
Current intensity, at the surface
Current direction, going to
Station name
spec2D <- get_2d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-02-28") image(spec2D$dir, spec2D$freq, spec2D$efth[, , 1], xlab = "Direction (°)", ylab = "Frequency (Hz" )
spec2D <- get_2d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-02-28") image(spec2D$dir, spec2D$freq, spec2D$efth[, , 1], xlab = "Direction (°)", ylab = "Frequency (Hz" )
Download time series of sea-state parameters from RESOURCECODE database
get_parameters( parameters = "hs", node = 42, start = as.POSIXct("1994-01-01 00:00:00", tz = "UTC"), end = as.POSIXct("1994-12-31 23:00:00", tz = "UTC") )
get_parameters( parameters = "hs", node = 42, start = as.POSIXct("1994-01-01 00:00:00", tz = "UTC"), end = as.POSIXct("1994-12-31 23:00:00", tz = "UTC") )
parameters |
character vector of sea-state parameters |
node |
single integer with the node to get |
start |
starting date (as integer, character or posixct) |
end |
ending date (as integer, character or posixct) |
a tibble with N-rows and length(parameters)
columns.
ts <- get_parameters(parameters = c("hs", "tp"), node = 42) plot(ts$time, ts$hs, type = "l")
ts <- get_parameters(parameters = c("hs", "tp"), node = 42) plot(ts$time, ts$hs, type = "l")
Creates a JONWSAP density spectrum (one-sided), defined by its integral parameters.
jonswap(hs = 5, tp = 15, fmax = rscd_freq, df = NULL, gam = 3.3)
jonswap(hs = 5, tp = 15, fmax = rscd_freq, df = NULL, gam = 3.3)
hs |
Hs (default: 5m) |
tp |
Period (default: 10s) |
fmax |
higher frequency of the spectrum or vector of frequencies (default to resourcecode frequency vector) |
df |
frequency step (unused if fmax=vector of frequencies) |
gam |
peak enhancement factor (default: 3.3) |
Reference :
O.G.Houmb and T.Overvik, "Parametrization of Wave Spectra and Long Term Joint Distribution of Wave Height and Period," in Proceedings, First International Conference on Behaviour of Offshore Structures (BOSS), Trondheim 1976. 23rd International Towing Tank Conference, vol. II, pp. 544-551
ITTC Committee, 2002, "The Specialist Committee on Waves - Final Report and Recommendations to the 23rd ITTC", Proc. ITTC, vol. II, pp. 505-736.
Density spectrum with corresponding parameters
S1 <- jonswap(tp = 15) S2 <- jonswap(tp = 15, fmax = 0.95, df = 0.003) plot(S1, type = "l", ylim = c(0, 72)) lines(S2, col = "red") abline(v = 1 / 15)
S1 <- jonswap(tp = 15) S2 <- jonswap(tp = 15, fmax = 0.95, df = 0.003) plot(S1, type = "l", ylim = c(0, 72)) lines(S2, col = "red") abline(v = 1 / 15)
Plot a wave density 2D spectrum
plot_2d_specta( spec, time = 1L, normalize = TRUE, trim = 0.01, cut_off = 0.4, ... )
plot_2d_specta( spec, time = 1L, normalize = TRUE, trim = 0.01, cut_off = 0.4, ... )
spec |
the spectral data, as an output from |
time |
the time to plot. Either an integer or the date. |
normalize |
Should the spectrum be normalized to have maimum 1 before ploting |
trim |
removes the values of the spectral density lower than this value |
cut_off |
cut-off frequency above which the spectrum is not plotted |
... |
currently unused |
a ggplot object
spec <- get_2d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-01-31") plot_2d_specta(spec, 1)
spec <- get_2d_spectrum("SEMREVO", start = "1994-01-01", end = "1994-01-31") plot_2d_specta(spec, 1)
(equivalent to a directional resolution of 10°;
rscd_dir
rscd_dir
rscd_dir
An array of length 36 with the directionnal bins
User Manual of the RESOURCECODE database https://archimer.ifremer.fr/doc/00751/86306/
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
rscd_freq
rscd_freq
rscd_freq
An array 36 elements with the frequencies values
User Manual of the RESOURCECODE database https://archimer.ifremer.fr/doc/00751/86306/
Create a map of the provided variable on the RESOURCECODE field grid
rscd_mapplot( z, name = "Depth (m)", zlim = NULL, palette = "YlOrRd", direction = 1, transform = "identity" )
rscd_mapplot( z, name = "Depth (m)", zlim = NULL, palette = "YlOrRd", direction = 1, transform = "identity" )
z |
the data ro plot: a vector of the same size as the grid (328,030 rows). |
name |
name of the variable plored, to be included in the legend. |
zlim |
limits of the scale. See |
palette |
If a string, will use that named palette.
See |
direction |
Sets the order of colours in the scale.
See |
transform |
Transformation to apply to the color scale.
See |
a ggplot2 object
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_mapplot(resourcecodedata::rscd_field$depth) }
# Ensure that data package is available before running the example. # If it is not, see the `resourcecode` package vignette for details # on installing the required data package. if (requireNamespace("resourcecodedata", quietly = TRUE)) { rscd_mapplot(resourcecodedata::rscd_field$depth) }
Converts wind or current zonal and meridional velocity components to magnitude and direction according to meteorological convention.
zmcomp2metconv(u, v = NULL, names = c("wspd", "wdir"))
zmcomp2metconv(u, v = NULL, names = c("wspd", "wdir"))
u |
zonal velocity (1D vector) or matrix with zonal and meridional velocity (Nx2 matrix) |
v |
meridional velocity (1D vector) |
names |
names to construct the resulting data.frame |
a Nx2 data.frame with the norm and direction (meteorological convention)
u <- matrix(rnorm(200), nrow = 100, ncol = 2) vdir <- zmcomp2metconv(u)
u <- matrix(rnorm(200), nrow = 100, ncol = 2) vdir <- zmcomp2metconv(u)