Error when reading netcdf (.nc) files into R: "Error, unrecognized type code of variable supplied: -1"

Viewed 106

I successfully used the below code to open a netcdf (.nc) file containing monthly Net Primary Productivity data for multiple years.

library(raster)
libarary(ncdf4)
setwd("C:/Raw data/Env/")
b <- brick('NPP_Dec2003-Mar2020.nc')
getZ(b)
class(getZ(b))
plot(b)

However, when using the same code to open a netcdf file of chlorophyll-a at 8 day resolution for a single year (downloaded from AQUA MODIS), I get the following warning:

"Error in ncvar_type_to_string(rv$precint) : Error, unrecognized type code of variable supplied: -1"

The same error shows up if I use any of the following:

file <- ("C:/Raw data/Env/chl_8d_2004.nc")
var_name <- "chlor_a"  
b <- brick(file, varname = var_name) 

or

filename <- (C:/Raw data/Env/chl_8d_2004.nc")
nc <- nc_open(filename)

or the following code from netCDF in R (https://pjbartlein.github.io/REarthSysSci/netCDF.html#reading-restructuring-and-writing-netcdf-files-in-r)

ncpath <- ("C:/Raw data/Env/")
ncname <- ("chl_8d_2007.nc")
ncfname <- paste(ncpath, ncname, "", sep="")
dname <- "chl"  
ncin <- nc_open(ncfname)
print(ncin)

Any suggestions why this might be?

If it is not possible to answer the question without the .nc files, please let me know the easiest way to share them, as I cannot find an 'attach file' option here.

Many thanks.

0 Answers
Related