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

后端 未结 3 1666
北海茫月
北海茫月 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:51

    Here's how I would proceed to do this with ncdf:

    library(ncdf)
    obsdata = open.ncdf("obs1.nc")
    obsdatadates = as.Date(obsdata$dim$time$vals,origin = '1950-01-01')
    #Get the whole data first
    obsoutput = get.var.ncdf(obsdata, varid = 'tasmin')
    #Prepare your points of interest
    points_of_interest = data.frame(lat=seq(1,8,by=2),lon=c(1,5,3,6))
    #Subset your data accordingly
    data_at_point = apply(points_of_interest,1,function(x)obsoutput[x[1],x[2],])
    #Turn it into a dataframe
    data_at_point = as.data.frame(data_at_point)
    #Add the dates to the dataframe
    data_at_point$Date = obsdatadates
    

提交回复
热议问题