ipeaGIT / r5r

https://ipeagit.github.io/r5r/
Other
181 stars 30 forks source link

Add function to calculate accessibility #169

Closed rafapereirabr closed 3 years ago

mvpsaraiva commented 3 years ago

Although accessibility can be calculated from the travel time matrices produced by r5r, a dedicated accessibility function has many advantages:

Additionally, the new accessibility() function signature is very similar to that of the travel_time_matrix() function, with just a few differences:

mvpsaraiva commented 3 years ago

First estimates, using a step decay function:

Screenshot 2021-05-14 at 09 48 06
mvpsaraiva commented 3 years ago

Conveyal documentation on decay functions is here. Those functions, beyond the step / cumulative opportunities function, are:

I think we have two options:

dhersz commented 3 years ago

I prefer exposing all decay functions and documenting what the parameter means in each case.

Regarding the figure you posted above, are all of these "no accessibility islands" snap-related? The image seems a bit weird to me. Had we calculated the travel time matrices manually and calculated accessibility within R, the resulting plot would be similar?

rafapereirabr commented 3 years ago

I would also prefer we expose all decay functions and create and decay argument.

I agree the maps has quite a few unexpected blind spots. Perhaps we should calculate accessibility step-by-step in R and compare agains the R5 estimates.

mvpsaraiva commented 3 years ago

Good points! The "inaccessible islands" of the previous maps happened because max_walk_dist was set to just 300m. I've increased it to 1km and calculated accessibility again, using the two methods. Now the areas with "no accessibility" (dark grey on the maps below) are concentrated towards the southern edge of the city, which makes more sense.

Screenshot 2021-05-14 at 14 33 52

The resulting maps look the same. I've also compared both data.frames, and the accessibility values are exactly the same as well. I believe that using a frequency-based GTFS and larger number of Monte Carlo draws, there will be some variation in travel times and accessibility values, but in this simple tests all values are equal.

rafapereirabr commented 3 years ago

Perfect. Thanks for looking into this, Marcus!Rafael H M Pereira -------- Original message --------From: Marcus Saraiva @.> Date: 5/14/21 14:42 (GMT-03:00) To: ipeaGIT/r5r @.> Cc: Rafael H M Pereira @.>, Author @.> Subject: Re: [ipeaGIT/r5r] Add function to calculate accessibility (#169) Good points! The "inaccessible islands" of the previous maps happened because max_walk_dist was set to just 300m. I've increased it to 1km and calculated accessibility again, using the two methods. Now the areas with "no accessibility" (dark grey on the maps below) are concentrated towards the southern edge of the city, which makes more sense.

The resulting maps look the same. I've also compared both data.frames, and the accessibility values are exactly the same as well. I believe that using a frequency-based GTFS and larger number of Monte Carlo draws, there will be some variation in travel times and accessibility values, but in this simple tests all values are equal.

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.

mvpsaraiva commented 3 years ago

Simple demonstration of the effects of all decay functions on accessibility. The title of each facet states the decay function used and the corresponding parameter value. In the case of step and exp, it's simply the travel time cutoff; the other functions were calculated with a cutoff of 30 min and the decay parameter stated in the facet.

Screenshot 2021-05-14 at 17 27 51
mvpsaraiva commented 3 years ago

Plots of the decay functions, for the record:

Screenshot 2021-05-21 at 08 15 33

Travel times on the x axis, step and exponential functions using cutoff = 30, fixed_exponential with decay = 0.001, and logistic and linear using decay = 10.

mvpsaraiva commented 3 years ago

To-do:

rafapereirabr commented 3 years ago

I've added some more documentation to the function but I think we still have to provide (1) intuitive explanations to the behavior of each decay function, (2) the equations of each decay function

rafapereirabr commented 3 years ago

@mvpsaraiva , I get the following error when I try to reproduce the example in the function:

library(r5r)

 # build transport network
 data_path <- system.file("extdata/poa", package = "r5r")
 r5r_core <- setup_r5(data_path = data_path)

 # load origin/destination points
 points <- read.csv(file.path(data_path, "poa_hexgrid.csv"))

   access <- accessibility(r5r_core,
                           origins = points,
                           destinations = points,
                           opportunities_colname = "schools",
                           mode = "WALK",
                           cutoffs = c(25, 30),
                           max_trip_duration = 30,
                           verbose = FALSE)

Error in get(opportunities_colname) : object 'schools' not found

mvpsaraiva commented 3 years ago

The issue seems to be in this line. I've removed the get from the data.table call and it seems to be working now. But sometimes it requires the get, so I'm not quite sure what's going on.

rafapereirabr commented 3 years ago

Thanks! I've just added a test script for the accessibility() function, commit 09e45870

rafapereirabr commented 3 years ago

Setting this issue as priority, to be incorporated in the next package release.