Code Monkey home page Code Monkey logo

trafficalmr's Issues

Error with osm_consolidate

Heads-up @mem48 there is an error when I run this function:

(Heads-up also @joeytalbot sorry for being slow on this!)

region_name = "Isle of Wight"
> # region_name = "Greater London" # test for London
> osm = osmextract::oe_get(region_name)
> osm = osm_main_roads(osm)
> osm = sf::st_transform(osm, 27700)
> osm = osm_consolidate(osm)
 Error in `[.data.frame`(x, i, j, drop = drop) : 
  undefined columns selected 

segment argument in osm_consolidate does not work as expected

The docs say:

#' @param segment numeric, max length of segments in metres

This implies that longer segments will results in fewer output objects.
However, the opposite is true, as shown below on the osm_cleaning branch:

> nrow(x) / nrow(osm_consolidated)
[1] 1.258448
> osm_consolidated_1000m = osm_consolidate(x, segment = 1000)
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=00s  
Warning message:
In st_cast.sf(xmlsB, "LINESTRING") :
  repeating attributes for all sub-geometries for which they may not be constant
> nrow(x) / nrow(osm_consolidated_1000m)
[1] 1.408046
> osm_consolidated_200m = osm_consolidate(x, segment = 200)
  |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02s  
Warning message:
In st_cast.sf(xmlsB, "LINESTRING") :
  repeating attributes for all sub-geometries for which they may not be constant
> nrow(x) / nrow(osm_consolidated_200m)
[1] 0.8423815

Was this intended @mem48 ? seems like a bug to me.

tc_join_stats19 should be more flexible

It should be able to return data at the casualty level. Example below:

remotes::install_github("saferactive/trafficalmr")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'trafficalmr' from a github remote, the SHA1 (bce0785a) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(trafficalmr)
nrow(crashes_wf)
#> [1] 3449
nrow(casualties_wf)
#> [1] 4245
crash_summary = tc_join_stats19(crashes_wf, casualties_wf, vehicles_wf)
#> Joining, by = "accident_index"
nrow(crash_summary)
#> [1] 3449

Created on 2020-07-17 by the reprex package (v0.3.0)

Time to check package...

On local desktop it takes almost a minute to run, although it's 40% faster on a remote server it's still on the slow side:

  • Local: 45.943 s
  • Remote: 33.84 s
system.time(devtools::check("~/saferactive/trafficalmr/"))
#> Updating trafficalmr documentation
#> Loading trafficalmr
#> Writing NAMESPACE
#> Writing NAMESPACE
#> ── Building ──────────────────────────────────────────────────────────────── trafficalmr ──
#> Setting env vars:
#> ● CFLAGS    : -Wall -pedantic
#> ● CXXFLAGS  : -Wall -pedantic
#> ● CXX11FLAGS: -Wall -pedantic
#> ───────────────────────────────────────────────────────────────────────────────────────────
#>      checking for file ‘/mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/orgs/saferactive/trafficalmr/DESCRIPTION’ ...  ✔  checking for file ‘/mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/orgs/saferactive/trafficalmr/DESCRIPTION’
#>   ─  preparing ‘trafficalmr’: (3.4s)
#>      checking DESCRIPTION meta-information ...  ✔  checking DESCRIPTION meta-information
#>   ─  installing the package to build vignettes
#>      creating vignettes ...  ✔  creating vignettes (12.2s)
#>   ─  checking for LF line-endings in source and make files and shell scripts
#>   ─  checking for empty or unneeded directories
#>   ─  building ‘trafficalmr_0.1.0.tar.gz’
#>      
#> ── Checking ──────────────────────────────────────────────────────────────── trafficalmr ──
#> Setting env vars:
#> ● _R_CHECK_CRAN_INCOMING_USE_ASPELL_: TRUE
#> ● _R_CHECK_CRAN_INCOMING_REMOTE_    : FALSE
#> ● _R_CHECK_CRAN_INCOMING_           : FALSE
#> ● _R_CHECK_FORCE_SUGGESTS_          : FALSE
#> ● NOT_CRAN                          : true
#> ── R CMD check ─────────────────────────────────────────────────────────────────
#> * using log directory ‘/tmp/RtmpXDmJzP/trafficalmr.Rcheck’
#> * using R version 4.0.2 (2020-06-22)
#> * using platform: x86_64-pc-linux-gnu (64-bit)
#> * using session charset: UTF-8
#> * using options ‘--no-manual --as-cran’
#> * checking for file ‘trafficalmr/DESCRIPTION’ ... OK
#> * checking extension type ... Package
#> * this is package ‘trafficalmr’ version ‘0.1.0’
#> * package encoding: UTF-8
#> * checking package namespace information ... OK
#> * checking package dependencies ... OK
#> * checking if this is a source package ... OK
#> * checking if there is a namespace ... OK
#> * checking for executable files ... OK
#> * checking for hidden files and directories ... OK
#> * checking for portable file names ... OK
#> * checking for sufficient/correct file permissions ... OK
#> * checking whether package ‘trafficalmr’ can be installed ... OK
#> * checking installed package size ... NOTE
#>   installed size is  6.2Mb
#>   sub-directories of 1Mb or more:
#>     doc   5.6Mb
#> * checking package directory ... OK
#> * checking for future file timestamps ... NOTE
#> unable to verify current time
#> * checking ‘build’ directory ... OK
#> * checking DESCRIPTION meta-information ... OK
#> * checking top-level files ... OK
#> * checking for left-over files ... OK
#> * checking index information ... OK
#> * checking package subdirectories ... OK
#> * checking R files for non-ASCII characters ... OK
#> * checking R files for syntax errors ... OK
#> * checking whether the package can be loaded ... OK
#> * checking whether the package can be loaded with stated dependencies ... OK
#> * checking whether the package can be unloaded cleanly ... OK
#> * checking whether the namespace can be loaded with stated dependencies ... OK
#> * checking whether the namespace can be unloaded cleanly ... OK
#> * checking loading without being on the library search path ... OK
#> * checking dependencies in R code ... OK
#> * checking S3 generic/method consistency ... OK
#> * checking replacement functions ... OK
#> * checking foreign function calls ... OK
#> * checking R code for possible problems ... OK
#> * checking Rd files ... OK
#> * checking Rd metadata ... OK
#> * checking Rd line widths ... OK
#> * checking Rd cross-references ... OK
#> * checking for missing documentation entries ... OK
#> * checking for code/documentation mismatches ... OK
#> * checking Rd \usage sections ... OK
#> * checking Rd contents ... OK
#> * checking for unstated dependencies in examples ... OK
#> * checking contents of ‘data’ directory ... OK
#> * checking data for non-ASCII characters ... OK
#> * checking data for ASCII and uncompressed saves ... OK
#> * checking installed files from ‘inst/doc’ ... OK
#> * checking files in ‘vignettes’ ... OK
#> * checking examples ... OK
#> * checking for unstated dependencies in ‘tests’ ... OK
#> * checking tests ...
#>   Running ‘skip-download.R’
#>   Running ‘testthat.R’
#>  OK
#> * checking for unstated dependencies in vignettes ... OK
#> * checking package vignettes in ‘inst/doc’ ... OK
#> * checking re-building of vignette outputs ... OK
#> * checking for non-standard things in the check directory ... OK
#> * checking for detritus in the temp directory ... OK
#> * DONE
#> 
#> Status: 2 NOTEs
#> See
#>   ‘/tmp/RtmpXDmJzP/trafficalmr.Rcheck/00check.log’
#> for details.
#>    user  system elapsed 
#>  24.942   4.580  45.943

Created on 2020-09-22 by the reprex package (v0.3.0)

tc_upset bug

Casualties or vehicles are not being properly assigned to the 'Other' category.

The figure in the function help example has lots of accidents with lone pedestrians or with lone cyclists. This isn't correct. Instead these crashes should probably be 'pedestrian + other' and 'cyclist + other.'

remotes::install_github("saferactive/trafficalmr")
library(trafficalmr)
remotes::install_github("krassowski/complex-upset")

crash_summary = tc_join_stats19(crashes_wf, casualties_wf, vehicles_wf)


# create plot with 'Other' category
casualties_wf2 = dplyr::mutate(
  casualties_wf,
  casualty_type_simple = dplyr::case_when(
    casualty_type == "Car occupant" ~ "Car",
    casualty_type == "Pedestrian" ~ "Pedestrian",
    casualty_type == "Cyclist" ~ "Cyclist",
    TRUE ~ "Other"
  )
)
crash_summary = tc_join_stats19(crashes_wf, casualties_wf2, vehicles_wf)
tc_upset(crash_summary, casualty_type = c("Car", "Pedestrian", "Bicycle", "Other"))

Function to recode maxspeed values from OSM

Currently maxspeed variables are all over the place. @mem48 we could integrate stuff you did on CyIPT here and make it well documented and future proof. Here's what I get for London:

summary(osm_london_highways_gf_common$maxspeed)
      10   10 mph      100  100 mph  105 mph  110 mph  115 mph   12 mph  125 mph       15   15 mph      180    2 mph       20 
       0        3        0        0        0        0        0        0        0        0        0        0        0        1 
  20 mph      225      230   25 mph      250       30   30 mph      300      320   35 mph    4 mph       40   40 mph   45 mph 
    9560        0        0        0        0       20    11220        0        0        0        0        1      924        0 
       5    5 mph       50   50 mph   55 mph       60   60 mph       64   65 mph        7   70 mph   75 mph       80   80 mph 
       0        2        0      236        0        0       62        0        0        0        2        0        0        0 
  85 mph   90 mph   95 mph national     none  signals variable     walk     NA's 
       0        0        0        1        0        6        0        0     5576 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.