我下载了netcdf文件并尝试在R中打开它。这是我的代码
download.file("https://data.giss.nasa.gov/impacts/agmipcf/agmerra/AgMERRA_1980_prate.nc4",destfile = "AgMERRA_1980_prate.nc4", method="libcurl")
我想使用R打开netcdf文件
library(ncdf4)
my.file <- nc_open("AgMERRA_1980_prate.nc4")
但是,每次我这样做,R都会崩溃。
我的代码有问题吗?还是R Studio有问题?
sessionInfo() R版本3.5.0(2018-04-23) 平台:x86_64-w64-mingw32 / x64(64位) 在以下环境中运行:Windows 7 x64(内部版本7601)Service Pack 1
Matrix产品:默认
编辑
如果我手动下载文件,则可以打开它。因此,我下载它的方式一定有问题。有什么建议吗?
答案 0 :(得分:0)
我不确定这里发生了什么,可能是Windows特定的。我尝试不带参数method="libcurl"
进行下载,但似乎可以正常工作。
download.file("https://data.giss.nasa.gov/impacts/agmipcf/agmerra/AgMERRA_1980_prate.nc4",
destfile = "AgMERRA_1980_prate.nc4")
library(ncdf4)
my.file <- nc_open("AgMERRA_1980_prate.nc4")
File AgMERRA_1980_prate.nc4 (NC_FORMAT_NETCDF4):
1 variables (excluding dimension variables):
short prate[longitude,latitude,time] (Chunking: [1440,720,1]) (Compression: level 9)
_FillValue: 32767
description: Precipitation Rate
units: mm/day
add_offset: 0
scale_factor: 0.100000001490116
vMin_original_data: 0
vMax_original_data: 457.399993896484
vRange: 457.399993896484
3 dimensions:
time Size:366 *** is unlimited ***
units: days since 1980 01-01-01 12:00:00
latitude Size:720
units: degrees_north
longitude Size:1440
units: degrees_east
4 global attributes:
history: Tue Aug 12 16:42:13 EDT 2014
source: AgMIP / Alex Ruane
title: AgMERRA v1.1 Precipitation Rate
center: NASA GISS
我的会话信息-
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
答案 1 :(得分:0)
我怀疑这个问题与Downloading NetCDF files with R: Manually works, download.file produces error重复。 @Luis建议使用mode = "wb"
而不是默认值mode = "w"
来避免R {4.0.2,RStudio 1.3.959和ncdf 1.17对我来说nc_open()
崩溃。 wb
告诉download.file()将文件视为二进制文件,与netCDF格式一致。
对于这里感兴趣的数据,应该是
download.file("https://data.giss.nasa.gov/impacts/agmipcf/agmerra/AgMERRA_1980_prate.nc4", destfile = "AgMERRA_1980_prate.nc4", method = "libcurl", mode = "wb")