有谁知道如何下载TRMM 3B42时间序列数据?

时间:2016-07-15 19:22:56

标签: r download ftp

我试图从NASA FTP server下载给定时间跨度的TRMM 3B42 3小时二进制数据。

Florian Detsch制作了一个优秀的代码,用于下载仅限GitHub Rsenal 包中的每日产品(此处为链接:https://github.com/environmentalinformatics-marburg/Rsenal/blob/master/R/downloadTRMM.R)。不幸的是,它不适用于3小时的数据。

我更改了代码:

downloadTRMM <- function(begin, end, dsn = ".", format = "%Y-%m-%d.%H") {

  ## transform 'begin' and 'end' to 'Date' object if necessary
  if (!class(begin) == "Date")
    begin <- as.Date(begin, format = format)

  if (!class(end) == "Date")
    end <- as.Date(end, format = format)

  ## trmm ftp server
  ch_url <-"ftp://disc2.nascom.nasa.gov/data/TRMM/Gridded/3B42_V7/"

  ## loop over daily sequence
  ls_fls_out <- lapply(seq(begin, end, 1), function(i) {

    # year and julian day (name of the corresponding folder)
    tmp_ch_yr <- strftime(i, format = "%Y%m")
    #tmp_ch_dy <- strftime(i, format = "%j")

    # trmm date format
    tmp_dt <- strftime(i+1, format = "%Y%m%d.%H")

    # list files available on server
    tmp_ch_url <- paste(ch_url, tmp_ch_yr, "", sep = "/")

    tmp_ch_fls <- tmp_ch_fls_out <- character(2L)
    for (j in 1:2) {
      tmp_ch_fls[j] <- paste0("3B42.", tmp_dt, "z.7.precipitation", 
                              ifelse(j == 1, ".bin"))

      tmp_ch_fls[j] <- paste(tmp_ch_url, tmp_ch_fls[j], sep = "/")
      tmp_ch_fls_out[j] <- paste(dsn, basename(tmp_ch_fls[j]), sep = "/")

      download.file(tmp_ch_fls[j], tmp_ch_fls_out[j], mode = "wb")
    }

    # return data frame with *.bin and *.xml filenames
    tmp_id_xml <- grep("xml", tmp_ch_fls_out)
    data.frame(bin = tmp_ch_fls_out[-tmp_id_xml], 
               xml = tmp_ch_fls_out[tmp_id_xml], 
               stringsAsFactors = FALSE)

  })

  ## join and return names of processed files
  ch_fls_out <- do.call("rbind",ls_fls_out)
  return(ch_fls_out)
}

getwd()

setwd("C:/Users/joaoreis/Documents/Bases_Geograficas/trmm_3h/")

fls_trmm <- downloadTRMM(begin = "2008-01-01.00", end = "2008-01-05.00")
fls_trmm

但是我收到以下错误:

  

尝试访问网址   &#39; ftp://disc2.nascom.nasa.gov/data/TRMM/Gridded/3B42_V7//200801//3B42.20080102.00z.7.precipitation.bin&#39;   download.file出错(tmp_ch_fls [j],tmp_ch_fls_out [j],mode =&#34; wb&#34;)   :无法打开网址   &#39; ftp://disc2.nascom.nasa.gov/data/TRMM/Gridded/3B42_V7//200801//3B42.20080102.00z.7.precipitation.bin&#39;   另外:警告信息:在download.file中(tmp_ch_fls [j],   tmp_ch_fls_out [j],mode =&#34; wb&#34;):InternetOpenUrl失败:&#39;&#39;叫   from:download.file(tmp_ch_fls [j],tmp_ch_fls_out [j],mode =&#34; wb&#34;)

是否有人知道如何使用R?

修复它

谢谢!

1 个答案:

答案 0 :(得分:1)

从提交909f98a开始,我已启用从ftp://disc3.nascom.nasa.gov/data/s4pa/TRMM_L3自动检索3小时数据。确保使用

安装了最新版本的 Rsenal
devtools::install_github("environmentalinformatics-marburg/Rsenal")

然后查看?downloadTRMM中的示例。目前,该功能支持character(需要&#39;格式&#39;参数传递给strptime)和POSIXlt输入。例如,像

downloadTRMM(begin = "2015-01-01 12:00", end = "2015-01-03 12:00", 
             type = "3-hourly", format = "%Y-%m-%d %H:%M")

从2015年1月1日至3日(中午至中午)下载3小时数据现在应该可以正常工作。

请注意,与您提到的FTP服务器相比,数据以.HDF格式和rasterize方法到目前为止尚未实现,这意味着您必须自己处理容器文件。关于数据的自动光栅化,我将尽快找出更方便的东西。

相关问题