{"id":833,"date":"2011-03-01T20:06:02","date_gmt":"2011-03-02T01:06:02","guid":{"rendered":"http:\/\/lukemiller.org\/?p=833"},"modified":"2015-11-30T16:00:20","modified_gmt":"2015-12-01T00:00:20","slug":"extracting-sea-surface-temperatures-from-noaas-oisstv2","status":"publish","type":"post","link":"https:\/\/lukemiller.org\/index.php\/2011\/03\/extracting-sea-surface-temperatures-from-noaas-oisstv2\/","title":{"rendered":"Extracting sea surface temperatures from NOAA&#8217;s OISSTv2"},"content":{"rendered":"<p><strong>Update, 2015-11-30<\/strong> <em>It appears that NOAA has gone through and upgraded all of the OISST files to the newer version of the NetCDF file format. As a result, the functions outlined in this post don&#8217;t work any longer. Instead, see the updated functions in my newer post, <a href=\"https:\/\/lukemiller.org\/index.php\/2014\/11\/extracting-noaa-sea-surface-temperatures-with-ncdf4\/\">https:\/\/lukemiller.org\/index.php\/2014\/11\/extracting-noaa-sea-surface-temperatures-with-ncdf4\/<\/a>. The concepts are the same as described here, but the newer functions use the ncdf4 package to access the newer NetCDF file format. <\/em><\/p>\n<figure id=\"attachment_834\" aria-describedby=\"caption-attachment-834\" style=\"width: 300px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/03\/oisst.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-834\" title=\"oisst\" src=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/03\/oisst-300x175.png\" alt=\"\" width=\"300\" height=\"175\" srcset=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/03\/oisst-300x175.png 300w, https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/03\/oisst.png 576w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-834\" class=\"wp-caption-text\">Sea surface temperatures<\/figcaption><\/figure>\n<p>NOAA&#8217;s <a href=\"http:\/\/www.esrl.noaa.gov\/psd\/\">Physical Sciences Division<\/a> produces a global map of weekly averaged sea surface temperatures, derived from satellite sources. The data can be found at <a href=\"http:\/\/www.esrl.noaa.gov\/psd\/data\/gridded\/data.noaa.oisst.v2.html\" target=\"_blank\">http:\/\/www.esrl.noaa.gov\/psd\/data\/gridded\/data.noaa.oisst.v2.html<\/a>. I&#8217;ve put together a R script that will extract data from a region of interest and optionally plot it for you. The input data file is a 135+ MB netCDF file found at the link above.<\/p>\n<p>The OISSTv2 data are arranged in a 1\u00b0 x 1\u00b0 grid covering the entire world, and a weekly average has been calculated for each grid cell for each 7-day period starting Jan 1, 1990, in the file <code>sst.wkmean.1990-present.nc<\/code>. You will also want to grab the land-sea mask file <code>lsmask.nc<\/code> as well. The land-sea mask is necessary to remove the spurious temperature values that fall on the continents. In the script below I use the land-sea mask to simply convert all points over land into <code>NA<\/code> values in the output matrix.<\/p>\n<p>This script makes use of two add-on packages available from the CRAN repositories. First, the <a href=\"http:\/\/cran.r-project.org\/web\/packages\/ncdf\/\" target=\"_blank\"><code>ncdf<\/code><\/a> package, written by David Pierce and maintained by Brian Ripley, is used to open the netCDF file and extract the desired data. The <a href=\"http:\/\/cran.r-project.org\/web\/packages\/fields\/\" target=\"_blank\"><code>fields<\/code><\/a> package, written by Reinhard Furrer, Douglas Nychka and Stephen Sain, provides the tools to plot the data with a color scale bar alongside the plot.<\/p>\n<p><del datetime=\"2015-11-30T23:58:19+00:00\">The <a href=\"http:\/\/www.lukemiller.org\/R\/journal_scripts\/NOAA_OISST_extraction.R\" target=\"_blank\">NOAA_OISST_extraction.R script can be downloaded here<\/a>.<\/del> Please see the newer functions described in <a href=\"https:\/\/lukemiller.org\/index.php\/2014\/11\/extracting-noaa-sea-surface-temperatures-with-ncdf4\/\">https:\/\/lukemiller.org\/index.php\/2014\/11\/extracting-noaa-sea-surface-temperatures-with-ncdf4\/<\/a><\/p>\n<div style=\"overflow: auto;\">\n<div class=\"geshifilter\">\n<pre class=\"r geshifilter-R\" style=\"font-family: monospace;\"><span style=\"color: #666666; font-style: italic;\"># Filename: NOAA_OISST_extraction.R<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Author: Luke Miller   Mar 1, 2011<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/library\"><span style=\"color: #003399; font-weight: bold;\">library<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/packages\/cran\/ncdf\"><span>ncdf<\/span><\/a><span style=\"color: #009900;\">)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># For info on the NOAA Optimum Interpolated Sea Surface Temperature V2 (OISST):<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># http:\/\/www.esrl.noaa.gov\/psd\/data\/gridded\/data.noaa.oisst.v2.html<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># This script works on the OISST sea surface temperature netCDF file called <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># sst.wkmean.1990-present.nc, which must be downloaded into the current <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># working directory (file size is &gt;135MB currently)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The OISST grid layout is 1 degree latitudes from 89.5 to -89.5 degrees north.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The longitude grid is 1 degree bins, 0.5 to 359.5 degrees east.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The SST values are given in degrees Celsius.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Time values are \"days since 1800-1-1 00:00\", starting from 69395<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Time delta_t is 0000-00-07 00:00, indices range from 0 to 1103 currently<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The time values in the sst field give the 1st day of the week for each <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># weekly temperature value (though the data are meant to be centered on <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Wednesday of that week), starting at 69395 = 12\/31\/1989.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Use as.Date(69395,origin = '1800-1-1') to convert the netCDF day value to a <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># human readable form. <\/span>\r\n\r\nlats = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/seq\"><span style=\"color: #003399; font-weight: bold;\">seq<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">89.5<\/span><span style=\"color: #339933;\">,<\/span><span>-<\/span><span style=\"color: #cc66cc;\">89.5<\/span><span style=\"color: #339933;\">,<\/span><span>-<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#generate set of grid cell latitudes (center of cell)<\/span>\r\nlons = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/seq\"><span style=\"color: #003399; font-weight: bold;\">seq<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0.5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">359.5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#generate set of grid cell longitudes (center of cell)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#Ask user to enter the boundaries of the search area<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter longitude of western edge of search area (degrees east 0 to 359)<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\nlon1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\"><span style=\"color: #003399; font-weight: bold;\">numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter longitude of eastern edge of search area (degrees east 0 to 359)<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\nlon2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\"><span style=\"color: #003399; font-weight: bold;\">numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter latitude of northern edge<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"of search area (degrees north, 89.5 to -89.5<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\nlat1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\"><span style=\"color: #003399; font-weight: bold;\">numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter latitude of southern edge<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"of search area (degrees north, 89.5 to -89.5<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\nlat2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/numeric\"><span style=\"color: #003399; font-weight: bold;\">numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\nlon1a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>lon1 <span>-<\/span> lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest longitude value<\/span>\r\nlon2a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>lon2 <span>-<\/span> lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest longitude value<\/span>\r\nlat1a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>lat1 <span>-<\/span> lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest latitude value<\/span>\r\nlat2a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>lat2 <span>-<\/span> lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest latitude value<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#The lon\/lat 1a\/2a values should now correspond to indices in the netCDF file<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#for the desired grid cell. <\/span>\r\nnlon = <span style=\"color: #009900;\">(<\/span>lon2a <span>-<\/span> lon1a<span style=\"color: #009900;\">)<\/span> <span>+<\/span> <span style=\"color: #cc66cc;\">1<\/span> <span style=\"color: #666666; font-style: italic;\">#get number of longitudes to extract<\/span>\r\nnlat = <span style=\"color: #009900;\">(<\/span>lat2a <span>-<\/span> lat1a<span style=\"color: #009900;\">)<\/span> <span>+<\/span> <span style=\"color: #cc66cc;\">1<\/span> <span style=\"color: #666666; font-style: italic;\">#get number of latitudes to extract<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#Ask the user to enter the dates of interest<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter the starting date in the form: 1990-1-31<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\ndate1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\"><span style=\"color: #003399; font-weight: bold;\">character<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/cat\"><span style=\"color: #003399; font-weight: bold;\">cat<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Enter the ending date in the form: 1990-1-31<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #009900;\">)<\/span>\r\ndate2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/scan\"><span style=\"color: #003399; font-weight: bold;\">scan<\/span><\/a><span style=\"color: #009900;\">(<\/span>what = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/character\"><span style=\"color: #003399; font-weight: bold;\">character<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>n = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#date1 = '2007-08-01'<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#date2 = '2007-09-01'<\/span>\r\ndate1 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.Date\"><span style=\"color: #003399; font-weight: bold;\">as.Date<\/span><\/a><span style=\"color: #009900;\">(<\/span>date1<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/format\"><span style=\"color: #003399; font-weight: bold;\">format<\/span><\/a> = <span style=\"color: #0000ff;\">\"%Y-%m-%d\"<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#convert to Date object<\/span>\r\ndate2 = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.Date\"><span style=\"color: #003399; font-weight: bold;\">as.Date<\/span><\/a><span style=\"color: #009900;\">(<\/span>date2<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/format\"><span style=\"color: #003399; font-weight: bold;\">format<\/span><\/a> = <span style=\"color: #0000ff;\">\"%Y-%m-%d\"<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#convert to Date object<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#Open the netCDF file for reading. <\/span>\r\nnc = open.ncdf<span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"sst.wkmean.1990-present.nc\"<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#print.ncdf(nc) will show info about the structure of the netCDF file<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#Extract available dates from netCDF file<\/span>\r\nncdates = nc<span>$<\/span>dim<span>$<\/span>time<span>$<\/span>vals\r\nncdates = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.Date\"><span style=\"color: #003399; font-weight: bold;\">as.Date<\/span><\/a><span style=\"color: #009900;\">(<\/span>ncdates<span style=\"color: #339933;\">,<\/span>origin = <span style=\"color: #0000ff;\">'1800-1-1'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#available time points in nc<\/span>\r\n\r\ndate1a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>date1 <span>-<\/span> ncdates<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest time point<\/span>\r\ndate2a = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/which.min\"><span style=\"color: #003399; font-weight: bold;\">which.min<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/abs\"><span style=\"color: #003399; font-weight: bold;\">abs<\/span><\/a><span style=\"color: #009900;\">(<\/span>date2 <span>-<\/span> ncdates<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get index of nearest time point<\/span>\r\nndates = <span style=\"color: #009900;\">(<\/span>date2a <span>-<\/span> date1a<span style=\"color: #009900;\">)<\/span> <span>+<\/span> <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #666666; font-style: italic;\">#get number of time steps to extract<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#Extract the data from the netCDF file to a matrix or array called 'sstout'. <\/span>\r\nsstout = get.var.ncdf<span style=\"color: #009900;\">(<\/span>nc<span style=\"color: #339933;\">,<\/span> varid = <span style=\"color: #0000ff;\">'sst'<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/stats\/start\"><span style=\"color: #003399; font-weight: bold;\">start<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span>lon1a<span style=\"color: #339933;\">,<\/span>lat1a<span style=\"color: #339933;\">,<\/span>date1a<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\tcount = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span>nlon<span style=\"color: #339933;\">,<\/span>nlat<span style=\"color: #339933;\">,<\/span>ndates<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#If you only retrieve one time point, sstout will be a 2D matrix with <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#longitudes running down the rows, and latitudes across the columns. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#For example, Column 1, sstout[1:nrow(sstout),1], will contain sst values for <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#each of the longitude values at the northern-most latitude in your search <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#area, with the first row, sstout[1,1], being the western-most longitude, and <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#the last row being the eastern edge of your search area.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#If you retrieve multiple time points, sstout will be a 3D array, where time is<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#the 3rd dimension. Lat\/lon will be arranged the same as the 2D case. <\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#The vector 'datesout' will hold the Date values associated with each set of <\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#sst values in the sstout array, should you need to access them.<\/span>\r\ndatesout = ncdates<span style=\"color: #009900;\">[<\/span>date1a<span>:<\/span>date2a<span style=\"color: #009900;\">]<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The NOAA OISST files contain sea surface temperatures for the entire globe,<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># including on the continents. This clearly isn't right, so they also supply a<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># land-sea mask file in netCDF format at the website listed at the start of <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># this script. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># We use the values (0 or 1) stored in the mask file to turn all of the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># continent areas into NA's. <\/span>\r\n\r\nnc2 = open.ncdf<span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'lsmask.nc'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#open land-sea mask<\/span>\r\nmask = get.var.ncdf<span style=\"color: #009900;\">(<\/span>nc2<span style=\"color: #339933;\">,<\/span> varid = <span style=\"color: #0000ff;\">\"mask\"<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/stats\/start\"><span style=\"color: #003399; font-weight: bold;\">start<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span>lon1a<span style=\"color: #339933;\">,<\/span>lat1a<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\tcount = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span>nlon<span style=\"color: #339933;\">,<\/span>nlat<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#get land-sea mask values (0 or 1)<\/span>\r\n\r\nmask = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ifelse\"><span style=\"color: #003399; font-weight: bold;\">ifelse<\/span><\/a><span style=\"color: #009900;\">(<\/span>mask <span>==<\/span> <span style=\"color: #cc66cc;\">0<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #000000; font-weight: bold;\">NA<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#replace 0's with NA's<\/span>\r\n\r\n<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/is.matrix\"><span style=\"color: #003399; font-weight: bold;\">is.matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> <span style=\"color: #666666; font-style: italic;\">#if there is only 1 time point (2D matrix)<\/span>\r\n\tsstout = sstout <span>*<\/span> mask <span style=\"color: #666666; font-style: italic;\">#all masked values become NA\t<\/span>\r\n<span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><span>!<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/is.matrix\"><span style=\"color: #003399; font-weight: bold;\">is.matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> <span style=\"color: #666666; font-style: italic;\">#if ssout is a 3D matrix<\/span>\r\n\tdims = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/dim\"><span style=\"color: #003399; font-weight: bold;\">dim<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">for<\/span> <span style=\"color: #009900;\">(<\/span>i <span style=\"color: #000000; font-weight: bold;\">in<\/span> <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span>dims<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">3<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\tsstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,,<\/span>i<span style=\"color: #009900;\">]<\/span> = sstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,,<\/span>i<span style=\"color: #009900;\">]<\/span> <span>*<\/span> mask <span style=\"color: #666666; font-style: italic;\">#all masked values become NA<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#Now we can produce a plot of the data. <\/span>\r\n<a href=\"http:\/\/inside-r.org\/r-doc\/base\/library\"><span style=\"color: #003399; font-weight: bold;\">library<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/packages\/cran\/fields\"><span>fields<\/span><\/a><span style=\"color: #009900;\">)<\/span>\r\ngoodlons = lons<span style=\"color: #009900;\">[<\/span>lon1a<span>:<\/span>lon2a<span style=\"color: #009900;\">]<\/span>\r\ngoodlats = lats<span style=\"color: #009900;\">[<\/span>lat1a<span>:<\/span>lat2a<span style=\"color: #009900;\">]<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\">#plot the 1st time point<\/span>\r\n<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/is.matrix\"><span style=\"color: #003399; font-weight: bold;\">is.matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span> <span style=\"color: #666666; font-style: italic;\">#if there is only one time point<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/par\"><span style=\"color: #003399; font-weight: bold;\">par<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/packages\/cran\/mAr\"><span>mar<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">4<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">6<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#widen margins<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/image\"><span style=\"color: #003399; font-weight: bold;\">image<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>sstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tylim = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/range\"><span style=\"color: #003399; font-weight: bold;\">range<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #666666; font-style: italic;\">#reverse y-axis<\/span>\r\n\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tyaxt = <span style=\"color: #0000ff;\">\"n\"<\/span><span style=\"color: #339933;\">,<\/span> xaxt = <span style=\"color: #0000ff;\">\"n\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude (degrees north)\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude (degrees east)\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tmain = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/paste\"><span style=\"color: #003399; font-weight: bold;\">paste<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Week of \"<\/span><span style=\"color: #339933;\">,<\/span>datesout<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>sep = <span style=\"color: #0000ff;\">\"\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/axis\"><span style=\"color: #003399; font-weight: bold;\">axis<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span>at = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/labels\"><span style=\"color: #003399; font-weight: bold;\">labels<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> las = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/axis\"><span style=\"color: #003399; font-weight: bold;\">axis<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span>at = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/labels\"><span style=\"color: #003399; font-weight: bold;\">labels<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> las = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#image.plot from the fields package inserts a color bar<\/span>\r\n\timage.plot<span style=\"color: #009900;\">(<\/span>zlim = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/range\"><span style=\"color: #003399; font-weight: bold;\">range<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>na.rm = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>nlevel = <span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tlegend.only = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> horizontal = <span style=\"color: #000000; font-weight: bold;\">FALSE<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tlegend.args = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399; font-weight: bold;\">list<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/text\"><span style=\"color: #003399; font-weight: bold;\">text<\/span><\/a> = <span style=\"color: #0000ff;\">\"Temperature, C\"<\/span><span style=\"color: #339933;\">,<\/span> cex = <span style=\"color: #cc66cc;\">1.2<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tside = <span style=\"color: #cc66cc;\">4<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/stats\/line\"><span style=\"color: #003399; font-weight: bold;\">line<\/span><\/a> = <span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">#If there is more than one time point, just plot the first time point<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/grDevices\/windows\"><\/a><a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/par\"><span style=\"color: #003399; font-weight: bold;\">par<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/packages\/cran\/mAr\"><span>mar<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/c\"><span style=\"color: #003399; font-weight: bold;\">c<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">4.5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">4.5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">3<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">6<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#widen margins<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/image\"><span style=\"color: #003399; font-weight: bold;\">image<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>sstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tylim = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/range\"><span style=\"color: #003399; font-weight: bold;\">range<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #666666; font-style: italic;\">#reverse y-axis<\/span>\r\n\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tyaxt = <span style=\"color: #0000ff;\">\"n\"<\/span><span style=\"color: #339933;\">,<\/span> xaxt = <span style=\"color: #0000ff;\">\"n\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude (degrees north)\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude (degrees east)\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tmain = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/paste\"><span style=\"color: #003399; font-weight: bold;\">paste<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">\"Week of \"<\/span><span style=\"color: #339933;\">,<\/span>datesout<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>sep = <span style=\"color: #0000ff;\">\"\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/axis\"><span style=\"color: #003399; font-weight: bold;\">axis<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span>at = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/labels\"><span style=\"color: #003399; font-weight: bold;\">labels<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> las = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/axis\"><span style=\"color: #003399; font-weight: bold;\">axis<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span>at = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/rev\"><span style=\"color: #003399; font-weight: bold;\">rev<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/labels\"><span style=\"color: #003399; font-weight: bold;\">labels<\/span><\/a> = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/pretty\"><span style=\"color: #003399; font-weight: bold;\">pretty<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> las = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">#image.plot from the fields package inserts a color bar<\/span>\r\n\timage.plot<span style=\"color: #009900;\">(<\/span>zlim = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/range\"><span style=\"color: #003399; font-weight: bold;\">range<\/span><\/a><span style=\"color: #009900;\">(<\/span>sstout<span style=\"color: #009900;\">[<\/span><span style=\"color: #339933;\">,,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>na.rm = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>nlevel = <span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tlegend.only = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> horizontal = <span style=\"color: #000000; font-weight: bold;\">FALSE<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">32<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tlegend.args = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/list\"><span style=\"color: #003399; font-weight: bold;\">list<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/graphics\/text\"><span style=\"color: #003399; font-weight: bold;\">text<\/span><\/a> = <span style=\"color: #0000ff;\">\"Temperature, C\"<\/span><span style=\"color: #339933;\">,<\/span> cex = <span style=\"color: #cc66cc;\">1.2<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tside = <span style=\"color: #cc66cc;\">4<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/stats\/line\"><span style=\"color: #003399; font-weight: bold;\">line<\/span><\/a> = <span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #009900;\">}<\/span><\/pre>\n<\/div>\n<\/div>\n<p><a title=\"Created by Pretty R at inside-R.org\" href=\"http:\/\/www.inside-r.org\/pretty-r\">Created by Pretty R at inside-R.org<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update, 2015-11-30 It appears that NOAA has gone through and upgraded all of the OISST files to the newer version of the NetCDF file format. As a result, the functions outlined in this post don&#8217;t work any longer. Instead, see the updated functions in my newer post, https:\/\/lukemiller.org\/index.php\/2014\/11\/extracting-noaa-sea-surface-temperatures-with-ncdf4\/. The concepts are the same as described [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[218],"tags":[76,74,75,64,77,58,73],"class_list":["post-833","post","type-post","status-publish","format-standard","hentry","category-r-project","tag-fields","tag-ncdf","tag-netcdf","tag-noaa","tag-oisst","tag-r-project","tag-sea-surface-temperature"],"_links":{"self":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/comments?post=833"}],"version-history":[{"count":13,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/833\/revisions"}],"predecessor-version":[{"id":2143,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/833\/revisions\/2143"}],"wp:attachment":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/media?parent=833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/categories?post=833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/tags?post=833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}