[R-sig-Geo] writeRaster error [Error in dim.create.ncdf(nc, d, verbose) : NA/NaN/Inf in foreign function call (arg 5)]

Robert J. Hijmans r.hijmans at gmail.com
Tue Mar 4 02:34:24 CET 2014


Aseem provided me with some more info. writeRaster fails when the
'z-value' cannot be converted to an integer. In his case:

> head(getZ(ncdata.qtr))
[1] "1950 Q1" "1950 Q2" "1950 Q3" "1950 Q4" "1951 Q1" "1951 Q2"

The work around is to change these values using the setZ function.
This has been fixed (with a warning) for the next version of the raster package.

Robert

PS. always show sessionInfo(), traceback() and do not include very
large amounts of data in your postings!


On Mon, Mar 3, 2014 at 11:00 AM, Aseem Sharma <nature.aseem at gmail.com> wrote:
> Hi,
> I am getting error(as below) when trying to write seasonal ( quarterly)
> data in netCDF.
> My data details and sample data are below.
> My code is
>
> library(raster)
> library(ncdf)
> writeRaster(ncdata.qtr,
> filename="QtrYTmax.nc",inf.rm=TRUE,na.rm=T,NaN.rm=T,format="CDF",overwrite=TRUE,verbose=T)
>
> but his gives me the error
>
> *Error in dim.create.ncdf(nc, d, verbose) : *
> *  NA/NaN/Inf in foreign function call (arg 5)*
>
> how to fix this error ?
> Data details
>> ncdata.qtr
> class       : RasterBrick
> dimensions  : 33, 49, 1617, 245  (nrow, ncol, ncell, nlayers)
> resolution  : 0.08333333, 0.08333333  (x, y)
> extent      : -122.75, -118.6667, 51.33333, 54.08333  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=longlat +datum=WGS84
> data source : in memory
> names       :      X1950.Q1,      X1950.Q2,      X1950.Q3,      X1950.Q4,
>    X1951.Q1,      X1951.Q2,      X1951.Q3,      X1951.Q4,      X1952.Q1,
>    X1952.Q2,      X1952.Q3,      X1952.Q4,      X1953.Q1,      X1953.Q2,
>    X1953.Q3, ...
> min values  : -16.365362537,  -1.802713221,  13.207888594,   0.351344078,  -
> 9.179404557,   0.165412183,  11.963329482,   0.847261630, -10.691397610,
> 1.387089575,  11.250096523,   4.754960467,  -7.522046683,  -0.010559140,
>  10.562655678, ...
> max values  :   -8.27851364,   11.63900332,   25.79347971,   11.56013953,
> -1.62892469,   12.18758037,   25.73696717,   11.55020404,   -3.60472369,
> 13.42343698,   23.57975216,   13.90885632,    1.45158215,   13.67788500,
> 23.25788837, ...
> year.qtr    : 1950 Q1, 2011 Q1 (min, max)
>
>
> Thank you,
>
> aseem
>
>
> ------------------
>
> "Namaste नमस्ते"
>
> Aseem Sharma
>
> Graduate Research Assistant
>
> Northern Hydrometeorology Group(NHG)
>
> Natural Resources and Environmental Studies Institute(NRESi)
>
> University of Northern British Columbia
>
> Prince George, BC, V2N 4Z9, Canada
>
> Tel: 250-960-5427
>
> Web: http://www.unbc.ca/
>
>
>  "All know the Way, but few actually walk it."
> "सबैको कल्याण होस् ।"
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list