2016-07-30 4 views
0

ftp에서 bz2 압축 netcdf 파일을 열려고하는데 작동하지 않습니다. 어떤 도움이라도 대단히 감사합니다.bz2 파일을 추출하고 Rc를 사용하여 ncdf를 엽니 다.

내가 직접 사용하여 열 시도했습니다

:

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' 

어떤 아이디어?

감사

답변

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 
관련 문제