[R-sig-Geo] Plots from netcdf file

David Forrest drf5n at maplepark.com
Fri Jun 15 16:11:22 CEST 2007


On Thu, 14 Jun 2007, Thomas Szegvary wrote:

> I am using the RNetCDF package to extract data from netcdf files. I've got a
> nc file (from an atmospheric model) with coordinates as the following:
>> dim(lon)
> [1] 67 46
>> dim(lat)
> [1] 67 46
>
> I suppose the lon and lat values are given to grid points. If I get the
> variables and plot(lon,lat) it shows me the grid points. But I am not able
> to use filled.contour(lon,lat,z) for a variable z. z containts also the
> coordinate array, 8 is an altitude layer and 121 represents the time
> (hours).
>
>> dim(z)
> [1]  67  46   8 121
>
> I tried to extract a specific hour and layer, e.g. z100 <- z[,,5,100] and
> tried to produce a contour plot. But I always have the following error
> message:
>
>> filled.contour(lon,lat,z100)
> Error in filled.contour(lon, lat, CO2.100) :
>        increasing 'x' and 'y' values expected
>
> What can I do?

A problem is that the grid is not regular, and several of the plotting 
tools for contour or surface data expect just two vectors of x and y 
coordinates.  If you just want a quick, distorted view, you could just 
grab a single row of lon and a column of lat.  Otherwise, 3d scatter plot 
methods like cloud or scatter3d might work.  For a nice surface, I think 
you'll need to resample/reproject/interpolate the points to a regular grid 
for plotting, as per MASS, 'local trend surfaces', with the 
predict(loess(z ~x+y,...),expand.grid(...)...) functions.

Another thing you might watch out for is that atmospheric model data often 
has staggered grids, with some features defined at the grid points, and 
others at the element centers.

Dave
-- 
  Dr. David Forrest
  drf at vims.edu                                    (804)684-7900w
  drf5n at maplepark.com                             (804)642-0662h
                                    http://maplepark.com/~drf5n/




More information about the R-sig-Geo mailing list