[R-sig-Geo] multiple data variables in one {Raster*, netCDF file}

Tom Roche Tom_Roche at pobox.com
Wed Jan 2 19:31:30 CET 2013


Can one read multiple data variables (datavars) to one netCDF-derived
Raster*? Can one write* from several Raster*'s to several datavars in
one netCDF file? What I mean, why I ask:

I have a netCDF file with several datavars. One datavar (concentrations)
is of primary interest, but I will need several of the other datavars to
do subsequent computations on the concentrations datavar. The concs
datavar is 3D (vertical level, latitude, longitude) but the others are
either 2D (surface pressure, dims=(lat, lon)) or 1D (coefficients,
dim=level). (There is only one timestep.)

I also need to crop the horizontal extent of the datavars >= 2D in the
file. This is easy with raster::crop(Raster*, ...), but it seems one can
only construct a Raster* with one datavar per netCDF file:

http://cran.r-project.org/web/packages/raster/raster.pdf
> raster   Create a RasterLayer object
...
> Details
...
> If x represents a NetCDF file, the following additional variable is
> recognized:

> varname: character. The variable name, such as ’tasmax’ or ’pr’. If
> not supplied and the file has multiple variables are a guess will be
> made (and reported)

Am I missing something? If not, I'd like to know:

1. Must I create and crop separate Raster*s for each datavar?

2. Can I at least create/crop separate Raster*s for each of the
   dimensionalities: i.e., put the 3D datavars in one Raster* and put
   the 2D datavars in another Raster*?

3. A subsequent processor (apparently) finds it advantageous to have all
   the datavars in one netCDF file. Can one write from multiple Raster*
   to multiple datavars in a single netCDF file? An optimistic reading
   of raster.pdf suggests this is supported via the sequence
   [writeStart, writeValues, writeStop], but I'd appreciate
   confirmation.

TIA, Tom Roche <Tom_Roche at pobox.com>



More information about the R-sig-Geo mailing list