R 在打开 netcdf 文件时崩溃
R crashes while opening netcdf file
我下载了一个 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 version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
矩阵产品:默认
编辑
如果我手动下载文件,我可以打开它。所以我下载它的方式肯定有问题。有什么建议吗?
我不确定这里发生了什么,可能是 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
我怀疑这个问题与 Downloading NetCDF files with R: Manually works, download.file produces error. @Luis's suggestion there of using mode = "wb"
rather than the default of mode = "w"
was successful in avoiding nc_open()
crashes for me with R 4.0.2, RStudio 1.3.959, and ncdf 1.17. wb
tells 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")
我下载了一个 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 version 3.5.0 (2018-04-23) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1
矩阵产品:默认
编辑
如果我手动下载文件,我可以打开它。所以我下载它的方式肯定有问题。有什么建议吗?
我不确定这里发生了什么,可能是 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
我怀疑这个问题与 Downloading NetCDF files with R: Manually works, download.file produces error. @Luis's suggestion there of using mode = "wb"
rather than the default of mode = "w"
was successful in avoiding nc_open()
crashes for me with R 4.0.2, RStudio 1.3.959, and ncdf 1.17. wb
tells 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")