Tutorials


Here is a list of tutorials currently under development at OceanWatch - Central Pacific :


ERDDAP is one of the types of data portals you can use to view or download OceanWatch data. It allows you to subset the data for your region and the time period you are interested in, allows you to create plots, save those as images or pdf files, or downoad the data in a number of formats (text files, ascii, csv, or NetCDF among others).
A complete documentation page for ERDDAP, including a tutorial, is available at the CoastWatch West Coast node


Downloading ERDDAP data from R

Because ERDDAP includes RESTful services, you can download data listed on any ERDDAP platform from R using the URL structure. For example, the following page allows you to subset monthly Chlorophyll a data from the Aqua-MODIS sensor
http://oceanwatch.pifsc.noaa.gov/erddap/griddap/OceanWatch_aqua_chla_monthly.html.
Select your region and date range of interest, then select the '.nc' (NetCDF) file type and click on "Just Generate the URL".



In this specific example, the URL we generated is :
http://oceanwatch.pifsc.noaa.gov/erddap/griddap/OceanWatch_aqua_chla_monthly.nc?chla[(2015-05-01T00:00:00Z):1:(2016-05-01T00:00:00Z)][(17):1:(30)][(195):1:(210)]
You can also edit this URL manually.


In R, run the following to download the data using the generated URL (you need to copy it from your browser):

library(ncdf4)
library(httr)
library(plotrix)  
  
junk <- GET('http://oceanwatch.pifsc.noaa.gov/erddap/griddap/OceanWatch_aqua_chla_monthly.nc?chla[(2015-05-01T00:00:00Z):1:(2016-05-01T00:00:00Z)][(17):1:(30)][(195):1:(210)]', write_disk("chl.nc"))

Importing the downloaded data in R

Now that we've downloaded the data locally, we can import it and extract our variables of interest:

#open file
nc=nc_open('chl.nc')

#examine which variables are included in the dataset
names(nc$var)
## [1] "chla"
#extract chla 
v1=nc$var[[1]]
chl=ncvar_get(nc,v1)

#examine structure of chl
dim(chl)
## [1] 301 261  13
#our dataset is a 3-D array with 301 rows corresponding to longitudes, 261 columns corresponding to latitudes for each of the 13 time steps

#get the dates for each time step
dates=as.POSIXlt(v1$dim[[3]]$vals,origin='1970-01-01',tz='GMT')
dates
##  [1] "2015-05-01 GMT" "2015-06-01 GMT" "2015-07-01 GMT" "2015-08-01 GMT"
##  [5] "2015-09-01 GMT" "2015-10-01 GMT" "2015-11-01 GMT" "2015-12-01 GMT"
##  [9] "2016-01-01 GMT" "2016-02-01 GMT" "2016-03-01 GMT" "2016-04-01 GMT"
## [13] "2016-05-01 GMT"
#get lon and lat
lon=v1$dim[[1]]$vals
lon
##   [1] 195.00 195.05 195.10 195.15 195.20 195.25 195.30 195.35 195.40 195.45
##  [11] 195.50 195.55 195.60 195.65 195.70 195.75 195.80 195.85 195.90 195.95
##  [21] 196.00 196.05 196.10 196.15 196.20 196.25 196.30 196.35 196.40 196.45
##  [31] 196.50 196.55 196.60 196.65 196.70 196.75 196.80 196.85 196.90 196.95
##  [41] 197.00 197.05 197.10 197.15 197.20 197.25 197.30 197.35 197.40 197.45
##  [51] 197.50 197.55 197.60 197.65 197.70 197.75 197.80 197.85 197.90 197.95
##  [61] 198.00 198.05 198.10 198.15 198.20 198.25 198.30 198.35 198.40 198.45
##  [71] 198.50 198.55 198.60 198.65 198.70 198.75 198.80 198.85 198.90 198.95
##  [81] 199.00 199.05 199.10 199.15 199.20 199.25 199.30 199.35 199.40 199.45
##  [91] 199.50 199.55 199.60 199.65 199.70 199.75 199.80 199.85 199.90 199.95
## [101] 200.00 200.05 200.10 200.15 200.20 200.25 200.30 200.35 200.40 200.45
## [111] 200.50 200.55 200.60 200.65 200.70 200.75 200.80 200.85 200.90 200.95
## [121] 201.00 201.05 201.10 201.15 201.20 201.25 201.30 201.35 201.40 201.45
## [131] 201.50 201.55 201.60 201.65 201.70 201.75 201.80 201.85 201.90 201.95
## [141] 202.00 202.05 202.10 202.15 202.20 202.25 202.30 202.35 202.40 202.45
## [151] 202.50 202.55 202.60 202.65 202.70 202.75 202.80 202.85 202.90 202.95
## [161] 203.00 203.05 203.10 203.15 203.20 203.25 203.30 203.35 203.40 203.45
## [171] 203.50 203.55 203.60 203.65 203.70 203.75 203.80 203.85 203.90 203.95
## [181] 204.00 204.05 204.10 204.15 204.20 204.25 204.30 204.35 204.40 204.45
## [191] 204.50 204.55 204.60 204.65 204.70 204.75 204.80 204.85 204.90 204.95
## [201] 205.00 205.05 205.10 205.15 205.20 205.25 205.30 205.35 205.40 205.45
## [211] 205.50 205.55 205.60 205.65 205.70 205.75 205.80 205.85 205.90 205.95
## [221] 206.00 206.05 206.10 206.15 206.20 206.25 206.30 206.35 206.40 206.45
## [231] 206.50 206.55 206.60 206.65 206.70 206.75 206.80 206.85 206.90 206.95
## [241] 207.00 207.05 207.10 207.15 207.20 207.25 207.30 207.35 207.40 207.45
## [251] 207.50 207.55 207.60 207.65 207.70 207.75 207.80 207.85 207.90 207.95
## [261] 208.00 208.05 208.10 208.15 208.20 208.25 208.30 208.35 208.40 208.45
## [271] 208.50 208.55 208.60 208.65 208.70 208.75 208.80 208.85 208.90 208.95
## [281] 209.00 209.05 209.10 209.15 209.20 209.25 209.30 209.35 209.40 209.45
## [291] 209.50 209.55 209.60 209.65 209.70 209.75 209.80 209.85 209.90 209.95
## [301] 210.00
lat=v1$dim[[2]]$vals
lat 
##   [1] 17.00 17.05 17.10 17.15 17.20 17.25 17.30 17.35 17.40 17.45 17.50
##  [12] 17.55 17.60 17.65 17.70 17.75 17.80 17.85 17.90 17.95 18.00 18.05
##  [23] 18.10 18.15 18.20 18.25 18.30 18.35 18.40 18.45 18.50 18.55 18.60
##  [34] 18.65 18.70 18.75 18.80 18.85 18.90 18.95 19.00 19.05 19.10 19.15
##  [45] 19.20 19.25 19.30 19.35 19.40 19.45 19.50 19.55 19.60 19.65 19.70
##  [56] 19.75 19.80 19.85 19.90 19.95 20.00 20.05 20.10 20.15 20.20 20.25
##  [67] 20.30 20.35 20.40 20.45 20.50 20.55 20.60 20.65 20.70 20.75 20.80
##  [78] 20.85 20.90 20.95 21.00 21.05 21.10 21.15 21.20 21.25 21.30 21.35
##  [89] 21.40 21.45 21.50 21.55 21.60 21.65 21.70 21.75 21.80 21.85 21.90
## [100] 21.95 22.00 22.05 22.10 22.15 22.20 22.25 22.30 22.35 22.40 22.45
## [111] 22.50 22.55 22.60 22.65 22.70 22.75 22.80 22.85 22.90 22.95 23.00
## [122] 23.05 23.10 23.15 23.20 23.25 23.30 23.35 23.40 23.45 23.50 23.55
## [133] 23.60 23.65 23.70 23.75 23.80 23.85 23.90 23.95 24.00 24.05 24.10
## [144] 24.15 24.20 24.25 24.30 24.35 24.40 24.45 24.50 24.55 24.60 24.65
## [155] 24.70 24.75 24.80 24.85 24.90 24.95 25.00 25.05 25.10 25.15 25.20
## [166] 25.25 25.30 25.35 25.40 25.45 25.50 25.55 25.60 25.65 25.70 25.75
## [177] 25.80 25.85 25.90 25.95 26.00 26.05 26.10 26.15 26.20 26.25 26.30
## [188] 26.35 26.40 26.45 26.50 26.55 26.60 26.65 26.70 26.75 26.80 26.85
## [199] 26.90 26.95 27.00 27.05 27.10 27.15 27.20 27.25 27.30 27.35 27.40
## [210] 27.45 27.50 27.55 27.60 27.65 27.70 27.75 27.80 27.85 27.90 27.95
## [221] 28.00 28.05 28.10 28.15 28.20 28.25 28.30 28.35 28.40 28.45 28.50
## [232] 28.55 28.60 28.65 28.70 28.75 28.80 28.85 28.90 28.95 29.00 29.05
## [243] 29.10 29.15 29.20 29.25 29.30 29.35 29.40 29.45 29.50 29.55 29.60
## [254] 29.65 29.70 29.75 29.80 29.85 29.90 29.95 30.00
nc_close(nc)
rm(junk,v1)
file.remove('chl.nc')
## [1] TRUE

Working with the data

Creating a map of Chl a for May 2015 (our first time step)

You will need to download the scale.R file and copy it to your working directory to plot the color scale properly.

#set color breaks 
h=hist(chl[,,1], 100, plot=FALSE)
breaks=h$breaks
n=length(breaks)-1

#define a color palette
jet.colors <-colorRampPalette(c("blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
#set color scale using the jet.colors palette
c=jet.colors(n)

#prepare graphic window : left side for map, right side for color scale
layout(matrix(c(1,2,3,0,4,0), nrow=1, ncol=2), widths=c(8,1), heights=4)
layout.show(2)

par(mar=c(3,3,3,1))
#plot Chl map
image(lon,lat,chl[,,1],col=c,breaks=breaks,xlab='',ylab='',axes=TRUE,xaxs='i',yaxs='i',asp=1,main=paste("Monthly Chlorophyll a concentration", dates[1]))
#example of how to add points to the map 
points(202:205,rep(26,4), pch=20, cex=2)
#example of how to add a contour (this is considered a new plot, not a feature, so you need to use par(new=TRUE)
par(new=TRUE)
contour(lon,lat,chl[,,1],levels=0.09,xaxs='i',yaxs='i',labcex=0.8,vfont = c("sans serif", "bold"),axes=FALSE,asp=1)

par(mar=c(3,1,3,3))
#plot color scale using 'image.scale' function from 'scale.R' script)
source('scale.R')
image.scale(chl[,,1], col=c, breaks=breaks, horiz=FALSE, yaxt="n",xlab='',ylab='',main='Chl a')
axis(4)
box()

Note: you will most likely need to adjust the graphics window manually to best fit the map.


Plotting a time-series of median Chlorophyll a concentration in a box

Let's pick the following box : 24-26N, 200-206E

I1=which(lon==200)
I2=which(lon==206)
J1=which(lat==24)
J2=which(lat==26)
chl2=chl[I1:I2,J1:J2,]

n=dim(chl2)[3]

res=rep(NA,n)
for (i in 1:n)
  res[i]=median(chl2[,,i],na.rm=TRUE)

plot(1:n,res,axes=FALSE,type='o',pch=20,xlab='',ylab='Chl a')
axis(2)
axis(1,1:n,dates)
box()

Creating a map of median Chl a concentration over a year

From May 2015 to April 2016

chl.yr=apply(chl[,,1:12],c(1,2),median,na.rm=TRUE)

layout(matrix(c(1,2,3,0,4,0), nrow=1, ncol=2), widths=c(8,1), heights=4)
layout.show(2)

par(mar=c(3,3,3,1))
image(lon,lat,chl.yr,col=c,breaks=breaks,xlab='',ylab='',axes=TRUE,xaxs='i',yaxs='i',asp=1,main=paste("Median Chlorophyll a concentration", dates[1],' - ',dates[12]))

par(mar=c(3,1,3,3))
image.scale(chl.yr, col=c, breaks=breaks, horiz=FALSE, yaxt="n",xlab='',ylab='',main='Chl a')
axis(4)
box()


You can use the TDS Web Map Service (WMS) from our THREDDS server to import data into ArcGIS.

1. First select the dataset you want from the THREDDS catalog :
http://oceanwatch.pifsc.noaa.gov/thredds/catalog.html



2. Let's say we want to import the 2-day GOES SST data. The following page lists several links to the data that use different web services:
http://oceanwatch.pifsc.noaa.gov/thredds/catalog.html?dataset=2day-goes. Select the WMS link.



3. Copy the WMS URL:



4. In ArcGIS, double-click "Add WMS Server" in ArcCatalog.



5. In the dialog window, paste the url for the WMS in the field at the top (#1), click on the 'Get Layers' button (#2), click OK (#3).



6. The OceanWatch service will be in the list of servers. Drag and drop the parameter of interest into the ArcMap window.



7. In order to access a specific time step within the dataset, you need to enable Arc's time controls:

  • Click on the 'Time Slider' icon in the 'Tools' Toolbar (#1)
  • Click on the 'Time Slider Options' button on the Time Slider controls (#2)
  • On the 'Time Display' tab, configure a Time step interval that is appropriate for the data (#3)
  • Use the Time Slider to view a specific time interval (#4)




8. You can also select a different color palette than the default one:
Right-click on the parameter in the layer list and select 'Properties' (#1), then in the 'Styles' tab, use the drop down list to select the color palette you would like to use (#2).




Note: Click on the linked heading text to expand or collapse accordion panels.

If you do not find the information you are looking for, or would like to suggest a tutorial topic, please email our operations manager