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

Elevation data #82

Open
dabreegster opened this issue Jun 23, 2020 · 18 comments
Open

Elevation data #82

dabreegster opened this issue Jun 23, 2020 · 18 comments
Labels
good first issue Good for newcomers

Comments

@dabreegster
Copy link
Collaborator

This is a big project, but with small steps. Roughly:

  1. Get better elevation data, either fixing the bugs in the srtm.rs impl or preferably using the better LIDAR data around Seattle. I have some pointers for that in an email somewhere; remind me to post them

  2. Figure out how elevation change affects the standard bicyclist speed. Incorporate that in the simulation and pathfinding cost function

  3. Render the elevation layer much more understandably. Isochrones are the thing people are familiar with, probably should give that a shot

I can give pointers to relevant code when needed

@dabreegster
Copy link
Collaborator Author

http://brouter.de/brouter/elevation.html for reference

@dabreegster
Copy link
Collaborator Author

All those references to better lidar data for washington, thanks to Michael Patrick from CUGOS:

@dabreegster
Copy link
Collaborator Author

Seattle only and old data, but looks detailed: https://data-seattlecitygis.opendata.arcgis.com/datasets/contour-lines-1993

@Robinlovelace
Copy link
Contributor

There's an R package that takes OSM data and calculates gradients in the surrounding area that can provide ideas/inspiration for this: https://github.com/ITSLeeds/slopes The main computational tasks are quite generally applicable so I would suggest splitting this out as a separate cargo crate, either within this repo (or perhaps better?) as a separate repo. Vested interest: I want the functionality in the slopes package to be faster. Thinking of eventually using the Rust implementation as a back-end via the libR-sys crate https://github.com/extendr/libR-sys . Another advantage of this approach: Rust is a solid and future-proof language with interfaces to many lanuages so a Rust implementation could help make the awesome functionality in slopes available for more communities, beyond the small (but highly active and rapidly growing #rspatial community).

@Robinlovelace
Copy link
Contributor

In terms of Rust/R integration it's early days but I just ran the following commands from the extendr/libR-sys repo and it works fine:

libR-sys on  master via 𝗥 v1.48.0 
➜ cargo build                          
    Updating crates.io index
   Compiling libR-sys v0.2.1 (/mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/orgs/extendr/libR-sys)
    Finished dev [unoptimized + debuginfo] target(s) in 12.26s

libR-sys on  master is 📦 v0.2.1 via 𝗥 v1.48.0 took 12s 
➜ cargo test -- --nocapture --test-threads=1

@Robinlovelace
Copy link
Contributor

Good news: it seems the approach is fast. Faster than R's very mature C++ bindings according to a small benchmark here: extendr/rextendr#11 (comment)

@Robinlovelace
Copy link
Contributor

Reproducible example on a machine that has R and Rust installed. Not 100% sure what's going on here, imagine @dabreegster you'll have a better idea if you can reproduce it...

library(rextendr)

# create a Rust function
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")
#> build directory: /tmp/RtmphEpi9F/file6a284aec7f99

# call it from R
add(2.5, 4.7)
#> [1] 7.2

Created on 2021-01-09 by the reprex package (v0.3.0)

@Robinlovelace
Copy link
Contributor

Robinlovelace commented Jan 9, 2021

And with regard to the question of which elevation data source to use... SRTM has been superseded I think, some countries (and cities) have higher res data but for the purposes of this package (which should be able to use custom DEM data) I think globally available datasets as a default will be sufficient and most useful.

In the slopes package as far as I can recall we use the https://docs.mapbox.com/help/troubleshooting/access-elevation-data/ via the ceramic package, source code of which can be found here: https://github.com/hypertidy/ceramic/blob/7980c9f4134c0770ab3de351049e7dd511aac002/R/tile-providers.R

@dabreegster
Copy link
Collaborator Author

The Mapbox API is quite convenient. Did you hit any licensing or API limit issues with caching data from them?

For a general purpose crate, having a method that winds up making a Mapbox request would be very useful. For the A/B Street case, we likely want to use some kind of bulk API or to find and operate on a DEM file. I'd be a little surprised if Mapbox just lets you dump elevation data for a huge reason, cache it on your end, redistribute it, etc.

@Robinlovelace
Copy link
Contributor

Did you hit any licensing or API limit issues with caching data from them?

Not yet, I have an unpaid mapbox API key that is quite generous and not even sure if you need one for the terrain data.

@dabreegster
Copy link
Collaborator Author

Huh, https://www.mapbox.com/legal/tos/ doesn't mention anything against redistributing data from their APIs. Nice!

@Robinlovelace
Copy link
Contributor

But to be fair haven't been bulk downloading data in a way that I have been doing for OSM/STATS19 data. I'm sure lack of DEM data will not be a limiting factor for this issue in any case!

@dabreegster
Copy link
Collaborator Author

https://valhalla.readthedocs.io/en/latest/sif/elevation_costing/ reference for how to use elevation data for cycle routing

dabreegster added a commit that referenced this issue Feb 25, 2021
…expired, and I can't find a replacement. The elevation data has always been extremely incorrect, and a proper replacement for it is in the works. #82, #534

Not regenerating Seattle maps yet, but next time, the elevation will be set to 0 everywhere. Should be a no-op.
dabreegster added a commit that referenced this issue Mar 18, 2021
…evation from importer config; the new approach will detect the right data source to use automatically using the bbox. #82
dabreegster added a commit that referenced this issue Mar 18, 2021
So far, just call it for Seattle maps. Store the data sources in S3.

Note this'll only run on my machine right now, unless you also build the
Docker image locally. Failures in elevation should be skipped for now.
dabreegster added a commit that referenced this issue Mar 19, 2021
dabreegster added a commit that referenced this issue Mar 19, 2021
… the inclines we're assigning to roads, but also, I realized a problem with how the elevation lookup not matching the trimmed roads. #82
dabreegster added a commit that referenced this issue Mar 19, 2021
to the elevation measured at the original intersection point. #82

Upload montlake, downtown, and phinney with elevation data, as an
initial demo.
dabreegster added a commit that referenced this issue Mar 25, 2021
This is simpler to reason about, allows the penalty for entering a zone
or taking an unprotected turn to be expressed in terms of a time
penalty, and is a step towards adjusting bike/foot routing for elevation
data.

When we later add things like "safety/quietness" for cycling, maybe we
can switch to using a (time, quietness) tuple, and transform into a
single number with a linear combination parameterized by that agent's
preference for time/safety. This change is compatible with that future
idea.

There are behavior changes here, particularly for zones and unprotected
turns. Impact on gridlock TBD... Broadmoor proposal TBD...
dabreegster added a commit that referenced this issue Mar 25, 2021
This is simpler to reason about, allows the penalty for entering a zone
or taking an unprotected turn to be expressed in terms of a time
penalty, and is a step towards adjusting bike/foot routing for elevation
data.

When we later add things like "safety/quietness" for cycling, maybe we
can switch to using a (time, quietness) tuple, and transform into a
single number with a linear combination parameterized by that agent's
preference for time/safety. This change is compatible with that future
idea.

There are behavior changes here, particularly for zones and unprotected
turns. No new maps start gridlocking, and in fact, Rainier starts
working again.
dabreegster added a commit that referenced this issue Mar 25, 2021
This is simpler to reason about, allows the penalty for entering a zone
or taking an unprotected turn to be expressed in terms of a time
penalty, and is a step towards adjusting bike/foot routing for elevation
data.

When we later add things like "safety/quietness" for cycling, maybe we
can switch to using a (time, quietness) tuple, and transform into a
single number with a linear combination parameterized by that agent's
preference for time/safety. This change is compatible with that future
idea.

There are behavior changes here, particularly for zones and unprotected
turns. No new maps start gridlocking, and in fact, Rainier starts
working again.
dabreegster added a commit that referenced this issue Apr 2, 2021
…ts, which import synthetic maps with strange coordinates. #82
dabreegster added a commit that referenced this issue Apr 2, 2021
…thfinding, using calcultions from Valhalla. #82

Not regenerating data yet.
dabreegster added a commit that referenced this issue Apr 2, 2021
dabreegster added a commit that referenced this issue Apr 3, 2021
dabreegster added a commit that referenced this issue Apr 3, 2021
dabreegster added a commit that referenced this issue Apr 3, 2021
…thfinding, using calcultions from Valhalla. #82

Not regenerating data yet.
dabreegster added a commit that referenced this issue Apr 3, 2021
dabreegster added a commit that referenced this issue Apr 4, 2021
It was always using the current directory, which breaks when running the
UI map importer from game/. [rebuild] [release]
dabreegster added a commit that referenced this issue Apr 7, 2021
…biking trips. It's just noise to see it for somebody walking to their car. #82
dabreegster added a commit that referenced this issue Apr 13, 2021
- Echo process output to the main UI's stdout, for easier debugging
- Remove the timing breakdown from elevation import, since it breaks
  when the function bails out early
dabreegster added a commit that referenced this issue Apr 13, 2021
…the UI, for #602 and #82.

This makes the logs understandable and should fix the issue where the
last line of one_step_import's output is sometimes a warning instead of
the map name.
dabreegster added a commit that referenced this issue May 4, 2021
… import can work on any Linux machine with docker. #82
@PayasR
Copy link

PayasR commented Aug 5, 2021

SRTM has been superseded by NASADEM:
https://earthdata.nasa.gov/esds/competitive-programs/measures/nasadem

@dabreegster
Copy link
Collaborator Author

Thanks, good to know! We could try hooking up NASDEM with https://github.com/eldang/elevation_lookups#raster-elevation-data pretty easily. If GDAL can read it, should be easy.

@dabreegster
Copy link
Collaborator Author

dabreegster commented Aug 5, 2021

Summarizing how things work currently.

  • We use https://github.com/eldang/elevation_lookups to deal with LIDAR data for Seattle, and with SRTM for other cities. This Python library has an API for elevation at a point and, more importantly, plugging in a polyline representing a street and getting the total incline.
  • The A/B Street importer calls out to this library during the first step of importing a map. We just store elevation per intersection, currently. Everything downstream just uses that; we're not keeping around the raw elevation datasets.
  • Walking and biking account for incline by costing pathfinding and in the simulation. Walking speed is here, based on Tobler's hiking function. Biking is here, loosely based on Valhalla -- I was unable to find a simple formula here.
  • We have a few dataviz things hooked up, some https://github.com/a-b-street/abstreet/blob/master/game/src/layer/elevation.rs. Contour map, showing steep streets, and per-trip elevation profiles:
    Screenshot from 2021-08-05 09-38-47
    Screenshot from 2021-08-05 09-38-20
    Screenshot from 2021-08-05 09-38-06

Future work / help needed:

  • Pure Rust solutions without heavy GDAL dependencies would be nice. Especially to parallelize querying; because of some mutable caching layer, it's expensive to spawn multiple threads to query a large vector or raster input source.
  • I've only carefully checked the end-to-end elevation results for Seattle, which uses LIDAR. Everywhere else uses SRTM, and the results look quite suspect -- as a quick sanity test, the contour map will jump from totally flat to 100m without anything in between. Not sure where the issue is yet.
  • If NASDEM has worldwide coverage and is better than SRTM, we should switch to it.
  • Things break near bridges, because I think the input dataset gives the value for the water/ground below. From the abst importer, we know when we are querying near a bridge, so there were some ideas to just ask for the polyline's endpoints, instead of sampling every few meters.

dabreegster added a commit that referenced this issue Jun 28, 2022
…keep an SRTM test case). Running everywhere slows down map regeneration on my current laptop, and doesn't add much benefit, since the SRTM support is unfinished. #82
dabreegster added a commit that referenced this issue Jun 29, 2022
…keep an SRTM test case). Running everywhere slows down map regeneration on my current laptop, and doesn't add much benefit, since the SRTM support is unfinished. #82
dabreegster added a commit that referenced this issue Nov 3, 2022
…ation yet; the results there aren't good enough to justify keeping the logic for this. #82

(Also the huge and unused Seattle contours geojson)
@dabreegster
Copy link
Collaborator Author

Keeping my eye on https://github.com/pka/georaster as another pure-Rust geotiff reader. Instead of memmap or similar for handling massive files, we could split the big UK and Seattle files into tiles (or possibly even download them that way to begin with)

@dabreegster
Copy link
Collaborator Author

https://opendem.info/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants