Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtfs2gps::gtfs2gps not updating trip_number attribute #189

Closed
Joaobazzo opened this issue Apr 15, 2021 · 1 comment
Closed

gtfs2gps::gtfs2gps not updating trip_number attribute #189

Joaobazzo opened this issue Apr 15, 2021 · 1 comment
Assignees

Comments

@Joaobazzo
Copy link
Collaborator

one important column of gtfs2gps::gtfs2gps output is not being properly update inside mod_updates.R

library(gtfs2gps)
library(magrittr)

sao <- read_gtfs(system.file("extdata/saopaulo.zip",
                             package = "gtfs2gps")) 
#> Reading 'agency.txt'
#> Reading 'routes.txt'
#> Reading 'stops.txt'
#> Reading 'stop_times.txt'
#> Reading 'shapes.txt'
#> Reading 'trips.txt'
#> Reading 'calendar.txt'
#> Reading 'frequencies.txt'

sao$shapes$shape_id %>% unique() %>% head(2)
#> [1] "52421" "52857"

sao1 <- sao %>% 
  filter_by_shape_id("52857")

sao2 <- sao1 %>% 
  gtfs2gps() 
#> Converting shapes to sf objects
#> Warning: package 'sf' was built under R version 4.0.4
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
#> Processing the data
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names
#> Warning: package 'data.table' was built under R version 4.0.4
#> 
#> Attaching package: 'data.table'
#> The following object is masked from 'package:purrr':
#> 
#>     transpose
#> Warning: package 'units' was built under R version 4.0.4
#> udunits database from C:/Users/B138750230/Documents/R/R-4.0.2/library/units/share/udunits/udunits2.xml

sao3 <- sao2 %>% 
  gps_as_sflinestring()

connecting point

plot(sao3$geometry)

id_stop <- which(sao2$stop_sequence==1)

id_stop[2]
#> [1] 757

here we can see that when sao2$cumdist==0, sao2$trip_number is not updated

sao2[755:760]
#>     id shape_id   trip_id trip_number route_type shape_pt_lon shape_pt_lat
#> 1: 755    52857 148L-10-0           1          3    -46.70174    -23.52002
#> 2: 756    52857 148L-10-0           1          3    -46.70169    -23.51999
#> 3: 757    52857 148L-10-0           1          3    -46.65231    -23.45463
#> 4: 758    52857 148L-10-0           1          3    -46.65228    -23.45445
#> 5: 759    52857 148L-10-0           1          3    -46.65225    -23.45424
#> 6: 760    52857 148L-10-0           1          3    -46.65221    -23.45410
#>    departure_time from_stop_id stop_sequence          dist         cumdist
#> 1:       01:24:54         <NA>            NA 20.361700 [m] 16691.59999 [m]
#> 2:       01:24:57    480012869            58  6.602334 [m] 16698.20232 [m]
#> 3:       04:00:00      1313512             1  0.000000 [m]     0.00000 [m]
#> 4:       04:00:03         <NA>            NA 20.255183 [m]    20.25518 [m]
#> 5:       04:00:06         <NA>            NA 23.021378 [m]    43.27656 [m]
#> 6:       04:00:08         <NA>            NA 16.085589 [m]    59.36215 [m]
#>            cumtime            speed interval_id
#> 1: 5093.933973 [s]  8.724828 [km/h]          58
#> 2: 5096.658199 [s]  8.724828 [km/h]          59
#> 3:    0.000000 [s] 28.199914 [km/h]          60
#> 4:    2.585776 [s] 28.199914 [km/h]          60
#> 5:    5.524684 [s] 28.199914 [km/h]          60
#> 6:    7.578170 [s] 28.199914 [km/h]          60

I might be able to solve it by adjust trip_number within mod_updates.R script
Created on 2021-04-15 by the reprex package (v0.3.0)

@Joaobazzo Joaobazzo self-assigned this Apr 15, 2021
@Joaobazzo
Copy link
Collaborator Author

Joaobazzo commented Apr 16, 2021

ok, i know what happened, and I’ll try to explain here
here’s sao paulo gtfs

library(gtfs2gps)
library(magrittr)
gps <- read_gtfs(system.file("extdata/saopaulo.zip", package = "gtfs2gps")) %>%
  filter_by_shape_id(c("52857")) %>% gtfs2gps() 
#> Reading 'agency.txt'
#> Reading 'routes.txt'
#> Reading 'stops.txt'
#> Reading 'stop_times.txt'
#> Reading 'shapes.txt'
#> Reading 'trips.txt'
#> Reading 'calendar.txt'
#> Reading 'frequencies.txt'
#> Converting shapes to sf objects
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
#> Processing the data
#> Warning: `future_options()` was deprecated in furrr 0.2.0.
#> Please use `furrr_options()` instead.
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names
#> 
#> Attaching package: 'data.table'
#> The following object is masked from 'package:purrr':
#> 
#>     transpose
#> udunits database from /usr/share/xml/udunits/udunits2.xml
#> Some 'speed' values are NA in the returned data

see what happens when we check number of trip_numbers

table(gps$trip_number)
#> 
#>     1     2     3     4     5     6     7     8     9    10    11    12    13 
#> 15876 15120 14364 13608 13608 12096 11340 11340  8316  6048   756   756   756 
#>    14    15 
#>   756   756

trip number of being repeted everytime for every headway
see the order for the first 10 observations:

gps[stop_sequence==1,][1:10]
#>     id shape_id   trip_id trip_number route_type shape_pt_lon shape_pt_lat
#>  1:  1    52857 148L-10-0           1          3    -46.65231    -23.45463
#>  2:  1    52857 148L-10-0           1          3    -46.65231    -23.45463
#>  3:  1    52857 148L-10-0           2          3    -46.65231    -23.45463
#>  4:  1    52857 148L-10-0           3          3    -46.65231    -23.45463
#>  5:  1    52857 148L-10-0           4          3    -46.65231    -23.45463
#>  6:  1    52857 148L-10-0           5          3    -46.65231    -23.45463
#>  7:  1    52857 148L-10-0           1          3    -46.65231    -23.45463
#>  8:  1    52857 148L-10-0           2          3    -46.65231    -23.45463
#>  9:  1    52857 148L-10-0           3          3    -46.65231    -23.45463
#> 10:  1    52857 148L-10-0           4          3    -46.65231    -23.45463
#>     departure_time stop_id stop_sequence  dist cumdist cumtime           speed
#>  1:       00:00:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  2:       04:00:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  3:       04:12:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  4:       04:24:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  5:       04:36:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  6:       04:48:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  7:       05:00:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  8:       05:08:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#>  9:       05:16:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]
#> 10:       05:24:00 1313512             1 0 [m]   0 [m]   0 [s] 26.23295 [km/h]

or

gps[stop_sequence==1,][1:15]$trip_number
#>  [1] 1 1 2 3 4 5 1 2 3 4 5 6 7 8 1

so i’ve made an adjustment on mod_updates.R so
trip_number are not updated anymore on every headway
Created on 2021-04-16 by the reprex package (v0.3.0)

image

however, I'm still not sure how's table time GTFS type performs with trip_number, so I'll check a little bit further

Joaobazzo added a commit to Joaobazzo/gtfs2gps that referenced this issue Apr 16, 2021
Joaobazzo added a commit to Joaobazzo/gtfs2gps that referenced this issue Apr 19, 2021
rafapereirabr added a commit that referenced this issue Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants