Description Usage Arguments Value See Also Examples
Reads an array of data (a slice) from an existing netCDF file. Typically this array is two-dimensional and meant to be plotted.
1 | ncvar_slice(nc, varid, ...)
|
nc |
netCDF handle, from |
varid |
the variable to read the data from. Needs to be an actual variable, not a dimension variable. Can be a string with the name of the variable or an object of class |
... |
ranges of the values to extract, for each dimension. Each range is a vector of numbers, in the unit of the corresponding dimension, and everything between the minimum and maximum of these numbers will be extracted. Ranges can be specified either as named arguments, whose name matches one of the dimensions, or are assumed to be in the same order as the dimensions of the netCDF variable. Unspecified or NA elements are fully extracted. |
A list containing vectors for each dimension (of length > 1) and one array containing the extracted data. For two-dimensional slices, this list is suitable for plotting functions such as image
, contour
and persp
after changing the names to "x", "y", and "z". Convenience functions are provided to make this conversion, convert the slice into a data.frame, or plot the slice directly.
as.xyz.ncslice4
and as.data.frame.ncslice4
to convert a slice to various usual formats; plot.ncslice4
to plot a slice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | nc <- nc_open(system.file("extdata", "sresa1b_ncar_ccsm3.nc", package="ncdf4helpers"))
# extract everything
x <- ncvar_slice(nc, "tas")
# inspect the result
str(x)
# extract some specific ranges
x <- ncvar_slice(nc, "tas", lon=c(100, 200))
x <- ncvar_slice(nc, "tas", lat=10:80)
x <- ncvar_slice(nc, "tas", lon=c(0,300), lat=c(10:20))
x <- ncvar_slice(nc, "tas", lon=c(0,50), lat=NA)
nc_close(nc)
# plot the result
image(as.xyz(x))
# or simply
image(x)
# convert the slice into a data.frame for later manipulation
head(as.data.frame(x))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.