[R-sig-Geo] Learning "raster"
Steve_Friedman at nps.gov
Steve_Friedman at nps.gov
Tue Jan 25 16:47:19 CET 2011
Hello,
I am trying to learn how to use the Raster package.
I have moderate (480 MB) to large netCDF files (2 GB) that contain daily
records. The smaller files cover 10 years and the larger files cover 30 to
46 years of data. I need to calculate a series of statistical summaries
(seasonal and annual means, sd) from the variables within these netCDF
files. These files also store coordinate locations for cell specific
information. For example the smaller files are ncols = 194 by nrows 174
with 3650 layernames (one layer for every day in the 10 year period of
record), and the larger file is larger in both spatial and temporal
domains.
I am looking for the most efficient method to read these data in R and then
process the statistical summaries that I mentioned above. I do need to
retain the spatial structure of the data as I eventually want to overlay a
vegetation map on these files to generate zonal statistics for vegetation
classes.
I can open the files using:
library(raster)
s <- brick("salinity.nc", varname = "Salinity")
or
ss <- stack("salinity.nc", varname = "Salinity")
But now I don' see an approach to subsetting this on the temporal domain.
Does raster support this kind of analysis?
I can also open the files directly using ncdf
salt <- open.ncdf("salinity_1990.nc") ## note here that I have subset
the 10 year data record to include just the first year (365 daily records)
prior to importing to R. I would really like to do this inside R if it is
feasible rather than using a stand alone utility for this purpose.
Once I have the annual data file in R, I can grab individual months as
follows:
for (i in 0 :30)
Jan <- salt[, , i]
for (i in 31 : 58)
Feb <- salt[, , i]
I found the cellStats function in raster, but I have not figure out how I
can convert this file to a raster, I think, correct me if I'm wrong, that
cellStats should be able to handle multiple layers and calculate the
statistics using data from each layer. Is that right ?
Jan.ras <- raster(Jan)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "raster", for signature
"array"
What can you recommend to help me. I'm currently reading the "Introduction
to the 'raster' package (1.7.-29) and the manual for the raster package as
well.
Thanks for your time and assistance.
Steve
Steve Friedman Ph. D.
Ecologist / Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034
Steve_Friedman at nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147
More information about the R-sig-Geo
mailing list