【问题标题】:Regarding extraction of data from multiple cordiantes of multiple nc files and merge to a single raster关于从多个 nc 文件的多个坐标中提取数据并合并到单个栅格
【发布时间】:2020-06-22 15:29:08
【问题描述】:

我一年有 365 个 .nc 文件,每个文件都包含一天的土壤水分信息。我想从三个不同的坐标中提取土壤水分信息,并将它们写入给定年份的三个 csv 文件。目前,我能够将所有 365 .nc 文件转换为 365 csv 文件,如附加代码中给出的。下一步怎么走?

rm(list = ls())
library(raster)
library(ncdf4)
ptf <- "D://SMOS_ECV_SM//SMOS_ECV_SM//ECV_SM_Data_1978_2010//1978"
setwd(ptf) # change your working directory
lf <- list.files(pattern="[.]nc$") # list of files ending in .nc
for(i in lf){
  nc.brick <- brick(i)
  nc.df <- as.data.frame(nc.brick[[1]], xy=T)
  write.csv(nc.df, sub("[.]nc$",".csv",i)) # write to the same file name substituting .nc to .csv
}

【问题讨论】:

    标签: r loops r-raster netcat


    【解决方案1】:

    您应该能够执行以下操作

    library(raster)
    ptf <- "D://SMOS_ECV_SM//SMOS_ECV_SM//ECV_SM_Data_1978_2010//1978"
    ff <- list.files(path=ptf, pattern="[.]nc$", full.names=TRUE)
    
    s <- stack(ff)
    points <- rbind(c(0,1), c(100,120), c(80,5))
    v <- extract(s, points)
    
    for (i in 1:ncol(v)) {
      write.csv(v[,i,drop=FALSE], paste0("file", i, ".csv"))
    }
    

    【讨论】:

    • 我收到以下错误。 if (is.na(get("has_proj_def.dat", envir = .RGDAL_CACHE))) { : 参数长度为零另外:警告消息:在 .varName(nc, varname, warn = warn) : varname used is: sm 如果不正确,可以将其设置为以下之一:sm、sm_noise、flag、sensor
    猜你喜欢
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 2021-10-05
    相关资源
    最近更新 更多