[R-sig-Geo] raster - units assignment error in reading NetCDF4

Alexandre Castagna @|ex@ndre@c@@t@gn@ @end|ng |rom gm@||@com
Tue Apr 30 12:43:12 CEST 2019


Hi group,

I'm trying to read a NetCDF4 file, but I get the following error message:

fl <- 'L8_OLI_2017_03_18_00_09_19_093086_L2R.nc'
r <- raster(fl, varname = 'rhos_443')

Error in (function (cl, name, valueClass)  :
  assignment of an object of class “numeric” is not valid for @‘unit’ in an
object of class “.SingleLayerData”; is(value, "character") is not TRUE

This data is OLI Landsat 8 atmospheric 'corrected' imagery with the ACOLITE
software (link <https://github.com/acolite/acolite>).
In a previous version of the software, exploring the file after nc_open
function revealed that units was numeric ('num' qualifier was shown in R
object print); but since, the developer has committed a change for all
units to be written as characters. The unit in question is '1' (unitless,
for bihemispherical reflectance). A new exploration after the update to
check the units type does not show the qualifier 'num' anymore, but the
error keep the same. Maybe R is translating '1' to 1 automatically?

I can go around and create a raster directly from data read with ncdf4
package, like:

ncfl <- nc_open(fl)
r     <- raster(t(ncvar_get(ncfl, 'rhos_443')))

But for a number of reasons that is less ideal. A temporary link to
download the example data file is: https://we.tl/t-nENAV7tmBg

Kind regards,

Alexandre Castagna Mourão e Lima

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list