title: "eddies: Package usage example" author: "Yves Le Bras" date: "r Sys.Date()" output: knitr:::html_vignette vignette: > %\VignetteIndexEntry{Package usage example} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}


# Intro

The eddies package allow to acess to an eddy database of matlab data files downloaded form http://datadryad.org/resource/doi:10.5061/dryad.gp40h/1.

In the southern ocean, cyclonic eddies contain a cold core and rotate in clockwise direction.

# Example

```r knitr::opts_chunk$set(fig.dpi = 96)

```r
require("rbl")
require("eddies")

ses <- readRDS("F:/data/ses/post_repro/rbl/large_acc/2011-28.rds")
ses$stat$day <- floorPOSIXct(ses$stat$time)

# Setup temporal subset
days <- seq(
  from = as.POSIXct("2011-11-25", tz = "UTC"), 
  to = as.POSIXct("2011-12-12", tz = "UTC"), 
  by = "day"
)

# Before using the package make sure that the database path is correct
# Consider setting this option in your .Rprofile if it is not the case
options("eddies.path")

# Setup geographical subset (Optional)
# options("eddies.area") <- list(
#   lon = range(ses$stat$lon), 
#   lat = range(ses$stat$lat)
#   )
# Here we will use defaults
options("eddies.area")

# Extract matching eddies from the database
edd <- eddies(days)

Here is an example of the result

names(edd) # See description of these variables in ?eddies

cnd <- ses$stat$day %in% days
plot(lat ~ lon, ses$stat[cnd, ], type = "n")
plot(edd, add = TRUE, col = c(cyc = "blue", anticyc = "red"))
lines(lat ~ lon, ses$stat[cnd, ], lwd = 2)

The distance to the edge of the closest eddy can be extracted as follows:

# Pre-allocate columns to target data frame
edd_nms <- c(
  "edd.dist",          # Distance to the edge of the closest eddy
  "no_eddy",           # ID number of the closest eddy
  "edd.Cyc",           # Type of eddy (-1: cyclonic, 1 anticyclonic)
  "edd.Lon", "edd.Lat" # Coordinates of eddy's center
)
ses$stat[ , edd_nms] <- as.list(rep(NA, length(edd_nms)))

for (d in days) {
  # Get seal locations at this date
  cnd <- with(ses$stat, as.numeric(ses$stat$day) == d & !is.na(lon) & !is.na(lat))
  sum(cnd) > 0 || next
  locs <- as.data.frame(ses$stat[cnd, c("lon", "lat")])

  # Get eddies locations at this date
  edd_dte <- eddies(as.POSIXct(d, origin = "1970-01-01"))
  ses$stat[cnd, edd_nms] <- match_track2eddies(edd, locs, n = 30)[ , edd_nms]
}

# Result preview
cnd <- ses$stat$day %in% days
plot(lat ~ lon, ses$stat[cnd, ], type = "n")
plot(edd, add = TRUE, col = c(cyc = "blue", anticyc = "red"))
# To transform distance in [0, +Inf[ to point size in ]0; 1[
scinvlogit <- function(x) 1 / (1 + exp(-scale(x)))
points(lat ~ lon, ses$stat[cnd, ], pch = 20, cex = scinvlogit(-edd.dist))

Reference

Faghmous JH, Frenger I, Yao Y, Warmka R, Lindell A, Kumar V (2015) A daily global mesoscale ocean eddy dataset from satellite altimetry. Scientific Data 2: 150028. http://dx.doi.org/10.1038/sdata.2015.28

Faghmous JH, Frenger I, Yao Y, Warmka R, Lindell A, Kumar V (2015) Data from: A daily global mesoscale ocean eddy dataset from satellite altimetry. Dryad Digital Repository. http://dx.doi.org/10.5061/dryad.gp40h



SESman/eddies documentation built on May 9, 2019, 11:10 a.m.