Comments (4)
I created a column speed_sequence
to add the sequence of constant speed into new_stoptimes
lim0 <- which(is.na(new_stoptimes$stop_sequence)==FALSE) # start limit
lim1 <- c(tail(lim0,-1)-1,nrow(new_stoptimes)) # end limit
lim_len <- lim1-lim0 +1 # length of each limit
new_stoptimes$speed_sequence <- rep(1:length(lim0),lim_len)
# apply function for speed estimation
new_stoptimes <- new_stoptimes[,speed := {
dt = data.table::last(departure_time) - data.table::first(departure_time)
ds = data.table::last(cumdist) - data.table::first(cumdist)
v = 3.6 * ds / dt
list(v = v)
},by = speed_sequence]
See the microbenchmark
library(microbenchmark)
mbm <- microbenchmark::microbenchmark(times = 20,
'new' = { new(gtfs_data = "tests_joao/sao_small.zip",
filepath = "tests_joao/data/output/speed_test",
spatial_resolution = 15,
cores = NULL,
progress = TRUE,
continue = FALSE) },
'old' = { old(gtfs_data = "tests_joao/sao_small.zip",
filepath = "tests_joao/data/output/speed_test",
spatial_resolution = 15,
cores = NULL,
progress = TRUE,
continue = FALSE) }
)
ggplot2::autoplot(mbm)
from gtfs2gps.
I created a column
speed_sequence
to add the sequence of constant speed intonew_stoptimes
lim0 <- which(is.na(new_stoptimes$stop_sequence)==FALSE) # start limit lim1 <- c(tail(lim0,-1)-1,nrow(new_stoptimes)) # end limit lim_len <- lim1-lim0 +1 # length of each limit new_stoptimes$speed_sequence <- rep(1:length(lim0),lim_len) # apply function for speed estimation new_stoptimes <- new_stoptimes[,speed := { dt = data.table::last(departure_time) - data.table::first(departure_time) ds = data.table::last(cumdist) - data.table::first(cumdist) v = 3.6 * ds / dt list(v = v) },by = speed_sequence]See the microbenchmark
library(microbenchmark) mbm <- microbenchmark::microbenchmark(times = 20, 'new' = { new(gtfs_data = "tests_joao/sao_small.zip", filepath = "tests_joao/data/output/speed_test", spatial_resolution = 15, cores = NULL, progress = TRUE, continue = FALSE) }, 'old' = { old(gtfs_data = "tests_joao/sao_small.zip", filepath = "tests_joao/data/output/speed_test", spatial_resolution = 15, cores = NULL, progress = TRUE, continue = FALSE) } ) ggplot2::autoplot(mbm)
This looks great. Could you please try this code? Not as elegant, but perhaps faster
# apply function for speed estimation
new_stoptimes <- new_stoptimes[, speed :=
3.6 * (data.table::last(cumdist) - data.table::first(cumdist)) / (data.table::last(departure_time) - data.table::first(departure_time)),
by = speed_sequence]
from gtfs2gps.
Your suggestion is the object new
, while the previous is old
It changes very little on average, but I think it should simplify the code...
library(microbenchmark)
mbm <- microbenchmark::microbenchmark(times = 50,
'new' = { gtfs2gps02(gtfs_data = "tests_joao/sao_small.zip",
filepath = "tests_joao/data/output/speed_test",
spatial_resolution = 15,
cores = NULL,
progress = TRUE,
continue = FALSE) },
'old' = { gtfs2gps01(gtfs_data = "tests_joao/sao_small.zip",
filepath = "tests_joao/data/output/speed_test",
spatial_resolution = 15,
cores = NULL,
progress = TRUE,
continue = FALSE) }
)
mbm
# Unit: milliseconds
# expr min lq mean median uq max neval cld
# new 153.9255 163.1745 171.1754 169.5541 174.6480 241.4118 50 a
# old 154.2710 160.4996 173.3043 166.2644 174.8794 335.7276 50 a
ggplot2::autoplot(mbm)
from gtfs2gps.
I've made the following change to the function script gtfs2gps
(line 88). It was taking too much time to convert 'segmentized' shape into points. I've used a new approach based on sfheaders
which is considerably faster.
# old (slower) version
new_shape <- subset(shapes_sf, shape_id == shapeid) %>%
sf::st_segmentize(spatial_resolution) %>%
sf::st_cast("LINESTRING") %>%
sf::st_cast("POINT", warn = FALSE) %>%
sf::st_sf()
# new faster verion using sfheaders
new_shape <- subset(shapes_sf, shape_id == shapeid) %>%
sf::st_segmentize(spatial_resolution) %>%
sfheaders::sf_to_df(fill = T) %>%
sfheaders::sf_point( x = "x", y="y", keep = T)
With this, I believe we've checked all the boxes in this issue. I'm closing this issue for now, but we'll likely other issues in the future to improve the package performance even further.
from gtfs2gps.
Related Issues (20)
- should gtfs2gps includes as gtfs class, such as gtfstools? HOT 9
- gtfs2gps::gtfs2gps not processing transport network sf object HOT 4
- example of adjust_speed function not working HOT 1
- writing a merged gtfs list got: 'gtfs' must inherit from the 'gtfs' class HOT 2
- gtfs2gps::gtfs2gps function not exporting file with proper units
- incompatibility with gtfstools HOT 1
- Vignette link does not work HOT 1
- Check performance of using gtfstools::string_to_seconds() HOT 2
- adjust_speed approach HOT 2
- Add `progress` parameter to gtfs2gps HOT 1
- New silent parameter to gtfs2gps()
- gtfs2gps function changing input parameter by reference HOT 1
- 'speed' values are NA , but not really HOT 3
- problems with spatial_resolution input argument
- Submit v2.1-0 to CRAN
- Add new parameter ncores
- passar apend_height p/ gtfs2emis
- fix documentation of parameter `ncores`
- Issues with the upcoming release of units 0.8-2 HOT 1
- Reactivate codecov
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 gtfs2gps.