[GRASS-stats] Cryptic warning when reading raster which consists only of NULL
Rainer M Krug
Rainer at krugs.de
Wed Sep 18 00:43:43 PDT 2013
Roger Bivand <Roger.Bivand at nhh.no> writes:
> Rainer,
>
> Please provide R code to generate such a raster using execGRASS() -
I tried it under 6.4 and 7 and the error occurs under both, but only
have the R code for 7 as it uses r.mapcalc:
,----
| > library(spgrass6)
| > execGRASS("r.mapcalc", expression="round(null())")
| > execGRASS("r.info", map="NULL")
| +----------------------------------------------------------------------------+
| | Layer: NULL Date: Wed Sep 18 09:36:57 2013 |
| | Mapset: asmDrak Login of Creator: rainerkrug |
| | Location: grass |
| | DataBase: /Users/rainerkrug/Documents/Projects/AlienManagementDrakensberg/ |
| | Title: ( NULL ) |
| | Timestamp: none |
| |----------------------------------------------------------------------------|
| | |
| | Type of Map: raster Number of Categories: 0 |
| | Data Type: CELL |
| | Rows: 330 |
| | Columns: 300 |
| | Total Cells: 99000 |
| | Projection: Albers Equal Area |
| | N: -70000 S: -103000 Res: 100 |
| | E: -130000 W: -160000 Res: 100 |
| | Range of data: min = NULL max = NULL |
| | |
| | Data Description: |
| | generated by r.mapcalc |
| | |
| | Comments: |
| | round(null()) |
| | |
| +----------------------------------------------------------------------------+
|
| > x <- readRAST6("NULL", useGDAL=FALSE, plugin=FALSE)
| Creating BIL support files...
| Exporting raster as integer values (bytes=4)
| 100%
| Warning messages:
| 1: In lapply(lres, as.numeric) : NAs introduced by coercion
| 2: In lapply(lres, as.numeric) : NAs introduced by coercion
| > x <- readRAST6("NULL", useGDAL=TRUE, plugin=FALSE)
| Loading required package: rgdal
| rgdal: version: 0.8-11, (SVN revision 479M)
| Geospatial Data Abstraction Library extensions to R successfully loaded
| Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24
| Path to GDAL shared files: /usr/local/Cellar/gdal/1.10.0/share/gdal
| Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
| Path to PROJ.4 shared files: (autodetected)
| Warning message:
| statistics not supported by this driver
| >
`----
It also only occurs when GDAL is not used.
It seems that the problem is the GRASS null() in CELL maps.
> I'm not sure that I can resolve this by guessing. Please also don't
> assume that posting via a newsgroup stays in thread - I'll try to
> reply using that route; the statgrass list is more appropriate anyway.
Sorry - I reposted it on statgrass.
Hope this helps,
Rainer
>
> Roger
>
> PS: [News not posted: "/usr/bin/inews -h": Error running
> "/usr/bin/inews -h"] - newsgroup not a feasible reply route - please
> revert to posting via mailing list (in gmane if you prefer).
>
>
>
> On Tue, 17 Sep 2013, Rainer M Krug wrote:
>
>> Hi
>>
>> When reading a raster from GRASS which consists only of NULL, a cryptic
>> warning is received:
>>
>> ,----
>> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
>> `----
>>
>> This is caused by the line
>>
>> ,----
>> | lres <- lapply(lres, as.numeric)
>> `----
>>
>> in the debug session below:
>>
>> ,----
>> | debug: con <- textConnection(tx)
>> | Browse[2]>
>> | debug: res <- read.dcf(con)
>> | Browse[2]>
>> | debug: close(con)
>> | Browse[2]>
>> | debug: lres <- as.list(res)
>> | Browse[2]>
>> | debug: names(lres) <- colnames(res)
>> | Browse[2]>
>> | debug: lres <- lapply(lres, as.numeric)
>> | Browse[2]>
>> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
>> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
>> | debug: if (!is.numeric(lres$min) || !is.finite(as.double(lres$min))) NODATA <- as.integer(999) else {
>> | lres$min <- floor(as.double(lres$min))
>> | NODATA <- floor(lres$min) - 1
>> | }
>> | Browse[2]> lres
>> | $min
>> | [1] NA
>> |
>> | $max
>> | [1] NA
>> |
>> | Browse[2]> tx
>> | [1] "min:NULL" "max:NULL"
>> | Browse[2]>
>> `----
>>
>> I would suggest to add thwe statements
>>
>> ,----
>> | if (lres[[1]]=="NULL") lrews[[1]] <- NA
>> | if (lres[[2]]=="NULL") lrews[[2]] <- NA
>> `----
>>
>> before the line
>>
>> ,----
>> | lres <- lapply(lres, as.numeric)
>> `----
>>
>> as this would replace the "NULL" with NA and not cause the error.
>>
>> ,----
>> | > sessionInfo()
>> | R version 3.0.1 (2013-05-16)
>> | Platform: x86_64-apple-darwin10.8.0 (64-bit)
>> |
>> | locale:
>> | [1] C
>> |
>> | attached base packages:
>> | [1] stats graphics grDevices utils datasets methods base
>> |
>> | other attached packages:
>> | [1] asmDrak_0.0-1 maptools_0.8-27 simecol_0.8-2
>> | [4] lattice_0.20-23 deSolve_1.10-7 prioritization_0.0-1
>> | [7] seedGerm_0.0-1 seedDisp_0.4-13 Rcpp_0.10.4
>> | [10] seedProd_0.0-1 fireSim_0.0-1 RSQLite_0.11.4
>> | [13] DBI_0.2-7 spgrass6_0.8-3 XML_3.95-0.2
>> | [16] sp_1.0-13 logger_0.0-1 devtools_1.3.99
>> |
>> | loaded via a namespace (and not attached):
>> | [1] RCurl_1.95-4.1 compiler_3.0.1 digest_0.6.3 evaluate_0.4.7 foreign_0.8-53
>> | [6] grid_3.0.1 httr_0.2 memoise_0.1 parallel_3.0.1 stringr_0.6.2
>> | [11] tools_3.0.1 whisker_0.3-2
>> |
>> | > version
>> | _
>> | platform x86_64-apple-darwin10.8.0
>> | arch x86_64
>> | os darwin10.8.0
>> | system x86_64, darwin10.8.0
>> | status
>> | major 3
>> | minor 0.1
>> | year 2013
>> | month 05
>> | day 16
>> | svn rev 62743
>> | language R
>> | version.string R version 3.0.1 (2013-05-16)
>> | nickname Good Sport
>> `----
>>
>> Thanks,
>>
>> Rainer
>>
>>
>>
<#secure method=pgpmime mode=sign>
roup stays in thread - I'll try to
reply using that route; the statgrass list is more appropriate anyway.
Roger
PS: [News not posted: "/usr/bin/inews -h": Error running
"/usr/bin/inews -h"] - newsgroup not a feasible reply route - please
revert to posting via mailing list (in gmane if you prefer).
On Tue, 17 Sep 2013, Rainer M Krug wrote:
> Hi
>
> When reading a raster from GRASS which consists only of NULL, a cryptic
> warning is received:
>
> ,----
> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
> `----
>
> This is caused by the line
>
> ,----
> | lres <- lapply(lres, as.numeric)
> `----
>
> in the debug session below:
>
> ,----
> | debug: con <- textConnection(tx)
> | Browse[2]>
> | debug: res <- read.dcf(con)
> | Browse[2]>
> | debug: close(con)
> | Browse[2]>
> | debug: lres <- as.list(res)
> | Browse[2]>
> | debug: names(lres) <- colnames(res)
> | Browse[2]>
> | debug: lres <- lapply(lres, as.numeric)
> | Browse[2]>
> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
> | Warning in lapply(lres, as.numeric) : NAs introduced by coercion
> | debug:
--
Rainer at krugs dot de
More information about the grass-stats
mailing list