{"id":1076,"date":"2011-12-05T16:15:18","date_gmt":"2011-12-05T21:15:18","guid":{"rendered":"http:\/\/lukemiller.org\/?p=1076"},"modified":"2013-07-29T12:47:09","modified_gmt":"2013-07-29T16:47:09","slug":"loading-osus-vgpm-ocean-productivity-data-in-r","status":"publish","type":"post","link":"https:\/\/lukemiller.org\/index.php\/2011\/12\/loading-osus-vgpm-ocean-productivity-data-in-r\/","title":{"rendered":"Loading OSU&#8217;s VGPM ocean productivity data in R"},"content":{"rendered":"<p>Oregon State University makes a set of ocean productivity data derived from satellite data available for download and use by researchers. The <a title=\"Ocean Productivity website\" href=\"http:\/\/www.science.oregonstate.edu\/ocean.productivity\/index.php\" target=\"_blank\">Ocean Productivity website<\/a> explains the available data and how it was derived. I have put together a few R functions to open a subset of the available data files and plot the data.<\/p>\n<figure id=\"attachment_1077\" aria-describedby=\"caption-attachment-1077\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/12\/test.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1077\" title=\"West coast productivity\" alt=\"\" src=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/12\/test-300x300.png\" width=\"300\" height=\"300\" srcset=\"https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/12\/test-300x300.png 300w, https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/12\/test-150x150.png 150w, https:\/\/lukemiller.org\/wp-content\/uploads\/2011\/12\/test.png 600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-1077\" class=\"wp-caption-text\">Average monthly net primary productivity along the west coast of North America during February 2003. Data derived from OSU&#8217;s Vertically Generalized Production Model.<\/figcaption><\/figure>\n<p>The data files used here are from the Vertically Generalized Production Model (VGPM) based on <a href=\"http:\/\/www.jstor.org\/stable\/10.2307\/2838857\" target=\"_blank\">Behrenfeld and Falkowski 1997<\/a>. Most of the available files on the website are HDF5 format, which is currently difficult to deal with in the Windows version of R. The standard VGPM data derived from MODIS satellite data are also available in a simplified text file format (called .xyz files by OSU). These data files can be reached from <a title=\"this page.\" href=\"http:\/\/www.science.oregonstate.edu\/ocean.productivity\/standard.product.php\" target=\"_blank\">this page.<\/a> The functions below work on the .xyz file type. The .xyz files are available in two resolutions, one with 1\/6-degree steps between grid cells (1080&#215;2160 grid), and one with 1\/12-degree steps (2160&#215;4320 grid). The files should first be downloaded to your local machine.<\/p>\n<p>There are 4 functions outlined below. The function vgpm.load() extracts a matrix of productivity values from a specified file. The function plot.ROI() will plot that matrix of data. The function vgpm.plot() will extract and plot a matrix of productivity values all in one operation, and return the data matrix. Finally, the function vgpm.raster() illustrates a method for plotting the productivity data as<br \/>\na raster image, which results in a smaller file size when saved as a pdf or when displayed on screen. On my machine, trying to plot data for the entire world as a vector graphic fails to display anything because of the large amount of memory necessary for such an operation, while displaying the same data in raster format works just fine. The raster display function is a bit of hack, as you&#8217;ll see if you check out the function code below.<\/p>\n<p>The functions below can be downloaded as a R script called OSU_VPGM_load_functions.R from my <a title=\"GitHub repository\" href=\"https:\/\/github.com\/millerlp\/Misc_R_scripts\" target=\"_blank\">GitHub repository<\/a>. Run that script in a R session to gain access to the functions.<\/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: OSU_VGPM_load_function.R<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># This script contains 4 functions for loading data from OSU's VGPM .xyz data<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># files and plotting the data. See below for further information.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Author: Luke Miller Dec 2, 2011<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">###############################################################################<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># This script is an attempt to extract data from Oregon State University's <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Ocean Productivity Standard Vertically Generalized Production Model (VGPM) <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># files that are accessible here:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># http:\/\/www.science.oregonstate.edu\/ocean.productivity\/index.php<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># This script deals specifically with files obtained from this page:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># http:\/\/orca.science.oregonstate.edu\/1080.by.2160.monthly.xyz.vgpm.m.chl.m.sst4.php<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># or this page:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># http:\/\/orca.science.oregonstate.edu\/2160.by.4320.monthly.xyz.vgpm.m.chl.m.sst4.php<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># This script is meant to work with .xyz files rather than .hdf files. The<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># .xyz files simply store the data as a set of 3 columns of data with lat\/lon <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># and the productivity value, in a simple text file format. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The files will follow the naming format: vgpm.yyyyddd.all.xyz.gz<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Files are in an Equidistant Cylindrical projection, and the lat\/lon value of <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the center of each pixel is given. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># For 1080x2160 data (2332800 rows of data in the file), the grid spacing is at <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># 1\/6 of a degree. There are 180 degrees of latitude starting at the north pole,<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># and 360 degrees of longitude starting at -180 degrees (i.e. in the north <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Pacific ocean). For 2160x4320 data files (9331200 rows of data in the file), <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the grid spacing is a 1\/12\u00b0. All lat\/lon locations given in the file are for<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the center of a grid cell.<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># See here: http:\/\/orca.science.oregonstate.edu\/faq01.php for more info.<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># To cite the data used here, cite:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#  Behrenfeld, MJ, PG Falkowski<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#  Limnology and Oceanography<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#  1997a, Volume 42: 1-20<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#  Photosynthetic rates derived from satellite-based chlorophyll concentration<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># as well as citing the website:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># \thttp:\/\/www.science.oregonstate.edu\/ocean.productivity\/index.php<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The plotting routines below make use of the fields package, which must be<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># installed before running these functions. The fields package was produced by<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#   Reinhard Furrer, Douglas Nychka and Stephen Sain (2011). fields:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#   Tools for spatial data. R package version 6.6.1.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#   http:\/\/CRAN.R-project.org\/package=fields<\/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 function vgpm.load() opens a vgpm .xyz data file and extracts the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># productivity data from the specified region of interest. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The return value is a matrix of productivity values with associated grid cell<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitudes and longitudes listed in the row and column names<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The options to vgpm.load() are as follows:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># file = file name (or substitute file.choose() to pick file interactively)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># w.lon = western longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># e.lon = eastern longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># n.lat = northern latitude limit for region of interest (+90 to -90)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># s.lat = southern latitude limit for region of interest (+90 to -90)<\/span>\r\n\r\nvgpm.load = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399; font-weight: bold;\">function<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> w.lon<span style=\"color: #339933;\">,<\/span> e.lon<span style=\"color: #339933;\">,<\/span> n.lat<span style=\"color: #339933;\">,<\/span> s.lat<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The value -9999 is used as a missing data marker, so all occurrences are <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># changed to NA during the initial file read.<\/span>\r\n\tx = <a href=\"http:\/\/inside-r.org\/r-doc\/utils\/read.table\"><span style=\"color: #003399; font-weight: bold;\">read.table<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> sep = <span style=\"color: #0000ff;\">' '<\/span><span style=\"color: #339933;\">,<\/span> skip = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span> na.strings = <span style=\"color: #0000ff;\">'-9999'<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/names\"><span style=\"color: #003399; font-weight: bold;\">names<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> = <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: #0000ff;\">'lon'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'lat'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'values'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#Rename input columns<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#Establish which grid size is being used, 1080x2160 or 2160x4320<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'1080'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'2160'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/warning\"><span style=\"color: #003399; font-weight: bold;\">warning<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'Unknown file type<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>'<\/span><span style=\"color: #339933;\">,<\/span> immediate. = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The units for the column 'values' should be mg C \/ m^2 \/ Day<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The data are arranged so that the first value is at ~-180 longitude, <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># +89.9166N latitude. The values then increase in longitude (encircling the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># globe at a fixed latitude) for 2160 rows total. After that, the data move to <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the next latitude value south, and the next 2160 values are for each longitude<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># at the new latitude. This continues until you reach the southern-most latitude<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># value. The process is the same for the higher-resolution 2160x4320 files.<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'1080'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">1080<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'2160'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">#Insert the lat\/lon values as the 'values' matrix dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>values<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Specify the boundaries of your lat\/lon of interest. Recall that<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># longitude values run from -180E (international date line in the Pacific)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># to +180E, where Greenwich,England is at 0E. Latitude values range from<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># +90N (north pole) to -90 (south pole). The first value for longitude must be<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the western-most edge of your region of interest, and the first value for the<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitude must be the northern-most edge of the region of interest.<\/span>\r\n\tlonlim = <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>w.lon<span style=\"color: #339933;\">,<\/span>e.lon<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\"># c(western edge, eastern edge)<\/span>\r\n\tlatlim = <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>n.lat<span style=\"color: #339933;\">,<\/span>s.lat<span style=\"color: #009900;\">)<\/span>\t<span style=\"color: #666666; font-style: italic;\"># c(northern edge, southern edge)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Create vectors of lat\/lon indices<\/span>\r\n\tlonindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lons<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of longitude cell indices<\/span>\r\n\tlatindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lats<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of latitude cell indices<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Pull out 2 vectors that contain the indices of the lat\/lon coordinates<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># of interest. We search for longitudes that are greater than the 1st value<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># in lonlim, and longitudes that are less than the 2nd value in lonlim, and<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># then grab the corresponding indices from lonindx to store in goodlons. The<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># same is done for the latitudes<\/span>\r\n\tgoodlons = lonindx<span style=\"color: #009900;\">[<\/span>lons <span>&gt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lons <span>&lt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\tgoodlats = latindx<span style=\"color: #009900;\">[<\/span>lats <span>&gt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lats <span>&lt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Extract a subset of the matrix 'values', call it the Region of Interest (ROI) <\/span>\r\n\tROI = values<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlats<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tgoodlons<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlons<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Add the latitudes and longitudes to the ROI matrix as dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">[<\/span>goodlons<span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\tROI <span style=\"color: #666666; font-style: italic;\"># return the ROI matrix at the conclusion of the function<\/span>\r\n<span style=\"color: #009900;\">}<\/span> <span style=\"color: #666666; font-style: italic;\"># end of vgpm.load function<\/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 plot.ROI function produces a plot of the productivity data stored in the<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># output matrix from the vgpm.load() function above. The ROI matrix is <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># expected to have latitudes in rows (from North to South) and longitudes in <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># columns (from -180 to +180\u00b0). The associated latitudes and longitudes must<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># be in the row\/column names of the matrix, as produced by vgpm.load().<\/span>\r\n\r\nplot.ROI = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399; font-weight: bold;\">function<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a> = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> color = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">30<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># For plotting with the image.plot() command, it is necessary to arrange ROI <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># so that longitudes are in rows, and latitudes are in columns, with the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitudes order reversed so that they increase as you move across columns. <\/span>\r\n\tROI.plot = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/t\"><span style=\"color: #003399; font-weight: bold;\">t<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#transpose the ROI matrix<\/span>\r\n\tROI.plot = ROI.plot<span style=\"color: #009900;\">[<\/span><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><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#reverse the latitudes<\/span>\r\n\tlons = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rownames\"><span style=\"color: #003399; font-weight: bold;\">rownames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract longitudes<\/span>\r\n\tlats = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/colnames\"><span style=\"color: #003399; font-weight: bold;\">colnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract latitudes<\/span>\r\n\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/require\"><span style=\"color: #003399; font-weight: bold;\">require<\/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\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\timage.plot<span style=\"color: #009900;\">(<\/span>x=lons<span style=\"color: #339933;\">,<\/span> y=lats<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/log10\"><span style=\"color: #003399; font-weight: bold;\">log10<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">10<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">\"(mg C \/ \"<\/span><span style=\"color: #339933;\">,<\/span>m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">\"\/ day)\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.1<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tmain = <span style=\"color: #0000ff;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlas = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <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\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\timage.plot<span style=\"color: #009900;\">(<\/span>x=lons<span style=\"color: #339933;\">,<\/span> y=lats<span style=\"color: #339933;\">,<\/span> ROI.plot<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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;\">\"mg C \/ \"<\/span><span style=\"color: #339933;\">,<\/span>m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">\"\/ day\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.1<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tmain = <span style=\"color: #0000ff;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlas = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #009900;\">}<\/span> <span style=\"color: #666666; font-style: italic;\">#end of plot.ROI function<\/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 function vgpm.plot() reads data from the desired region of interest and<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># also optionally plots the data. <\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The options supplied to vgpm.plot() are as follows:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># file = file name (or substitute file.choose() to pick file interactively)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># w.lon = western longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># e.lon = eastern longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># n.lat = northern latitude limit for region of interest (+90 to -90)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># s.lat = southern latitude limit for region of interest (+90 to -90)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># plot.data = , plots data from region of interest<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># log = ,  log10 transform productivity data before plotting<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># color = , specify color set to plot productivity data<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Function returns a matrix of productivity values for the specified region of<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># interest with lat\/lon listed in the row and column names.<\/span>\r\nvgpm.plot = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399; font-weight: bold;\">function<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> w.lon<span style=\"color: #339933;\">,<\/span> e.lon<span style=\"color: #339933;\">,<\/span> n.lat<span style=\"color: #339933;\">,<\/span> s.lat<span style=\"color: #339933;\">,<\/span> plot.data = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a> = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> color = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">30<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#Extract date from file title<\/span>\r\n\tfname = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/basename\"><span style=\"color: #003399; font-weight: bold;\">basename<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #009900;\">)<\/span>\r\n\tdots = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/gregexpr\"><span style=\"color: #003399; font-weight: bold;\">gregexpr<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'<span style=\"color: #000099; font-weight: bold;\">\\\\<\/span>.'<\/span><span style=\"color: #339933;\">,<\/span>fname<span style=\"color: #009900;\">)<\/span>\r\n\tyrday = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>fname<span style=\"color: #339933;\">,<\/span>dots<span style=\"color: #009900;\">[<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>+<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span>dots<span style=\"color: #009900;\">[<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span><span>-<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\tyr = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>yrday<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">4<\/span><span style=\"color: #009900;\">)<\/span>\r\n\tdoy = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>yrday<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">7<\/span><span style=\"color: #009900;\">)<\/span>\r\n\tday1 = <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><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>yr<span style=\"color: #339933;\">,<\/span>doy<span style=\"color: #339933;\">,<\/span>sep = <span style=\"color: #0000ff;\">'-'<\/span><span style=\"color: #009900;\">)<\/span><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-%j'<\/span><span style=\"color: #009900;\">)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The value -9999 is used as a missing data marker, so all occurrences are <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># changed to NA during the initial file read.<\/span>\r\n\tx = <a href=\"http:\/\/inside-r.org\/r-doc\/utils\/read.table\"><span style=\"color: #003399; font-weight: bold;\">read.table<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> sep = <span style=\"color: #0000ff;\">' '<\/span><span style=\"color: #339933;\">,<\/span> skip = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span> na.strings = <span style=\"color: #0000ff;\">'-9999'<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/names\"><span style=\"color: #003399; font-weight: bold;\">names<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> = <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: #0000ff;\">'lon'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'lat'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'values'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#Rename input columns<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#Establish which grid size is being used, 1080x2160 or 2160x4320<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'1080'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'2160'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/warning\"><span style=\"color: #003399; font-weight: bold;\">warning<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'Unknown file type<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>'<\/span><span style=\"color: #339933;\">,<\/span> immediate. = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The units for the column 'values' should be mg C \/ m^2 \/ Day<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The data are arranged so that the first value is at ~-180 longitude, <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># +89.9166N latitude. The values then increase in longitude (encircling the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># globe at a fixed latitude) for 2160 rows total. After that, the data move to <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the next latitude value south, and the next 2160 values are for each longitude<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># at the new latitude. This continues until you reach the southern-most latitude<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># value. The process is the same for the higher-resolution 2160x4320 files.<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'1080'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">1080<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'2160'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">#Insert the lat\/lon values as the 'values' matrix dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>values<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Specify the boundaries of your lat\/lon of interest. Recall that<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># longitude values run from -180E (international date line in the Pacific)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># to +180E, where Greenwich,England is at 0E. Latitude values range from<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># +90N (north pole) to -90 (south pole). The first value for longitude must be<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the western-most edge of your region of interest, and the first value for the<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitude must be the northern-most edge of the region of interest.<\/span>\r\n\tlonlim = <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>w.lon<span style=\"color: #339933;\">,<\/span>e.lon<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\"># c(western edge, eastern edge)<\/span>\r\n\tlatlim = <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>n.lat<span style=\"color: #339933;\">,<\/span>s.lat<span style=\"color: #009900;\">)<\/span>\t<span style=\"color: #666666; font-style: italic;\"># c(northern edge, southern edge)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Create vectors of lat\/lon indices<\/span>\r\n\tlonindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lons<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of longitude cell indices<\/span>\r\n\tlatindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lats<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of latitude cell indices<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Pull out 2 vectors that contain the indices of the lat\/lon coordinates<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># of interest. We search for longitudes that are greater than the 1st value<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># in lonlim, and longitudes that are less than the 2nd value in lonlim, and<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># then grab the corresponding indices from lonindx to store in goodlons. The<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># same is done for the latitudes<\/span>\r\n\tgoodlons = lonindx<span style=\"color: #009900;\">[<\/span>lons <span>&gt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lons <span>&lt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\tgoodlats = latindx<span style=\"color: #009900;\">[<\/span>lats <span>&gt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lats <span>&lt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Extract a subset of the matrix 'values', call it the Region of Interest (ROI) <\/span>\r\n\tROI = values<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlats<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tgoodlons<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlons<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Add the latitudes and longitudes to the ROI matrix as dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">[<\/span>goodlons<span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">##########################<\/span>\r\n\t<span style=\"color: #666666; font-style: italic;\">##########################<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#Plotting section<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># For plotting with the image.plot() command, it is necessary to arrange ROI <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># so that longitudes are in rows, and latitudes are in columns, with the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitudes order reversed so that they increase as you move across columns. <\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>plot.data<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\tROI.plot = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/t\"><span style=\"color: #003399; font-weight: bold;\">t<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#transpose the ROI matrix<\/span>\r\n\t\tROI.plot = ROI.plot<span style=\"color: #009900;\">[<\/span><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><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#reverse the latitudes<\/span>\r\n\t\tlons = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rownames\"><span style=\"color: #003399; font-weight: bold;\">rownames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract longitudes<\/span>\r\n\t\tlats = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/colnames\"><span style=\"color: #003399; font-weight: bold;\">colnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract latitudes<\/span>\r\n\r\n\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/require\"><span style=\"color: #003399; font-weight: bold;\">require<\/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\n\t\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\t\timage.plot<span style=\"color: #009900;\">(<\/span>x=lons<span style=\"color: #339933;\">,<\/span> y=lats<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/log10\"><span style=\"color: #003399; font-weight: bold;\">log10<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">10<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\t\t\t\t\t<span style=\"color: #0000ff;\">\"(mg C \/ \"<\/span><span style=\"color: #339933;\">,<\/span>m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">\"\/ day)\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.1<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\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;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/strftime\"><span style=\"color: #003399; font-weight: bold;\">strftime<\/span><\/a><span style=\"color: #009900;\">(<\/span>day1<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'%B %Y'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlas = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <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\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\t\timage.plot<span style=\"color: #009900;\">(<\/span>x=lons<span style=\"color: #339933;\">,<\/span> y=lats<span style=\"color: #339933;\">,<\/span> ROI.plot<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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;\">\"mg C \/ \"<\/span><span style=\"color: #339933;\">,<\/span>m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">\"\/ day\"<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.1<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\txlab = <span style=\"color: #0000ff;\">\"Longitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tylab = <span style=\"color: #0000ff;\">\"Latitude\"<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\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;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\t\t\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/strftime\"><span style=\"color: #003399; font-weight: bold;\">strftime<\/span><\/a><span style=\"color: #009900;\">(<\/span>day1<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'%B %Y'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\t\tlas = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t\t<span style=\"color: #009900;\">}<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\r\n\tROI <span style=\"color: #666666; font-style: italic;\"># return the ROI matrix at the conclusion of the function<\/span>\r\n<span style=\"color: #009900;\">}<\/span> <span style=\"color: #666666; font-style: italic;\"># end of vgpm.load function<\/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;\"># If you want to plot a very large area, such as the whole globe, plotting the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># data using the regular image() or image.plot() functions produces very large<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># file sizes due to the large number of vectors used to make up the figure. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Often the figure may not even display correctly on the screen due to the large <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># file size. For small areas this won't be as much of a problem.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># It is more space-efficient to plot large data sets as a raster image with the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># useRaster = TRUE option of the image plotting tools. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># To make use of the useRaster option for plotting, the lat\/lon grid must be on<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># a completely regular grid, but due to the limitations of precision by the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># computer, the 1\/6\u00b0 (or 1\/12\u00b0) steps stored as characters in the input file <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># aren't converted to exact 1\/6\u00b0 steps for latitude and longitude.<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># We can make a set of approximate lat\/lon values for plotting. For the 1\/6\u00b0 <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the maximal error for the latitudes calculated here (~1\/30000\u00b0) versus those <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># reported in the original input file is a few meters of latitude <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># near the south pole. <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># The error is smallest in the northwest corner of the plot and largest in the <\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># southeast corner. Remember this only applies to the displayed figure, not the<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># data and lat\/lon values extracted above.<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># The options supplied to vgpm.raster() are as follows:<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># file = file name (or substitute file.choose() to pick file interactively)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># w.lon = western longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># e.lon = eastern longitude limit for region of interest (-180 to +180)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># n.lat = northern latitude limit for region of interest (+90 to -90)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># s.lat = southern latitude limit for region of interest (+90 to -90)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># log = TRUE - log10 transform productivity data before plotting<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># color = specify color set to plot productivity data<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Function returns a matrix of productivity values for the specified region of<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># interest with lat\/lon listed in the row and column names.<\/span>\r\nvgpm.raster = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/function\"><span style=\"color: #003399; font-weight: bold;\">function<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> w.lon<span style=\"color: #339933;\">,<\/span> e.lon<span style=\"color: #339933;\">,<\/span> n.lat<span style=\"color: #339933;\">,<\/span> s.lat<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a> = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\tcolor = tim.colors<span style=\"color: #009900;\">(<\/span><span style=\"color: #cc66cc;\">30<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#Extract date from file title<\/span>\r\n\tfname = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/basename\"><span style=\"color: #003399; font-weight: bold;\">basename<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #009900;\">)<\/span>\r\n\tdots = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/gregexpr\"><span style=\"color: #003399; font-weight: bold;\">gregexpr<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'<span style=\"color: #000099; font-weight: bold;\">\\\\<\/span>.'<\/span><span style=\"color: #339933;\">,<\/span>fname<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#find locations of . in file name<\/span>\r\n\tyrday = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>fname<span style=\"color: #339933;\">,<\/span>dots<span style=\"color: #009900;\">[<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>+<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span>dots<span style=\"color: #009900;\">[<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span><span>-<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract yearday combo<\/span>\r\n\tyr = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>yrday<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">4<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract year<\/span>\r\n\tdoy = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/substr\"><span style=\"color: #003399; font-weight: bold;\">substr<\/span><\/a><span style=\"color: #009900;\">(<\/span>yrday<span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">5<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">7<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#extract day of year<\/span>\r\n\tday1 = <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><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>yr<span style=\"color: #339933;\">,<\/span>doy<span style=\"color: #339933;\">,<\/span>sep = <span style=\"color: #0000ff;\">'-'<\/span><span style=\"color: #009900;\">)<\/span><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-%j'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#convert to Date<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\">#Read data from input file<\/span>\r\n\tx = <a href=\"http:\/\/inside-r.org\/r-doc\/utils\/read.table\"><span style=\"color: #003399; font-weight: bold;\">read.table<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/file\"><span style=\"color: #003399; font-weight: bold;\">file<\/span><\/a><span style=\"color: #339933;\">,<\/span> sep = <span style=\"color: #0000ff;\">' '<\/span><span style=\"color: #339933;\">,<\/span> skip = <span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #339933;\">,<\/span> na.strings = <span style=\"color: #0000ff;\">'-9999'<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/names\"><span style=\"color: #003399; font-weight: bold;\">names<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> = <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: #0000ff;\">'lon'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'lat'<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'values'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#Rename input columns<\/span>\r\n\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'1080'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span style=\"color: #009900;\">)<\/span> <span>==<\/span> <span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span> f.size = <span style=\"color: #0000ff;\">'2160'<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/warning\"><span style=\"color: #003399; font-weight: bold;\">warning<\/span><\/a><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'Unknown file type<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>'<\/span><span style=\"color: #339933;\">,<\/span> immediate. = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'1080'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">2332800<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">1080<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'2160'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlons = x<span>$<\/span>lon<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get set of longitude values<\/span>\r\n\t\tlats = x<span>$<\/span>lat<span style=\"color: #009900;\">[<\/span><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;\">1<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #cc66cc;\">9331200<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\">#get latitude values<\/span>\r\n\t\tvalues = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/matrix\"><span style=\"color: #003399; font-weight: bold;\">matrix<\/span><\/a><span style=\"color: #009900;\">(<\/span>x<span>$<\/span>values<span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/nrow\"><span style=\"color: #003399; font-weight: bold;\">nrow<\/span><\/a> = <span style=\"color: #cc66cc;\">2160<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/ncol\"><span style=\"color: #003399; font-weight: bold;\">ncol<\/span><\/a> = <span style=\"color: #cc66cc;\">4320<\/span><span style=\"color: #339933;\">,<\/span> byrow = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n<span style=\"color: #666666; font-style: italic;\">#Insert the lat\/lon values as the 'values' matrix dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>values<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Specify the boundaries of your lat\/lon of interest. Recall that<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># longitude values run from -180E (international date line in the Pacific)<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># to +180E, where Greenwich,England is at 0E. Latitude values range from<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># +90N (north pole) to -90 (south pole). The first value for longitude must be<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># the western-most edge of your region of interest, and the first value for the<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># latitude must be the northern-most edge of the region of interest.<\/span>\r\n\tlonlim = <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>w.lon<span style=\"color: #339933;\">,<\/span>e.lon<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\"># c(western edge, eastern edge)<\/span>\r\n\tlatlim = <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>n.lat<span style=\"color: #339933;\">,<\/span>s.lat<span style=\"color: #009900;\">)<\/span>\t<span style=\"color: #666666; font-style: italic;\"># c(northern edge, southern edge)<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Create vectors of lat\/lon indices<\/span>\r\n\tlonindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lons<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of longitude cell indices<\/span>\r\n\tlatindx = <span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lats<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\">#make vector of latitude cell indices<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Pull out 2 vectors that contain the indices of the lat\/lon coordinates<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># of interest. We search for longitudes that are greater than the 1st value<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># in lonlim, and longitudes that are less than the 2nd value in lonlim, and<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># then grab the corresponding indices from lonindx to store in goodlons. The<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># same is done for the latitudes<\/span>\r\n\tgoodlons = lonindx<span style=\"color: #009900;\">[<\/span>lons <span>&gt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lons <span>&lt;=<\/span> lonlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\tgoodlats = latindx<span style=\"color: #009900;\">[<\/span>lats <span>&gt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #009900;\">]<\/span> <span>&amp;<\/span> lats <span>&lt;=<\/span> latlim<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n\r\n<span style=\"color: #666666; font-style: italic;\"># Extract a subset of the matrix 'values', call it the Region of Interest (ROI) <\/span>\r\n\tROI = values<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlats<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\tgoodlons<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span>:<\/span>goodlons<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>goodlons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">]<\/span>\r\n<span style=\"color: #666666; font-style: italic;\"># Add the latitudes and longitudes to the ROI matrix as dimension names<\/span>\r\n\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/dimnames\"><span style=\"color: #003399; font-weight: bold;\">dimnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> = <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>Latitude = lats<span style=\"color: #009900;\">[<\/span>goodlats<span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span> Longitude = lons<span style=\"color: #009900;\">[<\/span>goodlons<span style=\"color: #009900;\">]<\/span><span style=\"color: #009900;\">)<\/span>\r\n\tn.lats = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/rownames\"><span style=\"color: #003399; font-weight: bold;\">rownames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n\tn.lons = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/as.numeric\"><span style=\"color: #003399; font-weight: bold;\">as.numeric<\/span><\/a><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/colnames\"><span style=\"color: #003399; font-weight: bold;\">colnames<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span>\r\n\r\n\t<span style=\"color: #666666; font-style: italic;\"># Generate a new set of lats and longs on a regular grid spacing for plot.<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'1080'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlats2 = <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>n.lats<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span>-<\/span><span style=\"color: #cc66cc;\">0.1666667<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a>=<span>-<\/span><span style=\"color: #cc66cc;\">0.1666667<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t\tlons2 = <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>n.lons<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span>+<\/span><span style=\"color: #cc66cc;\">0.1666667<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a>=<span style=\"color: #cc66cc;\">0.1666667<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span>f.size <span>==<\/span> <span style=\"color: #0000ff;\">'2160'<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\tlats2 = <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>n.lats<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span>-<\/span><span style=\"color: #cc66cc;\">0.0833333<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a>=<span>-<\/span><span style=\"color: #cc66cc;\">0.0833333<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t\tlons2 = <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>n.lons<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">[<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span><span>+<\/span><span style=\"color: #cc66cc;\">0.0833333<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/by\"><span style=\"color: #003399; font-weight: bold;\">by<\/span><\/a>=<span style=\"color: #cc66cc;\">0.0833333<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lats2<span style=\"color: #009900;\">)<\/span> <span>&gt;<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> lats2 = lats2<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lats<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span><span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lons2<span style=\"color: #009900;\">)<\/span> <span>&gt;<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> lons2 = lons2<span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>n.lons<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span>\r\n\tROI.plot = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/t\"><span style=\"color: #003399; font-weight: bold;\">t<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI<span style=\"color: #009900;\">)<\/span> <span style=\"color: #666666; font-style: italic;\"># swap longs and lats in 'ROI', so lats are in columns<\/span>\r\n\tROI.plot = ROI.plot<span style=\"color: #009900;\">[<\/span><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><span style=\"color: #cc66cc;\">1<\/span><span>:<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/length\"><span style=\"color: #003399; font-weight: bold;\">length<\/span><\/a><span style=\"color: #009900;\">(<\/span>lats2<span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">]<\/span> <span style=\"color: #666666; font-style: italic;\"># reverse latitudes so that <\/span>\r\n\t <span style=\"color: #666666; font-style: italic;\"># southern lats are listed first<\/span>\r\n\t<span style=\"color: #000000; font-weight: bold;\">if<\/span> <span style=\"color: #009900;\">(<\/span><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n\t\timage.plot<span style=\"color: #009900;\">(<\/span>lons2<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>lats2<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/log10\"><span style=\"color: #003399; font-weight: bold;\">log10<\/span><\/a><span style=\"color: #009900;\">(<\/span>ROI.plot<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> useRaster = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\txlab = <span style=\"color: #0000ff;\">'Longitude'<\/span><span style=\"color: #339933;\">,<\/span> ylab = <span style=\"color: #0000ff;\">'Latitude'<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\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;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/strftime\"><span style=\"color: #003399; font-weight: bold;\">strftime<\/span><\/a><span style=\"color: #009900;\">(<\/span>day1<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'%B %Y'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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><a href=\"http:\/\/inside-r.org\/r-doc\/base\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">[<\/span><span style=\"color: #cc66cc;\">10<\/span><span style=\"color: #009900;\">]<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'(mg C \/'<\/span><span style=\"color: #339933;\">,<\/span> m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'\/ day)'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.1<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span> <span style=\"color: #000000; font-weight: bold;\">else<\/span> <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\/log\"><span style=\"color: #003399; font-weight: bold;\">log<\/span><\/a><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">{<\/span>\r\n\t\timage.plot<span style=\"color: #009900;\">(<\/span>lons2<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>lats2<span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> ROI.plot<span style=\"color: #339933;\">,<\/span> useRaster = <span style=\"color: #000000; font-weight: bold;\">TRUE<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\t\t\t<a href=\"http:\/\/inside-r.org\/r-doc\/base\/col\"><span style=\"color: #003399; font-weight: bold;\">col<\/span><\/a> = color<span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\txlab = <span style=\"color: #0000ff;\">'Longitude'<\/span><span style=\"color: #339933;\">,<\/span> ylab = <span style=\"color: #0000ff;\">'Latitude'<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\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;\">'Net Primary Production'<\/span><span style=\"color: #339933;\">,<\/span> <a href=\"http:\/\/inside-r.org\/r-doc\/base\/strftime\"><span style=\"color: #003399; font-weight: bold;\">strftime<\/span><\/a><span style=\"color: #009900;\">(<\/span>day1<span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'%B %Y'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span> \r\n\t\t\t\tlegend.lab = <a href=\"http:\/\/inside-r.org\/r-doc\/base\/expression\"><span style=\"color: #003399; font-weight: bold;\">expression<\/span><\/a><span style=\"color: #009900;\">(<\/span><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;\">'mg C \/'<\/span><span style=\"color: #339933;\">,<\/span> m<span>^<\/span><span style=\"color: #cc66cc;\">2<\/span><span style=\"color: #339933;\">,<\/span><span style=\"color: #0000ff;\">'\/ day'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">,<\/span>\r\n\t\t\t\tlegend.mar = <span style=\"color: #cc66cc;\">4.3<\/span><span style=\"color: #009900;\">)<\/span>\r\n\t<span style=\"color: #009900;\">}<\/span>\r\n\tROI <span style=\"color: #666666; font-style: italic;\"># return region of interest data to workspace<\/span>\r\n<span style=\"color: #009900;\">}<\/span>  <span style=\"color: #666666; font-style: italic;\"># end of vgpm.raster() function<\/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>Oregon State University makes a set of ocean productivity data derived from satellite data available for download and use by researchers. The Ocean Productivity website explains the available data and how it was derived. I have put together a few R functions to open a subset of the available data files and plot the data. [&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":[107,108,109,113,111,110,112,106],"class_list":["post-1076","post","type-post","status-publish","format-standard","hentry","category-r-project","tag-image-plot","tag-latitude","tag-longitude","tag-modis","tag-net-primary-productivity","tag-osu","tag-satellite-data","tag-vgpm"],"_links":{"self":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/1076","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=1076"}],"version-history":[{"count":10,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/1076\/revisions"}],"predecessor-version":[{"id":1085,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/posts\/1076\/revisions\/1085"}],"wp:attachment":[{"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/media?parent=1076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/categories?post=1076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukemiller.org\/index.php\/wp-json\/wp\/v2\/tags?post=1076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}