1

I would like to extract the time series from a NetCDF file for several points (lat, lon, combinations). How could I do that, so that the lat lon values are read each time from a .csv file?

1 Answer 1

2

In short,

library(raster)
b <- brick("myncfile.nc", varname = "myvar_in_myncfile")

pts <- read.csv("my_csvfile.csv", stringsAsFactors = FALSE)

ts <- extract(b, cbind(pts$lon, pts$lat))

That will give a n-pts * n-time-steps matrix with the extracted values, assuming your NetCDF variable is oriented (lon, lat, time).

But this is just code-guessing, since we have no details about your file/s. You can give a lot of detail by doing

print(b)
print(raster("myncfile.nc"))  ## provides the ncdump -h print

and telling us the contents. obviously you need to insert your actual file names, and variable name, and column names as appropriate.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.