0

我正在尝试从 ftp 打开一个 bz2 压缩的 netcdf 文件,但无法正常工作。任何帮助深表感谢。

我尝试使用以下方法直接打开它:

url <- 'ftp://podaac-ftp.jpl.nasa.gov/allData/ghrsst/data/L4/GLOB/NCDC/AVHRR_OI/1982/001/19820101-NCDC-L4LRblend-GLOB-v01-fv02_0-AVHRR_OI.nc.bz2'
nc_open(url)

但这不起作用(我得到:) Error in R_nc4_open: No such file or directory。我猜是因为压缩,所以我尝试先下载文件并解压缩。

temp <- tempfile()
download.file(url,temp)
nc_open(bzfile(temp, '19820101-NCDC-L4LRblend-GLOB-v01-fv02_0-AVHRR_OI.nc', 'rb'))

但这也不起作用,我同时收到错误和警告:

Error in bzfile(temp, "19820101-NCDC-L4LRblend-GLOB-v01-fv02_0-AVHRR_OI.nc",  : 
  cannot open the connection
In addition: Warning message:
In bzfile(temp, "19820101-NCDC-L4LRblend-GLOB-v01-fv02_0-AVHRR_OI.nc",  :
  cannot open bzip2-ed file '/var/folders/hs/k9t_8wxs2hn48qq4vp_7xmgm0000gn/T//Rtmpv9UIBr/filef5659606aee', probable reason 'Invalid argument'

有任何想法吗?

谢谢

4

1 回答 1

2

这似乎按您希望的方式工作:

library(ncdf4)
library(R.utils)

URL <- "ftp://podaac-ftp.jpl.nasa.gov/allData/ghrsst/data/L4/GLOB/NCDC/AVHRR_OI/1982/001/19820101-NCDC-L4LRblend-GLOB-v01-fv02_0-AVHRR_OI.nc.bz2"
bzfil <- basename(URL)
if (!file.exists(bzfil)) download.file(URL, bzfil)

fil <- bunzip2(bzfil, overwrite=TRUE, remove=FALSE)

nc <- nc_open(fil)
summary(nc)

##             Length Class  Mode     
## filename    1      -none- character
## writable    1      -none- logical  
## id          1      -none- numeric  
## safemode    1      -none- logical  
## format      1      -none- character
## is_GMT      1      -none- logical  
## groups      1      -none- list     
## fqgn2Rindex 1      -none- list     
## ndims       1      -none- numeric  
## natts       1      -none- numeric  
## dim         3      -none- list     
## unlimdimid  1      -none- numeric  
## nvars       1      -none- numeric  
## var         4      -none- list 
于 2016-07-30T17:40:43.423 回答