Wednesday, 12 March 2014

Bathymetry

There are several alternatives to get bathymetric data in R.


1) Using marmap library. NOAA bathymetry.
This is a good solution, for large areas.

require(marmap)
getNOAA.bathy(lon1=-10, lon2=-6, lat1=36, lat2=42, resolution = 1) -> bathy
plot(bathy, image=TRUE, deep=-6000, shallow=0, step=100)
Created by Pretty R at inside-R.org





2) GEBCO bathymetry. We need to register in:
http://www.bodc.ac.uk/data/online_delivery/gebco/select/ and after doing the login, simply download the file '.nc' in netCDF format. We can choose between GEBCO_08 Grid (30 arc-second resolution)and 1 arc-minute grid. We can also download only a selected area.
Once the file has been downloaded, either open it using marmap or raster.

# Using marmap package:
 
require(marmap)
readGEBCO.bathy("gebco_08_-10_36_-6_42.nc", db = "GEBCO_08") -> med
 
plot(med)
class(med) # note that this is a matrix
 
# example from help page:
colorRampPalette(c("lightblue","cadetblue1","white")) -> blues # custom col palette
plot(med, n=1, im=T, bpal=blues(100)) #n indicates the number of conoutr lines, im goes for the filled contour or just the bathy lines, and bpal defines the colour palette
 
# Using raster package:
gebco = raster("gebco_08_-10_36_-6_42.nc")
plot(gebco)
plot(gebco, col=blues(100))
 
summary(gebco) # this is now a raster object, that we can overlay in ggplot map, for example.
Created by Pretty R at inside-R.org





















2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi, you mention in this post that the 'summary(gebco) # this is now a raster object, that we can overlay in ggplot map, for example'

    however, I am trying to do this (add a bathymetry layer to ggplot map) using the code:
    new data <- fortify(gebco)

    but I get the error 'ggplot2 doesn't know how to deal with data of class character'

    Any ideas?

    ReplyDelete