1

I would like to display the NDVI parameter with R and subsequently extract the values of this parameter in each region.

My file is in NetCDF (.nc) format downloaded under the following link: https://www.ncei.noaa.gov/data/avhrr-land-normalized-difference-vegetation-index/access/1981/

So I imported the first file as "AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc" under R using the two packages "raster" and "ncdf4" from the following code:

library(ncdf4) 
library(raster) 
setwd("path/.../data")
r=raster("AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc",varname="NDVI")

But when apply my programme I get this error :

Error in CRS(as.character(projection(crs))) : 
  no arguments in initialization list

I choose the name of my variable ("NDVI") from the code below. I think the problem is in the format of the coordinate system!

library(ncdf4)    
nc <- nc_open("AVHRR-Land_v005_AVH13C1_NOAA-07_19810624_c20170610041337.nc")
attributes(nc$var)$names

Do you have a solution for this problem!

Thank you in advance

My R version and my System PC :

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)

EDIT

Thank you Robert Hijmans for your answer (below answer).

I updated the packages (error messages when updating some packages)

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

and applied your code but I still get the same error.

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 
tazrart
  • 167
  • 1
  • 15

1 Answers1

0

Download the file

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")

With R 3.6.2 and updated packages, I get:

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 

Can you please run update.packages(ask=F) and try again? If it still fails, can you show the traceback() after the error occurs, and also your sessionInfo()?

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Thank you Robert Hijmans for you answer. Even if I updated the packages (there are some errors) I still get the same error. see in the "edit" part (in my question above) the information obtained with the two commands traceback() and sessionInfo() – tazrart Jan 24 '20 at 13:44