| 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] (ORCID: <https://orcid.org/0000-0003-3385-5104>) |
| Maintainer: | Nicolas Raillard <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.5.4.9000 |
| Built: | 2026-06-06 06:18:16 UTC |
| Source: | https://github.com/Resourcecode-project/r-resourcecode |
Value Matching
x %nin% tablex %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).
semrev_west <- closest_point_field(c(-2.786, 47.239)) semrev_westsemrev_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_westsemrev_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, function(h) { jonswap(h)$spec })) 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), 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, function(h) { jonswap(h)$spec })) 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), 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 1D spectrum
rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp") ) spec <- resourcecodedata::rscd_1d_spectra param_calc <- compute_sea_state_1d_spectrum(spec) oldpar <- par(mfcol = c(2, 1)) 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$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") par(oldpar)rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp") ) spec <- resourcecodedata::rscd_1d_spectra param_calc <- compute_sea_state_1d_spectrum(spec) oldpar <- par(mfcol = c(2, 1)) 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$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, 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
rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp") ) spec <- resourcecodedata::rscd_2d_spectra param_calc <- compute_sea_state_2d_spectrum(spec) oldpar <- par(mfcol = c(2, 1)) 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$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, col = "red") par(oldpar)rscd_params <- get_parameters( node = "134865", start = "1994-01-01", end = "1994-01-31 23:00:00", parameters = c("hs", "tp") ) spec <- resourcecodedata::rscd_2d_spectra param_calc <- compute_sea_state_2d_spectrum(spec) oldpar <- par(mfcol = c(2, 1)) 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$tp, type = "l", xlab = "Time", ylab = "Tp (s)") lines(rscd_params$time, rscd_params$tp, 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'.
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)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)
Cuts direction vector into directional bins
cut_directions(directions, n_bins = 8, labels = NULL)cut_directions(directions, n_bins = 8, labels = NULL)
directions |
vector of directions to be binned, in degree, 0° being the North. |
n_bins |
number of bins, default: 8 sectors. |
labels |
optional character vector giving the sectors names. |
a factor vector the same size as directions with the values binned into sectors.
# Example usage and demonstration set.seed(123) directions <- runif(20, 0, 360) # Test with different numbers of bins cat("Original directions:\n") print(round(directions, 1)) cat("\n8 bins (default):\n") bins_8 <- cut_directions(directions, n_bins = 8) print(bins_8) cat("\n4 bins:\n") bins_4 <- cut_directions(directions, n_bins = 4) print(bins_4)# Example usage and demonstration set.seed(123) directions <- runif(20, 0, 360) # Test with different numbers of bins cat("Original directions:\n") print(round(directions, 1)) cat("\n8 bins (default):\n") bins_8 <- cut_directions(directions, n_bins = 8) print(bins_8) cat("\n4 bins:\n") bins_4 <- cut_directions(directions, n_bins = 4) print(bins_4)
Get season from date time object
cut_seasons( datetime, definition = "meteorological", hemisphere = "northern", labels = NULL )cut_seasons( datetime, definition = "meteorological", hemisphere = "northern", labels = NULL )
datetime |
a POSIXct vector from with the season is constructed |
definition |
the definition used to compute the season. See details section. |
hemisphere |
in the Southern hemisphere, seasons are reversed compared to the Northern one. |
labels |
optional, a character vector of length fours with the seasons' names. |
Available Definitions:
meteorological: Standard seasons (Dec-Feb = Winter, etc.)
astronomical: Based on equinoxes/solstices
djf: Dec-Jan-Feb, Mar-Apr-May, Jun-Jul-Aug, Sep-Oct-Nov
jfm: Jan-Feb-Mar, Apr-May-Jun, Jul-Aug-Sep, Oct-Nov-Dec
fma: Feb-Mar-Apr, May-Jun-Jul, Aug-Sep-Oct, Nov-Dec-Jan
amj, jas, ond: Alternative starting points for quarterly seasons
a Factor vector with 4 levels depending on the definitions (and labels if provided)
dates <- seq( from = as.POSIXct("2023-01-15"), to = as.POSIXct("2023-12-15"), by = "month" ) cut_seasons(dates)dates <- seq( from = as.POSIXct("2023-01-15"), to = as.POSIXct("2023-12-15"), by = "month" ) cut_seasons(dates)
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)
Calculates the fractional day of year from a POSIXct datetime object. The fractional day is zero-indexed, starting at 0 for January 1st at midnight and ending at approximately 365.958 for December 31st at 23:00 in a non-leap year (or 366.958 in a leap year).
fractional_day_of_year(datetime)fractional_day_of_year(datetime)
datetime |
A POSIXct object or vector of POSIXct objects representing date-time values. Must have a timezone attribute. |
The function computes the time difference in hours between the input datetime and midnight on January 1st of the same year, then divides by 24 to obtain fractional days. The calculation accounts for leap years automatically.
A numeric vector of the same length as datetime, containing
fractional day of year values. January 1st at midnight corresponds to 0,
and each hour adds approximately 0.04167 (1/24) to the value.
dates <- seq( from = as.POSIXct("2024-01-01 00:00:00", tz = "UTC"), to = as.POSIXct("2024-01-02 00:00:00", tz = "UTC"), by = "6 hours" ) fractional_day_of_year(dates) # Returns 0.00, 0.25, 0.50, 0.75, 1.00 # End of year dt_end <- as.POSIXct("2024-12-31 23:00:00", tz = "UTC") fractional_day_of_year(dt_end) # Returns ~365.958dates <- seq( from = as.POSIXct("2024-01-01 00:00:00", tz = "UTC"), to = as.POSIXct("2024-01-02 00:00:00", tz = "UTC"), by = "6 hours" ) fractional_day_of_year(dates) # Returns 0.00, 0.25, 0.50, 0.75, 1.00 # End of year dt_end <- as.POSIXct("2024-12-31 23:00:00", tz = "UTC") fractional_day_of_year(dt_end) # Returns ~365.958
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") if(!is.null(spec1D)){ 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") if(!is.null(spec1D)){ 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") if(!is.null(spec2D)){ 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") if(!is.null(spec2D)){ image(spec2D$dir, spec2D$freq, spec2D$efth[, , 1], xlab = "Direction (°)", ylab = "Frequency (Hz" ) }
If the remote resource is unavailable or returns an error, the function returns NULL and emits an informative message.
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.
rscd_data <- get_parameters(parameters = c("hs", "tp"), node = 42) if(!is.null(rscd_data)) plot(rscd_data$time, rscd_data$hs, type = "l")rscd_data <- get_parameters(parameters = c("hs", "tp"), node = 42) if(!is.null(rscd_data)) plot(rscd_data$time, rscd_data$hs, type = "l")
Creates a JONWSAP density spectrum (one-sided), defined by its integral parameters.
jonswap( hs = 5, tp = 15, fmax = resourcecodedata::rscd_freq, df = NULL, gam = 3.3 )jonswap( hs = 5, tp = 15, fmax = resourcecodedata::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)
Function for computing the (weighted) arithmetic mean of directional data in meteorological convention.
mean_direction(directions, weights = NULL)mean_direction(directions, weights = NULL)
directions |
numeric vector of directions, in degree, 0° being the North |
weights |
numeric vector, usually wind speed of wave height. |
The (weighted) mean of the values in directions is computed.
# Test with some wind directions (unweighted) wind_directions <- c(10, 20, 350, 5, 15) # Directions mostly around North mean_dir <- mean_direction(wind_directions) cat("Mean wind direction (unweighted):", round(mean_dir, 1), "degrees\n") wind_directions <- c(350, 10, 20, 340, 30) # Directions around North wind_speeds <- c(15, 5, 2, 12, 3) # Higher speeds for directions closer to North mean_dir_weighted <- mean_direction(wind_directions, wind_speeds) cat("Mean wind direction (weighted):", round(mean_dir_weighted, 1), "degrees\n") # Compare weighted vs unweighted for the same data mean_dir_unweighted <- mean_direction(wind_directions) cat("Same data unweighted:", round(mean_dir_unweighted, 1), "degrees\n")# Test with some wind directions (unweighted) wind_directions <- c(10, 20, 350, 5, 15) # Directions mostly around North mean_dir <- mean_direction(wind_directions) cat("Mean wind direction (unweighted):", round(mean_dir, 1), "degrees\n") wind_directions <- c(350, 10, 20, 340, 30) # Directions around North wind_speeds <- c(15, 5, 2, 12, 3) # Higher speeds for directions closer to North mean_dir_weighted <- mean_direction(wind_directions, wind_speeds) cat("Mean wind direction (weighted):", round(mean_dir_weighted, 1), "degrees\n") # Compare weighted vs unweighted for the same data mean_dir_unweighted <- mean_direction(wind_directions) cat("Same data unweighted:", round(mean_dir_unweighted, 1), "degrees\n")
Converts wind speed (magnitude) and direction (in degrees, meteorological convention: direction from which the wind blows, measured clockwise from north) into zonal (u) and meridional (v) components.
metconv2zmcomp(speed, direction, names = c("uwnd", "vwnd"))metconv2zmcomp(speed, direction, names = c("uwnd", "vwnd"))
speed |
Numeric vector of wind speeds. |
direction |
Numeric vector of wind directions in degrees (0° = from north, 90° = from east, 180° = from south, 270° = from west). |
names |
(optional) ames to construct the resulting data.frame. |
A data.frame with two columns:
Zonal wind component (m/s), positive eastward.
Meridional wind component (m/s), positive northward.
# Example 1: North wind of 10 m/s (blowing southward) metconv2zmcomp(10, 0) # Example 2: East wind of 5 m/s (blowing westward) metconv2zmcomp(5, 90) # Example 3: South wind of 8 m/s (blowing northward) metconv2zmcomp(8, 180)# Example 1: North wind of 10 m/s (blowing southward) metconv2zmcomp(10, 0) # Example 2: East wind of 5 m/s (blowing westward) metconv2zmcomp(5, 90) # Example 3: South wind of 8 m/s (blowing northward) metconv2zmcomp(8, 180)
Plot a wave density 1D spectrum at a given time
plot_1d_specta(spec, time = 1L, print_sea_state = TRUE, ...)plot_1d_specta(spec, time = 1L, print_sea_state = TRUE, ...)
spec |
the spectral data, as an output from |
time |
the time to plot. Either an integer or the date. |
print_sea_state |
should the sea_states parameters being plot ? Default to TRUE. |
... |
currently unused |
a ggplot object
plot_1d_specta(resourcecodedata::rscd_1d_spectra, 1)plot_1d_specta(resourcecodedata::rscd_1d_spectra, 1)
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 maximum 1 before plotting |
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
plot_2d_specta(resourcecodedata::rscd_2d_spectra, 1)plot_2d_specta(resourcecodedata::rscd_2d_spectra, 1)
An extract of the Resourcecode Hindcast database, at node 123456, spanning from 1994-01-01 00:00:00 to 1999-12-31 23:00:00.
rscd_data_examplerscd_data_example
POSIXct. Timestamp in UTC (hourly resolution).
numeric. Significant wave height (m).
numeric. Peak wave period (s).
numeric. Mean wave direction (degrees, coming from true North, clockwise).
numeric. Zonal (east–west) component of the 10-m wind (m/s). Positive eastward.
numeric. Meridional (north–south) component of the 10-m wind (m/s). Positive northward.
numeric.Depth (m).
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
rscd_mapplot(resourcecodedata::rscd_field$depth)rscd_mapplot(resourcecodedata::rscd_field$depth)
Computes and returns start date of each weather window, implemented in C++ for speed.
weather_windows( valid_periods, window_length, allow_overlap = TRUE, time_step = 3600 )weather_windows( valid_periods, window_length, allow_overlap = TRUE, time_step = 3600 )
valid_periods |
A data frame with a 'time' column (POSIXct). |
window_length |
Minimum window duration (hours). |
allow_overlap |
Logical; If TRUE, the algorithm searches for window, if a window is found, search of next window will start from the end of the previous window. If FALSE, it uses continuous window search: The algorithm searches for window starting from every time step that meets the criteria. |
time_step |
Expected time step between consecutive timestamps (seconds). |
POSIXct vector of detected window start times.
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)