[R-sig-Geo] focal.function() adds NA value to output

Alexander Brenning alexander.brenning at uwaterloo.ca
Fri Dec 20 16:07:10 CET 2013


Dear Ludwig,

the reason for this issue seems to be that the correct argument name is nodata.values, not no.data.values.

Your 'no.data.values' argument is passed on to the function specified in your 'fun' argument, i.e. 'sum', which in turn happily accepts '...' as arguments and just adds your no.data.values to the values from the moving window. focal.function doesn't cause an error because the argument is just passed on, and sum doesn't cause an error for 'unused argument' because it accepts named arguments of whatever name, as in
     sum(c(1,2,3), no.data.values=-99999)

All the best
  Alex

--
Alexander Brenning
brenning at uwaterloo.ca - T +1-519-888-4567 ext 35783
Department of Geography and Environmental Management
University of Waterloo
200 University Ave. W - Waterloo, ON - Canada N2L 3G1
UW: https://uwaterloo.ca/gem/people-profiles/alexander-brenning
Academia.edu: http://uwaterloo.academia.edu/AlexanderBrenning
LinkedIn: http://ca.linkedin.com/pub/alexander-brenning/3/242/440

________________________________________

Date: Fri, 20 Dec 2013 00:53:57 -0800 (PST)
From: Ludwig Hilger <l.hilger at ku.de>
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] focal.function() adds NA value to output
Message-ID: <1387529637959-7585417.post at n2.nabble.com>
Content-Type: text/plain; charset=UTF-8

Hello everybody,

I have an .asc file containing only 0 and 1 and I am running
focal.function() from the RSAGA package to sum these values in a moving
window. Using a 5*5 window, the values I get in the output grid do not range
between 0 and 25 but between -99999 and 99974, so evidently, the NA values
(-99999 in my case) is added to every single window output. I can not find
any explanation for this.

Appreciating you help and time,
regards,
Ludwig

*SessionInfo:*
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
LC_TIME=German_Germany.1252

attached base packages:
[1] grDevices datasets  splines   graphics  stats     tcltk     utils
methods   base

other attached packages:
 [1] lattice_0.20-23 outliers_0.14   gplots_2.12.1   rgdal_0.8-11
raster_2.1-49   sp_1.0-13       RSAGA_0.93-6    plyr_1.8
shapefiles_0.7  foreign_0.8-55  gstat_1.0-17    svSocket_0.9-55 TinnR_1.0-5
[14] R2HTML_2.2.1    Hmisc_3.12-2    Formula_1.1-1   survival_2.37-4

loaded via a namespace (and not attached):
 [1] bitops_1.0-6       caTools_1.14       cluster_1.14.4     gdata_2.13.2
grid_3.0.2         gtools_3.1.0       intervals_0.14.0   KernSmooth_2.23-10
rpart_4.1-3        spacetime_1.0-9    svMisc_0.9-69
[12] tools_3.0.2        xts_0.9-7          zoo_1.7-10

*The input grid can be found here: *
http:///www.altmuehlnet.de/~hilger/Diff_not_sig_plus.asc

*Here is my code:*

library(RSAGA)
ws <- 5

focal.function(
  in.grid = "Diff_not_sig_plus.asc",
  path = getwd(),
  fun = "sum",
  radius = (ws-1)/2,
  out.grid.prefix = paste("Diff_not_sig_plus_", ws, "mal", ws, sep = ""),
  varnames = "counts",
  is.pixel.radius = TRUE,
  valid.range = c(-10000, 10000),
  out.nodata.value = -99999,
  no.data.values = c(-99999),
  mw.to.vector = FALSE,
  mw.na.rm = TRUE,
  search.mode = "square",
  digits = 1,
  dec = ".",
  quiet = TRUE)



-----
Dipl. Geogr. Ludwig Hilger
Wiss. MA
Lehrstuhl f?r Physische Geographie
Katholische Universit?t Eichst?tt-Ingolstadt
Ostenstra?e 18
85072 Eichst?tt

Tel.: 08421-93-1180
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/focal-function-adds-NA-value-to-output-tp7585417.html
Sent from the R-sig-geo mailing list archive at Nabble.com.


_______________________________________________
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