2

我正在尝试从简单海洋数据同化 (SODA) 2.2.4 访问 NetCDF 文件。我想将它们下载为栅格图层,包含温度、年份、深度、纬度和经度数据。

这些文件位于 DOD(分布式海洋数据系统)/OPeNDAP 中,因为它们太大而无法作为 netcdf 文件下载。我以前没有使用过这种格式,因为我一直都能下载 .nc 文件。在该站点上,它说我应该能够像使用 R 脚本中的 .nc 文件一样使用此链接,以便转换为栅格图层并下载。但是,当我尝试这样做时,它失败了。但是,我可以在 R 中查看有关文件的属性,如下所示。

url_grid <- "http://iridl.ldeo.columbia.edu/SOURCES/.CARTON-GIESE/.SODA/.v2p2p4/.temp/time/%28Jan%201953%29%28Dec%201979%29RANGEEDGES/lat/%280N%29%2889.5N%29RANGEEDGES/lon/%28-200E%29%2820E%29RANGEEDGES/dods"

nc <- nc_open(url_grid)

nc

File http://iridl.ldeo.columbia.edu/SOURCES/.CARTON-GIESE/.SODA/.v2p2p4/.temp/time/%28Jan%201953%29%28Dec%201979%29RANGEEDGES/lat/%280N%29%2889.5N%29RANGEEDGES/lon/%28-200E%29%2820E%29RANGEEDGES/dods (NC_FORMAT_CLASSIC):

     1 variables (excluding dimension variables):
        float temp[lon,lat,depth,time]   
            pointwidth: 1
            missing_value: -9.98999971057742e+33
            standard_name: sea_water_temperature
            units: Celsius_scale
            long_name: TEMPERATURE

     4 dimensions:
        depth  Size:40
            gridtype: 0
            units: meters
        lat  Size:179
            standard_name: latitude
            pointwidth: 0.5
            gridtype: 0
            units: degree_north
        lon  Size:440
            standard_name: longitude
            pointwidth: 0.5
            gridtype: 0
            units: degree_east
        time  Size:324
            standard_name: time
            pointwidth: 1
            calendar: 360
            gridtype: 0
            units: months since 1960-01-01

    1 global attributes:
        Conventions: IRIDL

#This function reads out data from a typical netcdf I have downloaded (I've used this and it works great for .nc files)
get.soda <- function(file){

  soda.info <- nc_open(file)
  name.soda.sizes <- sapply(soda.info$var$temp$dim, function(x)x$name)
  soda.sizes <- soda.info$var$temp$size
  dim.units <- sapply(soda.info$var$temp$dim, function(x)x$units)
  print(dim.units)
  stopifnot(grepl("months since ", dim.units[4])) # make sure time is in correct units and in right place
  names(soda.sizes) <- name.soda.sizes
  ntime <- soda.sizes["time"]
  ndepth <- soda.sizes["depth"]

  soda.time0 <- soda.info$var$temp$dim[[4]]$vals
  ref.date <- as.Date(gsub("months since ", "", dim.units[4]))
  start.before.ref <- grepl("-", soda.time0[1]) # is the first date before ref.date?
  n.month.before <- ceiling(abs(soda.time0[1])) + as.integer(start.before.ref)
  start.increment <- ifelse(start.before.ref, "-1 month", "1 month")
  time.start <- rev(seq.Date(ref.date, by=start.increment, length.out=n.month.before))[1]
  soda.time <- seq.Date(time.start, by="1 month", length.out=ntime)

  soda <- brick(file)
  names(soda) <- soda.time


  return(soda)

}
get.soda(url_grid)
[1] "degree_east"             "degree_north"           
[3] "meters"                  "months since 1960-01-01"

#I get the following error message:

Error in .local(.Object, ...) : 

Error in .rasterObjectFromFile(x, objecttype = "RasterBrick", ...) : 
  Cannot create a RasterLayer object from this file. (file does not exist)

该文件在我的计算机上不存在,但应该存在于此链接中?帮助?

4

0 回答 0