Extract time series of a point ( lon, lat) from netCDF in R

后端 未结 3 1677
北海茫月
北海茫月 2020-12-17 03:43

I am relatively new on R. I am trying to get time series of different points ( lat, lon) of temperature data from a netCDF file. My sample data file is here and here is the

3条回答
  •  渐次进展
    2020-12-17 03:52

    Perhaps use the raster package, this won't work for all NetCDF files but it does for yours:

    library(raster)
    ## brick reads all 22280 layers
    r <- brick("obs.nc", varname = "tasmin")
    ## extract works for all time steps
    vals <- extract(r, matrix(c(-120, 52.5), ncol = 2))
    
    dim(vals)
    ## [1]     1 22280
    

    Note that gives a 1-row, many column matrix because I only gave a single point to extract().

    (The extraction is simple with direct copy from the nearest cell, use method = "bilinear" to do interpolation). See ?extract for other options.

提交回复
热议问题