从较大的栅格堆栈创建许多光栅堆栈子集

时间:2017-09-24 21:05:15

标签: r raster

难以概念化这一个。我目前有一个netcdf文件,其中包含1979-2016的月度气候平均值。我想从这个较大的光栅堆栈中制作单独的年度光栅堆栈(即从1个光栅堆栈到38个)。我不能为我的生活弄清楚这一点。任何建议都会很棒!数据可在此处找到:http://nimbus.cos.uidaho.edu/abatz/DATA/vpd19792016.nc

我到目前为止所做的工作如下:

  library(raster)
  library(lubridate)
  library(rgdal)
  library(tidyverse)
  library(tools)

  file = "../data/raw/climate/aet_19792016.nc" 
  file_split <- file %>%
    basename %>%
    strsplit(split = "_") %>%
    unlist
  var <- file_split[1]
  year <- substr(file_split[2], start = 1, stop = 4)
  endyear <- substr(file_split[2], start = 5, stop = 8)

  start_date <- as.Date(paste(year, "01", "01", sep = "-"))
  end_date <- as.Date(paste(ifelse(year == endyear, year, endyear), "12", "31", sep = "-"))
  date_seq <- seq(start_date, end_date, by = "1 month")
  month_seq <- month(date_seq)

  nc <- nc_open(file)
  nc_att <- attributes(nc$var)$names
  ncvar <- ncvar_get(nc, nc_att)
  tvar <- aperm(ncvar, c(3,2,1))
  proj <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0 "

  raster <- brick(tvar, crs= proj)
  extent(raster) <- c(-124.793, -67.043, 25.04186, 49.41686)
  names(raster) <- paste(var, year(date_seq),
                                     unique(month(date_seq, label = TRUE)),
                                     sep = "_")
  unstack(raster)

提前感谢任何建议!

1 个答案:

答案 0 :(得分:1)

首先,您必须根据futureResult.map { res => obj2.result = res :: obj2.result obj2 } Years正确命名栅格堆栈:

months