Comments (7)
Sounds reasonable ;-) This is also trivial to change: 1775175
I guess I'll open a pull request, now.
from landscapetools.
This surely is a bug. It turns out, the values in the raster columns are actually slightly different, and the classification has problems with more than 16 significant digits.
library(raster)
#> Loading required package: sp
#> Loading required package: sp
library(NLMR)
library(landscapetools)
set.seed(2020-01-25)
r = nlm_planargradient(100, 100, direction = 90)
r2 = util_classify(r, weighting = c(0.5, 0.5))
# See where the wrong classification occurs.
# Each for col the rows should contain the same values
mat <- as.matrix(r)
mat2 <- as.matrix(r2)
mat2[58:61,50] # col 50 between rows 59 and 60.
#> [1] 2 2 1 1
mat[58:61,50] # however, the raster values are the same!
#> [1] 0.4949495 0.4949495 0.4949495 0.4949495
sprintf("%.20f", mat[58:61,50]) # OR ARE THEY?!
#> [1] "0.49494949494949502800" "0.49494949494949502800" "0.49494949494949497248"
#> [4] "0.49494949494949497248"
Created on 2020-01-25 by the reprex package (v0.3.0)
nlm_planargradient and util_classify both consider stupidly too many decimal digits and rounding errors do happen. Maybe the easiest fix would be to round to something between 6-16 digits in both, nlm_planargradient and util_classify.
from landscapetools.
Can you have a look at cf700c1 ? I'm not 100% sure if that's the way it is intended to work, but it works and throws no errors.
from landscapetools.
Great fix @bitbacchus! Thanks a lot.
I've tried the new code on several 2-classes rasters and it worked well in every case.
library(raster)
#> Loading required package: sp
library(NLMR)
library(landscapetools)
set.seed(2020-01-25)
r = nlm_planargradient(100, 100, direction = 90)
r2 = util_classify(r, weighting = c(0.5, 0.5))
freq(r2)
#> value count
#> [1,] 1 5000
#> [2,] 2 5000
plot(r)
plot(r2)
Created on 2020-01-26 by the reprex package (v0.3.0)
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 3.6.2 (2019-12-12)
#> os Fedora 31 (Workstation Edition)
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Warsaw
#> date 2020-01-26
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib
#> assertthat 0.2.1 2019-03-21 [1]
#> backports 1.1.5 2019-10-02 [1]
#> callr 3.4.0 2019-12-09 [1]
#> checkmate 1.9.4 2019-07-04 [1]
#> cli 2.0.1 2020-01-08 [1]
#> codetools 0.2-16 2018-12-24 [2]
#> crayon 1.3.4 2017-09-16 [1]
#> curl 4.3 2019-12-02 [1]
#> desc 1.2.0 2018-05-01 [1]
#> devtools 2.2.1 2019-09-24 [1]
#> digest 0.6.23 2019-11-23 [1]
#> ellipsis 0.3.0 2019-09-20 [1]
#> evaluate 0.14 2019-05-28 [1]
#> fansi 0.4.1 2020-01-08 [1]
#> fs 1.3.1 2019-05-06 [1]
#> glue 1.3.1 2019-03-12 [1]
#> highr 0.8 2019-03-20 [1]
#> htmltools 0.4.0 2019-10-04 [1]
#> httr 1.4.1 2019-08-05 [1]
#> knitr 1.27 2020-01-16 [1]
#> landscapetools * 0.6.1 2020-01-26 [1]
#> lattice 0.20-38 2018-11-04 [2]
#> magrittr 1.5 2014-11-22 [1]
#> memoise 1.1.0 2017-04-21 [1]
#> mime 0.8 2019-12-19 [1]
#> NLMR * 1.0 2020-01-23 [1]
#> pkgbuild 1.0.6 2019-10-09 [1]
#> pkgload 1.0.2 2018-10-29 [1]
#> prettyunits 1.1.0 2020-01-09 [1]
#> processx 3.4.1 2019-07-18 [1]
#> ps 1.3.0 2018-12-21 [1]
#> R6 2.4.1 2019-11-12 [1]
#> raster * 3.0-11 2020-01-19 [1]
#> Rcpp 1.0.3 2019-11-08 [1]
#> remotes 2.1.0 2019-06-24 [1]
#> rlang 0.4.3.9000 2020-01-26 [1]
#> rmarkdown 2.0 2019-12-12 [1]
#> rprojroot 1.3-2 2018-01-03 [1]
#> sessioninfo 1.1.1 2018-11-05 [1]
#> sp * 1.3-2 2019-11-07 [1]
#> stringi 1.4.5 2020-01-11 [1]
#> stringr 1.4.0 2019-02-10 [1]
#> testthat 2.3.1 2019-12-01 [1]
#> usethis 1.5.1 2019-07-04 [1]
#> withr 2.1.2 2018-03-15 [1]
#> xfun 0.12 2020-01-13 [1]
#> xml2 1.2.2 2019-08-09 [1]
#> yaml 2.2.0 2018-07-25 [1]
#> source
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> Github (ropensci/landscapetools@cf700c1)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.1)
#> Github (rspatial/raster@4988ed0)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.0)
#> Github (r-lib/rlang@d606eaa)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.1)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.2)
#> CRAN (R 3.6.0)
#> CRAN (R 3.6.0)
#>
#> [1] /home/jn/R/x86_64-redhat-linux-gnu-library/3.6
#> [2] /usr/lib64/R/library
#> [3] /usr/share/R/library
from landscapetools.
There is one difference though - the new raster has factor values (not numeric).
from landscapetools.
There is one difference though - the new raster has factor values (not numeric).
Isn't that what we want? The values are classes, after all.
from landscapetools.
Hmm... I can think of two reasons against it:
- It was numeric previously, therefore it is a breaking change
- (My opinion) Factor rasters (from the raster package) are not greatly supported, and users can have issues operating on them
from landscapetools.
Related Issues (20)
- util_facetplot color scales HOT 1
- landscapetools 0.5 HOT 16
- Generate neutral landscapes that match exactly the extent (non-NA cells) of another raster HOT 10
- Share plots HOT 9
- Issues with `show_landscape()` for categorical rasters HOT 4
- long - wide option for raster2tibble HOT 1
- Build failure HOT 4
- show_landscape coloring bug with ratified raster
- CRAN HOT 2
- show_shareplot function cannot be found HOT 2
- How to define the order of the rasters shown with `show_landscape()`? HOT 3
- Support for terra HOT 9
- `util_extract_multibuffer` as a separate function HOT 10
- Re-add continuous integration workflows? HOT 5
- Fix pkgdown configuration for reference HOT 2
- random % with corresponding % from real landscape HOT 8
- Discrepancy in the `util_classify()` docs HOT 1
- white space
- util_facetplot + raster names
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from landscapetools.