2

I am trying to access NetCDF files from Simple Ocean Data Assimilation (SODA) 2.2.4. I want to download them as raster layers, with temp, year, depth, lat, and lon data.

The files are in DODs (Distributed Oceans Data Systems)/OPeNDAP because they are too big to download as a netcdf file. I haven't used this format before, as I've always been able to just download the .nc files. On the site, it says I should be able to just use this link as if it were a .nc file in R script in order to convert to a raster layer and download. However, when I try to do this, it fails. However, I can view attributes about the file in R, as shown below.

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)

The file does not exist on my computer, but should exist at this link? Help?

zoek
  • 141
  • 1
  • 7

0 Answers0