Glider temperature

## =============================================================================
## The glider data, using traditional R-graphics
## implemented by Karline Soetaert
## =============================================================================
require(OceanView)

# ------------------------------------------------------------------------------
# The bathymetry has been downloaded as nc (netCDF) file from 
# http://coastwatch.pfeg.noaa.gov/erddap/griddap/usgsCeSrtm30v6.html
# ------------------------------------------------------------------------------
#url <- "http://coastwatch.pfeg.noaa.gov/erddap/griddap/usgsCeSrtm30v6/usgsCeSrtm30v6_6ebb_eec1_d277.nc"
url <- "http://gliders.oceantrack.org"
require(RNetCDF)
Nc <- open.nc("usgsCeSrtm30v6_6ebb_eec1_d277.nc")
# print.nc(Nc)
lat <- var.get.nc(Nc, "latitude")
lon <- var.get.nc(Nc, "longitude")
topo <- depth <- var.get.nc(Nc, "topo")
depth[depth > 0] <- NA

par (mfrow = c(2, 2), oma = c(3, 0, 0, 0))
image2D(lon, lat, z = depth, ylim = c(42, 45),
  col = "white", contour = TRUE )

# ------------------------------------------------------------------------------
# The glider input files are downloaded only if they are not yet available
# The R-command list.files() creates a list of all files in the directory
# ------------------------------------------------------------------------------

Listfiles <- list.files()

# The external directory and name of the files that we want to import:
Directory <- "http://gliders.oceantrack.org/data/live/"
Files <- c("otn200_sci_water_temp_live.csv", "otn200_sci_water_sal_live.csv")

for (Tempfile in Files)
  if (!Tempfile %in% Listfiles) 
 # Downloading file - put on local directory  
  download.file(url = paste(Directory, Tempfile, sep = ""), 
      destfile = Tempfile, method = "auto", quiet = FALSE, 
      mode = "wb", cacheOK = TRUE)

# The csv file is read and its initial content shown
temp <- read.csv("otn200_sci_water_temp_live.csv")
head(temp)

scatter2D(temp$lon, temp$lat, colvar = (temp$unixtime - temp$unixtime[1])/3600, 
  pch = ".", cex = 3, clab = "time", add = TRUE, colkey = list(dist = 0.1))

# perspective plot
pm <- par(mar = c(0,0,2,2))
scatter3D(temp$lon, temp$lat, -temp$depth, colvar = temp$sci_water_temp, 
  pch = ".", cex = 3, theta = 10, bty = "f", clab = "dg C", 
  colkey = list(side = 1, length = 0.5, dist = -0.1))

# the distance to first point
require(marelac)
alat <- temp[1, "lat"]
alon <- temp[1, "lon"]
temp$distance <- earth_dist(alat, alon, temp$lat, temp$lon)

# First part of transect
turnpoint <- which.max(temp$distance)
Temp <- temp[1:turnpoint,]

par(mar = pm)
scatter2D(Temp$distance, Temp$depth, colvar = Temp$sci_water_temp, 
  pch = ".", cex = 5, colkey = list(width = 0.5, length = 0.5),
  ylim = rev(range(Temp$depth)), 
  xlab = "distance along transect, km", ylab = "depth, m", 
  clab = c("","  dgC"), main = "part 1")

# zoom in on smaller topographic region - specific to data loaded
Lon <- lon[-(1:400)]
Lat <- lat[-(300:361)]
Depth <- depth[-(1:400),- (300:361)]
Depth[Depth < -250] <- -250
pm <- par(mar = c(2,2,2,2))
persp3D(Lon, Lat, z = Depth, scale = FALSE, plot = FALSE, lphi = 70, 
  theta = -60, expand = 0.005, main = "glider temperature",
  xlab = "longitude", ylab = "latitude", ticktype = "detailed",
  col = "grey", lighting = TRUE)
scatter3D(Temp$lon, Temp$lat, -Temp$depth, colvar = Temp$sci_water_temp, 
  pch = ".", cex = 3, theta = 10, bty = "f", clab = "dg C", 
  colkey = list(side = 1, length = 0.5, width = 0.5, 
      dist = 0.05, shift = -0.2, side.clab = 3, line.clab = 1, 
    cex.clab = 0.8, cex.axis = 0.8), add = TRUE)
plotrgl(lighting = TRUE, smooth = TRUE)
AddSource(url)

Go back