
Last chance! 50% off unlimited learning
Sale ends in
This function extracts all data at given points. The points are given by a pair of vectors with longitude and latitude coordinates. The function will find the closest grid points to the given coordinates and extracts the data for these points. For each point a separate output file is written. The output-files can be optional in NetCDF or csv. Input can be a single NetCDF file (given by the infile attribute) or a bunch of NetCDF files (given by the path and pattern attributes).
selpoint.multi(
var,
infile,
path,
pattern,
outpath,
lon1,
lat1,
station_names = NULL,
format = "nc",
nc34 = 4,
verbose = FALSE,
nc = NULL
)
For each pair of longitude and latitude coordinates one separate
NetCDF or csv file including the selected data is written. The csv files are
tested for use in Excel and include four columns (Time ; Data ; Longitude ;
Latitude), which are separated by ';'. If station_names are defined, the
output files will be named according to this vector. Otherwise, the output
files will be named as selpoint_longitude_latitude.format. Already existing
files will be overwritten in case that station_names are given or renamed
(e.g., selpoint1_longitude_latitude.nc
) in case that no station_names are
given.
Name of NetCDF variable (character).
Filename of input NetCDF file. This may include the directory (character). Infile is not needed if path and pattern are given.
Directory of input files (character). Will not be used if infile is given.
Pattern that all desired files in the 'path' directory have in common (character).
Directory where output files will be stored (character).
Longitude vector of desired points (numeric vector). Must
have the same length as lat1
.
Latitude vector of desired points (numeric vector). Must have
the same length as lon1
.
Optional vector of names, which will be used for the
output files (character vector). Must have the same length as
lon1
and lat1
.
Intended output format. Options are nc
or csv
. Default is
nc
(character).
NetCDF version of output file. If nc34 = 3
the output file will be
in NetCDFv3 format (numeric). Default output is NetCDFv4.
logical; if TRUE, progress messages are shown
Alternatively to infile
you can specify the input as an
object of class ncdf4
(as returned from ncdf4::nc_open
).
Other selection and removal functions:
extract.level()
,
extract.period()
,
sellonlatbox()
,
selmon()
,
selperiod()
,
selpoint()
,
seltime()
,
selyear()
## Create an example NetCDF file with a similar structure as used by CM
## SAF. The file is created with the ncdf4 package. Alternatively
## example data can be freely downloaded here:
library(ncdf4)
## create some (non-realistic) example data
lon <- seq(5, 15, 0.5)
lat <- seq(45, 55, 0.5)
time <- seq(as.Date("2000-01-01"), as.Date("2010-12-31"), "month")
origin <- as.Date("1983-01-01 00:00:00")
time <- as.numeric(difftime(time, origin, units = "hour"))
data <- array(250:350, dim = c(21, 21, 132))
## create example NetCDF
x <- ncdim_def(name = "lon", units = "degrees_east", vals = lon)
y <- ncdim_def(name = "lat", units = "degrees_north", vals = lat)
t <- ncdim_def(name = "time", units = "hours since 1983-01-01 00:00:00",
vals = time, unlim = TRUE)
var1 <- ncvar_def("SIS", "W m-2", list(x, y, t), -1, prec = "short")
vars <- list(var1)
ncnew <- nc_create(file.path(tempdir(),"CMSAF_example_file.nc"), vars)
ncvar_put(ncnew, var1, data)
ncatt_put(ncnew, "lon", "standard_name", "longitude", prec = "text")
ncatt_put(ncnew, "lat", "standard_name", "latitude", prec = "text")
nc_close(ncnew)
## Select two points of the example CM SAF NetCDF file and write the
## output to a csv-file.
selpoint.multi(var = "SIS", infile = file.path(tempdir(),"CMSAF_example_file.nc"),
outpath = tempdir(), lon1 = c(8, 9), lat1 = c(48, 49),
station_names = c("A", "B"), format = "csv")
unlink(c(file.path(tempdir(),"CMSAF_example_file.nc"), file.path(tempdir(),"A.csv"),
file.path(tempdir(),"B.csv")))
Run the code above in your browser using DataLab