我想用 R 显示 NDVI 参数,然后在每个区域中提取此参数的值。
我的文件是NetCDF(.nc(格式,通过以下链接下载:https://www.ncei.noaa.gov/data/avhrr-land-normalized-difference-vegetation-index/access/1981/
因此,我使用以下代码中的两个包"raster"和"ncdf4"将第一个文件导入R下的"AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc":
library(ncdf4)
library(raster)
setwd("path/.../data")
r=raster("AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc",varname="NDVI")
但是当应用我的程序时,我收到此错误:
Error in CRS(as.character(projection(crs))) :
no arguments in initialization list
我从下面的代码中选择变量的名称("NDVI"(。我认为问题出在坐标系的格式上!
library(ncdf4)
nc <- nc_open("AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc")
attributes(nc$var)$names
你有解决这个问题的方法吗!
提前谢谢你
我的R版本和我的系统电脑:
R version 3.6.2 (2019-12-12)
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
编辑
谢谢罗伯特·希曼斯的回答(下面的答案(。
我更新了软件包(更新某些软件包时出现错误消息(
update.packages(ask=F)
Warning: package 'BH' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'callr' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'cli' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'DT' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'fansi' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'farver' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'gh' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'mime' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'pillar' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'plyr' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'prettyunits' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'stringi' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'vctrs' in library '/usr/local/lib/R/site-library' will not be updated
Warning: package 'foreign' in library '/usr/lib/R/library' will not be updated
并应用了您的代码,但我仍然收到相同的错误。
r <- raster(f, varname="NDVI")
Error in CRS(as.character(projection(crs))) :
no arguments in initialization list.
traceback()
No traceback available .
sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ncdf4_1.17 raster_3.0-7 sp_1.3-2
loaded via a namespace (and not attached):
[1] compiler_3.6.2 rgdal_1.4-8 tools_3.6.2 yaml_2.2.0 Rcpp_1.0.3 codetools_0.2-16
[7] grid_3.6.2 lattice_0.20-38
下载文件
url <- "https://www.ncei.noaa.gov/data/avhrr-land-normalized-difference-vegetation-index/access/1981/"
f <- "AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc"
if (!file.exists(f)) download.file(file.path(url, f), f, mode="wb")
使用 R 3.6.2 和更新的软件包,我得到:
library(raster)
#Loading required package: sp
r <- raster(f, varname="NDVI")
#Loading required namespace: ncdf4
r
#class : RasterLayer
#dimensions : 3600, 7200, 25920000 (nrow, ncol, ncell)
#resolution : 0.05, 0.05 (x, y)
#extent : -180, 180, -89.99999, 90 (xmin, xmax, ymin, ymax)
#crs : +init=EPSG:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
#source : AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc
#names : NOAA.Climate.Data.Record.of.Normalized.Difference.Vegetation.Index
#z-value : 1981-06-24
#zvar : NDVI
你能update.packages(ask=F)
运行并重试吗?如果仍然失败,您能否显示错误发生后的traceback()
以及您的sessionInfo()
?