[R-sig-Geo] writeRaster does not preserve names when writing to NetCDF
dschneiderch
Dominik.Schneider at colorado.edu
Fri Feb 6 18:32:14 CET 2015
I was running into this problem and wondering if there was any progress?
As a workaround, I was trying to add an attribute to my variable using
ncput_att but it doesn't show more than 1 (no warning was shown that only 1
could be accepted and the min/max attributes have a value for each layer).
r=raster(matrix(runif(9),nrow=3))
r2=raster(matrix(runif(9),nrow=3))
s=stack(r,r2)
names(s)=c('X20120101','X20120108')
writeRaster(s,filename='~/Desktop/test.nc', format='CDF', varname='swe',
varunit='meters', xname='long', xunit='deg', yname='lat', yunit='deg',
zname='time', zunit='day', overwrite=T, NAflag=-99)
#Note the names of the written stack are generic.
#Now I try to add an attribute to the swe variable in the file so I can
retrieve later but it only lists the first name
n=nc_open('~/Desktop/test.nc',write=T)
ncatt_put(n,varid='swe',attname='dates',attval=names(s),prec='text')
nc_close(n)
nc_open('~/Desktop/test.nc',write=F)
File ~/Desktop/test.nc (NC_FORMAT_CLASSIC):
1 variables (excluding dimension variables):
float swe[long,lat,time]
units: meters
_FillValue: -99
missing_value: -99
long_name: swe
min: 0.0572868520393968
min: 0.1845921901986
max: 0.852122258627787
max: 0.772868746891618
dates: X20120101
3 dimensions:
long Size:3
units: degrees_east
long_name: long
lat Size:3
units: degrees_north
long_name: lat
time Size:2 *** is unlimited ***
units: day
long_name: time
3 global attributes:
Conventions: CF-1.4
created_by: R, packages ncdf and raster (version 2.3-24)
date: 2015-02-06 10:18:51
Could that be a bug in ncatt_put? Or, are there any suggestions for storing
irregular spatial-temporal data (consistent spatial grid, but inconsistent
time slices that therefore require some annotation about the date)
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeRaster-does-not-preserve-names-when-writing-to-NetCDF-tp7586909p7587744.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list