The goal of nchelper is to provide NetCDF variables as R arrays.
You can install nchelper from GitHub with:
# install.packages("devtools")
devtools::install_github("mdsumner/nchelper")
This is an example that reads an inbuilt data set of sea surface temperature.
First, find the file and open the variable “sst” as object a
.
library(nchelper)
f <- system.file("extdata", "avhrr-only-v2.20180126.nc", package = "nchelper")
a <- nchelper(f, "sst")
dim(a)
#> [1] 1440 720 1 1
names(a)
#> [1] "sst"
(Even though we asked for the variable “sst”, we could also see other names if there were any available.)
Now use standard indexing idioms to extract data from this 4D array.
grcol <- grey(seq(0, 1, length.out = 12))
image(a[,,,], col = grcol)
image(a[400:800, 100:300,,], col = grcol)
plot(a[,360,,] * 0.01, ylim = c(20, 32), type = "l")
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.