Package 'rWind'

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

Help Index


Download, edit and include wind and sea currents data in ecological and evolutionary analysis

Description

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.

Details

The complete list of functions can be displayed with library(help = rWind). For more information, please check: https://allthiswasfield.blogspot.com/.

Author(s)

Javier Fernández-López

Klaus Schliep

Yurena Arjona

Maintainer: Javier Fernández-López [email protected]

See Also

Useful links:


Arrow direction fitting for Arrowhead function from "shape" package

Description

arrowDir adapts wind direction value to be used by Arrowhead function from "shape" package to plot wind direction for each coordinate.

Usage

arrowDir(W)

Arguments

W

An object of class rWind or a data.frame which should content a column named "dir".

Details

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.

Value

A vector with angles for each arrow to be plotted by Arrowhead.

Note

arrowDir function works always together with Arrowhead function from "shape" package.

Author(s)

Javier Fernández-López

References

Karline Soetaert (2017). shape: Functions for Plotting Graphical Shapes, Colors. R package version 1.4.3. https://CRAN.R-project.org/package=shape

See Also

wind.dl

Examples

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)

Relative cost of active movement through a flow

Description

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.

Usage

cost.active(flow.direction, flow.speed, target, speed.scale = NULL)

Arguments

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.

Details

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).

Value

Relative movement cost. A value below one indicates support and a value above one indicates opposition.


Compute flow-based cost or conductance

Description

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):

Usage

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,
  ...
)

Arguments

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 "passive" mode, deviations of 90 degrees or more from the flow direction are forbidden. In "active" mode, supportive flow lowers relative cost and opposing flow raises it; movement against the flow remains possible.

speed.scale

Positive reference speed for the active model. If NULL, the median positive speed of the complete raster layer is used. For comparisons among dates or regions, supply one fixed value in the same units as wind.speed.

x

A SpatRaster returned by wind2raster() with direction and speed layers, a legacy RasterStack, or a list of either type.

fun

A function to compute the cost to move between cells. The default is cost.FMGS from Felicísimo et al. (2008), see details.

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.

Details

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.

Value

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).

Note

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.

Author(s)

Javier Fernández-López; Klaus Schliep; Yurena Arjona

References

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

See Also

wind.dl, wind2raster

Examples

require(gdistance)

data(wind.data)

wind <- wind2raster(wind.data)

Conductance <- flow.dispersion(wind, type = "passive")

transitionMatrix(Conductance)
image(transitionMatrix(Conductance))

OSCAR Sea currents data download

Description

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.

Usage

seaOscar.dl(
  yyyy,
  mm,
  dd,
  lon1,
  lon2,
  lat1,
  lat2,
  type = "read-data",
  trace = 1
)

Arguments

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

Details

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.

Value

"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.

Author(s)

Javier Fernández-López ([email protected])

References

doi:10.5067/OSCAR-03D01

See Also

wind.dl_2, wind2raster

Examples

# Download sea currents for Galapagos Islands
## Not run: 

seaOscar.dl(2015, 1, 1, -93, -88, 2, -3)

## End(Not run)

Transforming a rWind_series object into a data.frame

Description

The output of tidy is always a data.frame. It is therefore suited for further manipulation by packages like dplyr, reshape2, ggplot2 and ggvis.

Usage

tidy(x, ...)

## S3 method for class 'rWind_series'
tidy(x, ...)

Arguments

x

An object to be converted into a tidy data.frame

...

extra arguments

Examples

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

Description

Transform U and V components in direction and speed and vice versa

Usage

uv2ds(u, v)

ds2uv(d, s)

Arguments

u

U component.

v

U component.

d

direction (degrees).

s

speed (m/s).

Value

"uv2ds" returns a matrix with direction and speed values

"ds2uv" returns a matrix with U and V values

Note

Multiple U and V values can be processed. "dir" denotes where the wind/sea current is going (toward), not from where is coming.

Author(s)

Javier Fernández-López ([email protected])

See Also

wind.mean, wind2raster

Examples

(ds <- uv2ds(c(1, 1, 3, 1), c(1, 1.7, 3, 1)))
ds2uv(ds[, 1], ds[, 2])

Wind data example

Description

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)

Format

A list with one data.frame with 651 observations on the following 7 variables:

list("time (UTC)")

a numeric with selected time of wind data

list("latitude (degrees_north)")

a numeric with latitude values

list("longitude (degrees_east)")

a numeric with longitude values

list("ugrd10m (m s-1)")

a numeric with U component of wind data

list("vgrd10m (m s-1)")

a numeric with V component of wind data

list("dir")

a numeric with direction of wind data

list("speed")

a numeric with speed of wind data

Details

This data set is the result of:

wind.data <- wind.dl(2015,2,12,0,-10,5,35,45)

Source

https://allthiswasfield.blogspot.com/2016/12/rwind-r-package-released.html

References

https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast

Examples

data(wind.data)
str(wind.data)
head(wind.data[[1]])

Wind-data download

Description

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

Usage

wind.dl(
  yyyy,
  mm,
  dd,
  tt,
  lon1,
  lon2,
  lat1,
  lat2,
  type = "read-data",
  trace = 1,
  source = c("auto", "pacioos", "ncei")
)

read.rWind(file)

Arguments

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. "auto" selects PacIOOS for dates in its current coverage and NOAA/NCEI for older dates. Use "pacioos" or "ncei" to force one provider.

file

file name of the saved ".csv" files.

Details

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.

Value

"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.

Note

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.

Author(s)

Javier Fernández-López ([email protected])

References

http://www.digital-geography.com/cloud-gis-getting-weather-data/#.WDOWmbV1DCL

https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.graph

See Also

wind.dl_2, wind2raster

Examples

# 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-data download

Description

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.

Usage

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]]

Arguments

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. "auto" selects PacIOOS for dates in its current coverage and NOAA/NCEI for older dates. Use "pacioos" or "ncei" to force one provider.

x

object from which to extract element(s).

i

indices specifying elements to extract.

exact

Controls possible partial matching (not used yet).

Details

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.

Value

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.

Note

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.

Author(s)

Javier Fernández-López ([email protected])

References

http://www.digital-geography.com/cloud-gis-getting-weather-data/#.WDOWmbV1DCL

https://pae-paha.pacioos.hawaii.edu/erddap/griddap/ncep_global.graph

See Also

wind.mean, wind2raster, wind.dl, as_datetime, as.POSIXct

Examples

# 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-data mean

Description

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.

Usage

wind.mean(x)

Arguments

x

An object of class rWind_series

Value

An object of class rWind, which is a data.frame

Note

For large time series, it could take a while.

Author(s)

Javier Fernández-López ([email protected])

References

https://en.wikipedia.org/wiki/Cross_product

See Also

wind.dl

Examples

data(wind.series)
wind_average <- wind.mean(wind.series)

Wind series example

Description

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)

Format

The format is an rWind list of 8 data.frame. Each data.frame contain 961 observations on the following 7 variables:

list("time (UTC)")

a factor with selected time of wind data

list("latitude (degrees_north)")

a factor with latitude values

list("longitude (degrees_east)")

a factor with longitude values

list("ugrd10m (m s-1)")

a factor with U component of wind data

list("vgrd10m (m s-1)")

a factor with V component of wind data

list("dir")

a numeric with direction of wind data

list("speed")

a numeric with speed of wind data

Details

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)

Source

https://allthiswasfield.blogspot.com/2016/12/rwind-r-package-released.html

References

https://www.ncei.noaa.gov/products/weather-climate-models/global-forecast

Examples

data(wind.series)
str(tidy(wind.series))

Wind data to terra rasters

Description

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).

Usage

wind2raster(x)

Arguments

x

An object of class rWind or rWind_series.

Value

A terra::SpatRaster, or a list of them, with layers direction and speed.

Author(s)

Javier Fernández-López ([email protected])

See Also

wind.dl

Examples

data(wind.data)

# Create a SpatRaster with wind direction and speed layers

wind2raster(wind.data)