| Title: | Download, Edit and Include Wind and Sea Currents Data in Ecological and Evolutionary Analysis |
|---|---|
| Description: | Tools to download and manage surface wind and sea-current data from the Global Forecast System <https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast> and to compute flow-sensitive connectivity between locations. |
| Authors: | Javier Fernández-López [aut, cre], Klaus Schliep [aut], Yurena Arjona [aut] |
| Maintainer: | Javier Fernández-López <[email protected]> |
| License: | GPL (>=3) |
| Version: | 1.2.0 |
| Built: | 2026-10-19 10:15:44 UTC |
| Source: | https://github.com/jabiologo/rwind |
rWind contains tools for downloading, editing and transforming wind and sea currents data from the Global Forecast System (GFS) and Ocean Surface Current Analyses Real-time (OSCAR). It also allows wind and sea currents data to be used to compute minimum-cost paths from flow speed and direction and to perform connectivity analysis.
The complete list of functions can be displayed with library(help =
rWind). For more information, please check:
https://allthiswasfield.blogspot.com/.
Javier Fernández-López
Klaus Schliep
Yurena Arjona
Maintainer: Javier Fernández-López [email protected]
Useful links:
Report bugs at https://github.com/jabiologo/rWind/issues
arrowDir adapts wind direction value to be used by Arrowhead function from "shape" package to plot wind direction for each coordinate.
arrowDir(W)arrowDir(W)
W |
An object of class |
Angle argument of Arrowhead function from "shape" package needs to be fed in an anti-clockwise way, relative to x-axis, in degrees 0,360. arrowDir function adapts wind direction provided by wind.fit (clockwise, relative to y-axis ) to requirements of Arrowhead.
A vector with angles for each arrow to be plotted by Arrowhead.
arrowDir function works always together with Arrowhead function from "shape" package.
Javier Fernández-López
Karline Soetaert (2017). shape: Functions for Plotting Graphical Shapes, Colors. R package version 1.4.3. https://CRAN.R-project.org/package=shape
data(wind.data) # Create a vector with wind direction (angles) adapted alpha <- arrowDir(wind.data) ## Not run: # Now, you can plot wind direction with Arrowhead function from shapes package # Load "shape package require(shape) plot(wind.data$lon, wind.data$lat, type = "n") Arrowhead(wind.data$lon, wind.data$lat, angle = alpha, arr.length = 0.1, arr.type = "curved" ) ## End(Not run)data(wind.data) # Create a vector with wind direction (angles) adapted alpha <- arrowDir(wind.data) ## Not run: # Now, you can plot wind direction with Arrowhead function from shapes package # Load "shape package require(shape) plot(wind.data$lon, wind.data$lat, type = "n") Arrowhead(wind.data$lon, wind.data$lat, angle = alpha, arr.length = 0.1, arr.type = "curved" ) ## End(Not run)
cost.active() is a deliberately simple, general index based on signed flow
support. The flow component parallel to movement is speed * cos(angle).
Supportive flow lowers cost, opposing flow raises it, and perpendicular flow
has no effect. This is a relative index, not physical travel time or energy.
cost.active(flow.direction, flow.speed, target, speed.scale = NULL)cost.active(flow.direction, flow.speed, target, speed.scale = NULL)
flow.direction |
Flow direction in degrees, pointing towards where the flow moves. |
flow.speed |
Non-negative flow speed. |
target |
Movement direction in degrees. |
speed.scale |
Positive reference speed used to make flow support dimensionless. By default, the median positive input speed is used. |
Let z = speed * cos(angle) / speed.scale. When z >= 0, cost is
1 / (1 + z); when z < 0, cost is 1 - z. Thus support equal to the
reference speed halves cost, opposition equal to the reference speed doubles
it, and cost(-z) = 1 / cost(z).
Relative movement cost. A value below one indicates support and a value above one indicates opposition.
flow.dispersion computes movement conductance through a flow such as
sea or wind currents. Passive movement uses a restricted version of the
formula described in Felícisimo et al. (2008):
cost.FMGS( wind.direction, wind.speed, target, type = c("passive", "active"), speed.scale = NULL ) flow.dispersion( x, fun = cost.FMGS, output = "transitionLayer", type = c("passive", "active"), speed.scale = NULL, ... )cost.FMGS( wind.direction, wind.speed, target, type = c("passive", "active"), speed.scale = NULL ) flow.dispersion( x, fun = cost.FMGS, output = "transitionLayer", type = c("passive", "active"), speed.scale = NULL, ... )
wind.direction |
A vector or scalar containing wind directions. |
wind.speed |
A vector or scalar containing wind speeds. |
target |
direction of the target cell |
type |
Movement model. In |
speed.scale |
Positive reference speed for the active model. If |
x |
A |
fun |
A function to compute the cost to move between cells. The default
is |
output |
This argument allows to select different kinds of output. "raw" mode creates a matrix (class "dgCMatrix") with transition costs between all cells in the raster. "transitionLayer" creates a TransitionLayer object with conductance values to be used with "gdistance" package. |
... |
Further arguments passed to or from other methods. |
Cost=(1/Speed)*(HorizontalFactor)
where HorizontalFactor incrementally penalizes angular deviations from the flow direction and prevents passive movement at deviations of 90 degrees or more. Active movement uses a general relative index based on signed flow support rather than the original formula.
In "transitionLayer" output, the function returns conductance values (1/cost)to move between all cells in a raster having into account flow speed and direction obtained from wind.fit function("rWind" package). As wind or sea currents implies directionality, flow.dispersion produces an anisotropic conductance matrix (asymmetric). Conductance values are used later to built a TransitionLayer object from "gdistance" package.
In "raw" output, flow.dispersion creates a sparse Matrix with cost values.
Each edge cost is the mean of the local costs at its origin and destination.
Diagonal edges are multiplied by sqrt(2).
The active model is a relative connectivity index, not a mechanistic model of animal movement. It ignores the component of flow perpendicular to movement.
Costs are relative per grid step. The diagonal correction assumes a square grid, but no correction is made for the changing physical distances of longitude/latitude cells. Do not interpret results as physical time, energy, or distance or compare them directly across grid resolutions or distant latitude ranges.
Note that for large data sets, it could take a while. For large study areas is strongly advised perform the analysis in a remote computer or a cluster.
Javier Fernández-López; Klaus Schliep; Yurena Arjona
Felicísimo, Á. M., Muñoz, J., & González-Solis, J. (2008). Ocean surface winds drive dynamics of transoceanic aerial movements. PLoS One, 3(8), e2928.
Jacob van Etten (2017). R Package gdistance: Distances and Routes on Geographical Grids. Journal of Statistical Software, 76(13), 1-21. doi:10.18637/jss.v076.i13
require(gdistance) data(wind.data) wind <- wind2raster(wind.data) Conductance <- flow.dispersion(wind, type = "passive") transitionMatrix(Conductance) image(transitionMatrix(Conductance))require(gdistance) data(wind.data) wind <- wind2raster(wind.data) Conductance <- flow.dispersion(wind, type = "passive") transitionMatrix(Conductance) image(transitionMatrix(Conductance))
seaOscar.dl downloads sea currents data from the Ocean Surface Current Analyses Real-time (OSCAR) (PO.DAAC, doi:10.5067/OSCAR-03D01). Geospatial resolution is 0.33 degrees and sea currents are calculated for 15 m depth. Longitudes in the usual -180 to 180 notation are translated to the 20 to 420 degree axis used by the service.
seaOscar.dl( yyyy, mm, dd, lon1, lon2, lat1, lat2, type = "read-data", trace = 1 )seaOscar.dl( yyyy, mm, dd, lon1, lon2, lat1, lat2, type = "read-data", trace = 1 )
yyyy |
Selected year. |
mm |
Selected month. |
dd |
Selected day. |
lon1 |
Western longitude |
lon2 |
Eastern longitude |
lat1 |
Northern latitude |
lat2 |
Southern latitude |
type |
Output type. "read-data" is selected by default, creating an R object. If you choose "csv", seaOscar.dl create a a CSV file in your working directory named "oscar_yyyy_mm_dd.csv". |
trace |
if trace = 1 (by default) track downloaded files |
The output type is determined by type="csv" or type="read-data". If type="csv" is selected, the function creates a "sea_yyyy_mm_dd.csv" file that is downloaded at the work directory. If type="read-data" is selected, an R object (data.frame) is created.
"rWind" and "data.frame" class object or .csv file with U and V vector components and sea current direction and speed for each coordinate in the study area defined by lon1/lon2 and lat1/lat2.
Javier Fernández-López ([email protected])
# Download sea currents for Galapagos Islands ## Not run: seaOscar.dl(2015, 1, 1, -93, -88, 2, -3) ## End(Not run)# Download sea currents for Galapagos Islands ## Not run: seaOscar.dl(2015, 1, 1, -93, -88, 2, -3) ## End(Not run)
The output of tidy is always a data.frame. It is therefore suited for further manipulation by packages like dplyr, reshape2, ggplot2 and ggvis.
tidy(x, ...) ## S3 method for class 'rWind_series' tidy(x, ...)tidy(x, ...) ## S3 method for class 'rWind_series' tidy(x, ...)
x |
An object to be converted into a tidy data.frame |
... |
extra arguments |
data(wind.series) df <- tidy(wind.series) head(df) ## Not run: # use the tidyverse library(dplyr) mean_speed <- tidy(wind.series) %>% group_by(lat, lon) %>% summarise(speed = mean(speed)) wind_average2 <- wind.mean(wind.series) all.equal(wind_average2$speed, mean_speed$speed) ## End(Not run)data(wind.series) df <- tidy(wind.series) head(df) ## Not run: # use the tidyverse library(dplyr) mean_speed <- tidy(wind.series) %>% group_by(lat, lon) %>% summarise(speed = mean(speed)) wind_average2 <- wind.mean(wind.series) all.equal(wind_average2$speed, mean_speed$speed) ## End(Not run)
Transform U and V components in direction and speed and vice versa
uv2ds(u, v) ds2uv(d, s)uv2ds(u, v) ds2uv(d, s)
u |
U component. |
v |
U component. |
d |
direction (degrees). |
s |
speed (m/s). |
"uv2ds" returns a matrix with direction and speed values
"ds2uv" returns a matrix with U and V values
Multiple U and V values can be processed. "dir" denotes where the wind/sea current is going (toward), not from where is coming.
Javier Fernández-López ([email protected])
(ds <- uv2ds(c(1, 1, 3, 1), c(1, 1.7, 3, 1))) ds2uv(ds[, 1], ds[, 2])(ds <- uv2ds(c(1, 1, 3, 1), c(1, 1.7, 3, 1))) ds2uv(ds[, 1], ds[, 2])
This is an example of wind data obtained with wind.dl function for the Iberian Peninsula coordinates on 12/February/2015 at 00:00 (UTC)
A list with one data.frame with 651 observations on the following 7 variables:
a numeric with selected time of wind data
a numeric with latitude values
a numeric with longitude values
a numeric with U component of wind data
a numeric with V component of wind data
a numeric with direction of wind data
a numeric with speed of wind data
This data set is the result of:
wind.data <- wind.dl(2015,2,12,0,-10,5,35,45)
https://allthiswasfield.blogspot.com/2016/12/rwind-r-package-released.html
https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast
data(wind.data) str(wind.data) head(wind.data[[1]])data(wind.data) str(wind.data) head(wind.data[[1]])
wind.dl downloads wind data from the Global Forecast System (GFS) of the USA's National Weather Service (NWS) (https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast). Wind data are taken from NOAA/NCEP Global Forecast System (GFS) Atmospheric Model collection. Geospatial resolution is 0.5 degrees (approximately 50 km), and wind is calculated for Earth surface, at 10 m. More metadata information for the current PacIOOS data: https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.graph Historical data are obtained from the official NOAA/NCEI GFS 0.5 degree archive: https://www.ncei.noaa.gov/access/metadata/landing-page/bin/iso?id=gov.noaa.ncdc:C00634
wind.dl( yyyy, mm, dd, tt, lon1, lon2, lat1, lat2, type = "read-data", trace = 1, source = c("auto", "pacioos", "ncei") ) read.rWind(file)wind.dl( yyyy, mm, dd, tt, lon1, lon2, lat1, lat2, type = "read-data", trace = 1, source = c("auto", "pacioos", "ncei") ) read.rWind(file)
yyyy |
Selected year. |
mm |
Selected month. |
dd |
Selected day. |
tt |
Selected time. There are currently several options at the GFS database: 00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00 (UTC). |
lon1 |
Western longitude |
lon2 |
Eastern longitude |
lat1 |
Southern latitude |
lat2 |
Northern latitude |
type |
Output type. "read-data" is selected by default, creating an R object. If you choose "csv", wind.dl create a a CSV file in your working directory named "wind_yyyy_mm_dd_tt.csv". |
trace |
if trace = 1 (by default) track downloaded files |
source |
Data provider. |
file |
file name of the saved ".csv" files. |
The output type is determined by type="csv" or type="read-data". If type="csv" is selected, the function creates a "wind_yyyy_mm_dd_tt.csv" file that is downloaded at the work directory. If type="read-data" is selected, an R object (data.frame) is created.
"rWind" and "data.frame" class object or .csv file with U and V vector components and wind direction and speed for each coordinate in the study area defined by lon1/lon2 and lat1/lat2.
Longitude coordinate are provided by GFS dataset in 0/360 notation
and transformed internally into -180/180. Wind "dir" denotes where the
wind is going (toward), not from where is coming. With source = "auto",
dates before the current PacIOOS coverage are requested from NOAA/NCEI.
Javier Fernández-López ([email protected])
http://www.digital-geography.com/cloud-gis-getting-weather-data/#.WDOWmbV1DCL
https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.graph
# Download wind for Iberian Peninsula region at 2015, February 12, 00:00 ## Not run: wind.dl(2015, 2, 12, 0, -10, 5, 35, 45) ## End(Not run)# Download wind for Iberian Peninsula region at 2015, February 12, 00:00 ## Not run: wind.dl(2015, 2, 12, 0, -10, 5, 35, 45) ## End(Not run)
wind.dl_2 downloads time-series wind data from the Global Forecast System (GFS) of the USA's National Weather Service (NWS) (https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast). Wind data are taken from NOAA/NCEP Global Forecast System (GFS) Atmospheric Model collection. Geospatial resolution is 0.5 degrees (approximately 50 km), and wind is calculated for Earth surface, at 10 m. More metadata information for current data: https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.html Historical data are obtained from the official NOAA/NCEI GFS 0.5 degree archive.
wind.dl_2( time, lon1, lon2, lat1, lat2, type = "read-data", trace = 1, source = c("auto", "pacioos", "ncei") ) ## S3 method for class 'rWind_series' x[[i, exact = TRUE]]wind.dl_2( time, lon1, lon2, lat1, lat2, type = "read-data", trace = 1, source = c("auto", "pacioos", "ncei") ) ## S3 method for class 'rWind_series' x[[i, exact = TRUE]]
time |
a scalar or vector of POSIXt or Date objects or an character which can transformed into those, see example below. There are currently these options at the GFS database for the hours: 00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00 (UTC) (TO). |
lon1 |
Western longitude |
lon2 |
Eastern longitude |
lat1 |
Southern latitude |
lat2 |
Northern latitude |
type |
Output type. "read-data" is selected by default, creating an R object. If you choose "csv", wind.dl create a a CSV file in your work directory named "wind_yyyy_mm_dd_tt.csv". |
trace |
if trace = 1 (by default) track downloaded files |
source |
Data provider. |
x |
object from which to extract element(s). |
i |
indices specifying elements to extract. |
exact |
Controls possible partial matching (not used yet). |
To get the same format as wind.dl, you should run tidy function from
wind.dl_2 output.
The output type is determined by type="csv" or type="read-data". If
type="csv" is selected, the function creates a "wind_yyyy_mm_dd_tt.csv" file
that is downloaded at the work directory. If type="read-data" is selected,
an rWind_series object is created.
an object of class rWind_series or .csv file/s with
U and V vector components and wind direction and speed for each coordinate
in the study area defined by lon1/lon2 and lat1/lat2.
wind.dl_2 requires two dates that represent the boundaries of the time
lapse to download wind series data.
U and V vector components allow you to create wind averages or tendencies
for each coordinate at the study area. Longitude coordinates are
provided by GFS dataset in 0/360 notation and transformed internally into
-180/180. "dir" denotes where the
wind/sea current is going (toward), not from where is coming. With
source = "auto", dates before the current PacIOOS coverage are requested
from NOAA/NCEI.
Javier Fernández-López ([email protected])
http://www.digital-geography.com/cloud-gis-getting-weather-data/#.WDOWmbV1DCL
https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.graph
wind.mean, wind2raster,
wind.dl, as_datetime,
as.POSIXct
# Download wind for Iberian Peninsula region at 2015, February 12, 00:00 ## Not run: wind.dl_2("2018/3/15 9:00:00", -10, 5, 35, 45) library(lubridate) dt <- seq(ymd_hms(paste(2018, 1, 1, 00, 00, 00, sep = "-")), ymd_hms(paste(2018, 1, 2, 21, 00, 00, sep = "-")), by = "3 hours" ) ww <- wind.dl_2(dt, -10, 5, 35, 45) tidy(ww) ## End(Not run)# Download wind for Iberian Peninsula region at 2015, February 12, 00:00 ## Not run: wind.dl_2("2018/3/15 9:00:00", -10, 5, 35, 45) library(lubridate) dt <- seq(ymd_hms(paste(2018, 1, 1, 00, 00, 00, sep = "-")), ymd_hms(paste(2018, 1, 2, 21, 00, 00, sep = "-")), by = "3 hours" ) ww <- wind.dl_2(dt, -10, 5, 35, 45) tidy(ww) ## End(Not run)
wind.mean computes the mean (average) wind speed and wind direction of a time series dataset of winds of the same region. Summaries of time series are not trivial to compute. We compute the arithmetic mean for the wind speed. The direction as the circular mean, see https://en.wikipedia.org/wiki/Circular_mean for more details. The U and V components are afterwards transformed from these values.
wind.mean(x)wind.mean(x)
x |
An object of class |
An object of class rWind, which is a data.frame
For large time series, it could take a while.
Javier Fernández-López ([email protected])
https://en.wikipedia.org/wiki/Cross_product
data(wind.series) wind_average <- wind.mean(wind.series)data(wind.series) wind_average <- wind.mean(wind.series)
This is an example of a wind series data obtained with wind.dl function for New Zealand area on 3/January/2015 at all the available times: 00:00 - 03:00 - 06:00 - 09:00 - 12:00 - 15:00 - 18:00 - 21:00 (UTC)
The format is an rWind list of 8 data.frame. Each data.frame contain 961 observations on the following 7 variables:
a factor with selected time of wind data
a factor with latitude values
a factor with longitude values
a factor with U component of wind data
a factor with V component of wind data
a numeric with direction of wind data
a numeric with speed of wind data
This data set is the result of:
library(lubridate)
dt <- seq(ymd_h(paste(2015,1,3,00, sep="-")),
ymd_h(paste(2015,1,3,21, sep="-")),by="3 hours")
wind.series <- wind.dl_2(dt, 164, 179, -48, -33)
https://allthiswasfield.blogspot.com/2016/12/rwind-r-package-released.html
https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast
data(wind.series) str(tidy(wind.series))data(wind.series) str(tidy(wind.series))
wind2raster() converts an rWind object to a two-layer
terra::SpatRaster containing wind direction and speed. An
rWind_series is converted to a list of SpatRaster objects, one per time
step. All outputs use WGS 84 (EPSG:4326).
wind2raster(x)wind2raster(x)
x |
An object of class |
A terra::SpatRaster, or a list of them, with layers direction
and speed.
Javier Fernández-López ([email protected])
data(wind.data) # Create a SpatRaster with wind direction and speed layers wind2raster(wind.data)data(wind.data) # Create a SpatRaster with wind direction and speed layers wind2raster(wind.data)