README.md

obpgtools

R language tools for use with raster data originating from the Ocean Biolog Processing Group. Can be used in conjunction with obpgcrawler and spnc.

Requirements

Installation

It's fairly easy to install using Hadley Wickham's devtools.

library(devtools)
install_github('btupper/obpgtools')

Examples

Let's start with two SST and two CHL datasets from OBPG stored in raster format. The following are 8 day composites from 2012 and are subsets covering the Gulf of Maine.

dir()
# [1] "A20121452012152.L3m_8D_SST_sst_9km.grd"     "A20121452012152.L3m_8D_SST_sst_9km.gri"    
# [3] "A20121532012160.L3m_8D_SST_sst_9km.grd"     "A20121532012160.L3m_8D_SST_sst_9km.gri"    
# [5] "A20141452014152.L3m_8D_CHL_chlor_a_9km.grd" "A20141452014152.L3m_8D_CHL_chlor_a_9km.gri"
# [7] "A20141532014160.L3m_8D_CHL_chlor_a_9km.grd" "A20141532014160.L3m_8D_CHL_chlor_a_9km.gri"
library(raster)
library(obpgtools)

# get the SST and CHL filenames
sstff <- list.files( pattern = glob2rx("*SST*.grd"), full.names = TRUE)
chlff <- list.files( pattern = glob2rx("*CHL*.grd"), full.names = TRUE)

# load SST and take a peak
sst <- obpgtools::read_obpg(sstff)
sst
# class       : RasterBrick 
# dimensions  : 85, 108, 9180, 2  (nrow, ncol, ncell, nlayers)
# resolution  : 0.08410497, 0.08235296  (x, y)
# extent      : -72, -62.91667, 39, 46  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
# data source : in memory
# names       : A20121452012152.L3m_8D_SST_sst_9km, A20121532012160.L3m_8D_SST_sst_9km 
# min values  :                           4.730064,                           5.549806 
# max values  :                           24.36515,                           25.84255 

spplot(sst)

Chlorophyl presents an interesting twist - generally we want to display log-scaled data. We have two choices here. We can read the data in as is and then transform just when displaying, or we can read the data in transformed already. We specify the transform function used with the fun argument (which is NULL by default). Note the value of fun is actually a reference to a known function, not a quoted name of a function. You could specify other functions other than log10 - try sqrt or make your own.

my_transform <- function(x) {x*2 + 7}
chl_transform <- obpgtools::read_obpg(chlff, fun = my_transform)

But we'll stick with the conventional log10.

chl <- obpgtools::read_obpg(chlff)
spplot(log10(chl))

chl_logged <- obpgtools::read_obpg(chlff, fun = log10)
spplot(chl_logged)


btupper/obpgtools documentation built on May 13, 2019, 8:42 a.m.