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

Implement R5's native elevation weighting #243

Closed
rafapereirabr opened this issue May 3, 2022 · 10 comments
Closed

Implement R5's native elevation weighting #243

rafapereirabr opened this issue May 3, 2022 · 10 comments
Assignees
Labels
v1.0 Features to be included in r5r 1.0

Comments

@rafapereirabr
Copy link
Member

R5 started considering elevation data as of v6.7. We can remove our elevantion calculations from r5r.

@mvpsaraiva mvpsaraiva added the v1.0 Features to be included in r5r 1.0 label May 4, 2022
@mvpsaraiva
Copy link
Collaborator

I've implemented R5's native elevation feature, with two cost functions currently available: Tobler's hiking function and Minetti et al.

Now, there is an elevation parameter in setup_r5(), so users can chose between the options NONE, TOBLER, or MINETTI. For this feature to work, there needs to be a raster DEM file in tiff format inside the data folder. R5 will weight the street network edges according to the chosen function and serialize it in the network.dat.


Below, there is a demonstration of the differences between the cost functions using the Porto Alegre sample dataset:

Screenshot 2022-05-17 at 17 16 44

  • For walking, R5's Tobler's function is quite similar to the current implementation in r5r, producing just slightly longer travel times. R5 actually breaks long street segments into smaller pieces before applying the cost function, thus producing results at a finer resolution than the current implementation in r5r.
  • For cycling, Minetti's function produced results that are closer to r5r's implementation (which is a based on OpenTripPlanner).

@mvpsaraiva mvpsaraiva changed the title Remove elevantion calculations Implement R5's native elevation weighting May 17, 2022
@mvpsaraiva
Copy link
Collaborator

A few more comparisons, for reference. Some trips can be completed within max_trip_duration on flat terrain, but they exceed that time when elevation is considered. These trips could not be plotted in the charts above, because they have NA values in the x and/or y axes.
Below, we can see the count of those trips considering each cost function:

walking

image

cycling

image

@mvpsaraiva
Copy link
Collaborator

mvpsaraiva commented May 17, 2022

This is mostly done now... I've pushed it to the master branch. We still need to:

  • check the inputs and documentation of the elevation parameter in setup_r5()
  • update the tests of setup_r5() to account for elevation

@rafapereirabr
Copy link
Member Author

I just added some input checks for the elevation paramter in setup_r5(). If there are no .tif files in the data path, r5r will automatically consider elevation = "NONE"

@rafapereirabr
Copy link
Member Author

This is lookig really good. However, I just noticed that r5r prints some messages about the elevation model even when setup_r5(verbose = FALSE). Is it possible to supress these messages as well?

...
Gradient over 0.5: -0.600000 (dx 10.000000 / dy -6.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.700000 (dx 10.000000 / dy 7.000000) Clamping.
Gradient over 0.5: -0.700000 (dx 10.000000 / dy -7.000000) Clamping.
Gradient over 0.5: -0.700000 (dx 10.000000 / dy -7.000000) Clamping.
Gradient over 0.5: 0.700000 (dx 10.000000 / dy 7.000000) Clamping.
Gradient over 0.5: 4.700000 (dx 10.000000 / dy 47.000000) Clamping.
Gradient over 0.5: -4.700000 (dx 10.000000 / dy -47.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.800000 (dx 10.000000 / dy 8.000000) Clamping.
Gradient over 0.5: -0.800000 (dx 10.000000 / dy -8.000000) Clamping.
Gradient over 0.5: -2.900000 (dx 10.000000 / dy -29.000000) Clamping.
Gradient over 0.5: 2.900000 (dx 10.000000 / dy 29.000000) Clamping.
Gradient over 0.5: -2.900000 (dx 10.000000 / dy -29.000000) Clamping.
Gradient over 0.5: 2.900000 (dx 10.000000 / dy 29.000000) Clamping.
Gradient over 0.5: -1.334223 (dx 1.499000 / dy -2.000000) Clamping.
Gradient over 0.5: 1.334223 (dx 1.499000 / dy 2.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: -1.152406 (dx 3.471000 / dy -4.000000) Clamping.
Gradient over 0.5: 1.152406 (dx 3.471000 / dy 4.000000) Clamping.
Gradient over 0.5: 2.900000 (dx 10.000000 / dy 29.000000) Clamping.
Gradient over 0.5: -2.900000 (dx 10.000000 / dy -29.000000) Clamping.
Gradient over 0.5: 1.600000 (dx 10.000000 / dy 16.000000) Clamping.
Gradient over 0.5: -1.600000 (dx 10.000000 / dy -16.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: 1.124859 (dx 4.445000 / dy 5.000000) Clamping.
Gradient over 0.5: -1.124859 (dx 4.445000 / dy -5.000000) Clamping.
Gradient over 0.5: -0.578102 (dx 8.649000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.578102 (dx 8.649000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: 0.749064 (dx 2.670000 / dy 2.000000) Clamping.
Gradient over 0.5: -0.749064 (dx 2.670000 / dy -2.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.
Gradient over 0.5: 0.500000 (dx 10.000000 / dy 5.000000) Clamping.
Gradient over 0.5: -0.500000 (dx 10.000000 / dy -5.000000) Clamping.

Finished building network.dat at R:/Dropbox/git/r5r/r-package/inst/extdata/poa/network.dat

@mvpsaraiva
Copy link
Collaborator

Is it possible to supress these messages as well?

Currently, it's not. They're using regular print commands instead of the Logging engine that we can suppress. I'll open an issue on R5 asking them to change that.

@rafapereirabr
Copy link
Member Author

done

@rafapereirabr
Copy link
Member Author

rafapereirabr commented May 24, 2022

@mvpsaraiva , does Conveyal mention any publications by Tobler or Minetti that were used as a reference for their algorithm?

ps. I just realized the correct spelling is Minetti, not Manetti. this needs to be fixed in r5r

@rafapereirabr
Copy link
Member Author

thanks. I'll add them to the details of setup_r5()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.0 Features to be included in r5r 1.0
Projects
None yet
Development

No branches or pull requests

2 participants