Code Monkey home page Code Monkey logo

trip-simulator's Introduction

trip-simulator

A module for generating simulated location telemetry

Overview

trip-simulator is a tool created by SharedStreets for generating simulated raw GPS telemetry. Raw GPS data is highly sensitive, since it can be easily deanonymized and used to track the historical movements of an individual. For this reason, it is difficult to safely develop algorithms for use cases like transit analysis, map matching, or speed profiling without having this data locally available. The SharedStreets trip-simulator realistically creates location telemetry using agents and physically modeled GPS output. Since the data is fake, there is no privacy risk, and since the noise is plausibly simulated, it can still be used for algorithms that need to operate under real world signal conditions.

1 million trips simulated over NYC

Features

  • Multi-agent model supporting cars, bikes, or scooters
  • Generates GPS data with no inputs besides OpenStreetMap
  • Reasonable pickup/dropoff generated using agent model based on network density
  • Physically realistic GPS noise modeled for usage in real world telemetry algorithms
  • Outputs 1hz location probes, MDS compliant trips, and MDS compliant status changes

Install

npm install -g trip-simulator

CLI

trip-simulator

-h,--help     show help
--config      config car,bike,scooter
--pbf         osm.pbf file
--graph       osrm graph file
--agents      number of agents
--start       start time in epoch milliseconds
--seconds     number of seconds to simulate
--probes      GeoJSON probes output file
--traces      GeoJSON traces output file
--trips       MDS trips output file
--changes     MDS status changes output file

Use

trip-simulator features a command line interface capable of generating telemetry data for simulated vehicles around a city. The simulation requires an OpenStreetMap extract, which can be downloaded from many sources, such as planet.osm, geofabrick, or nextzen. Download and extract, and trim the network to the target area using a tool such as osmium. Once you have a trimmed extract, process the road graph using OSRM. As an example, we will walk through simulating data for Nashville, TN using a nextzen extract.

1. download data

curl https://s3.amazonaws.com/metro-extracts.nextzen.org/nashville_tennessee.osm.pbf -o nashville.osm.pbf

2. extract a smaller target bounding box

osmium extract -b "-86.84881,36.12262,-86.73688,36.20494" nashville.osm.pbf -o ./nash.osm.pbf -s "complete_ways" --overwrite

3. install OSRM to your project directory & process the road graph using the default pedestrian profile

npm install osrm;
./node_modules/osrm/lib/binding/osrm-extract ./nash.osm.pbf -p ./node_modules/osrm/profiles/foot.lua;
./node_modules/osrm/lib/binding/osrm-contract ./nash.osrm

4. run a 24 hour scooter simulation with 100 vehicle agents

trip-simulator \
  --config scooter \
  --pbf nash.osm.pbf \
  --graph nash.osrm \
  --agents 100 \
  --start 1563122921000 \
  --seconds 86400 \
  --traces ./traces.json \
  --probes ./probes.json \
  --changes ./changes.json \
  --trips ./trips.json

Test

npm test

Lint

npm run lint

trip-simulator's People

Contributors

imresamu avatar mhkeller avatar morganherlocker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trip-simulator's Issues

trip-simulator lib API

I would like to break out the path simulation code into a library API called by the CLI. This will allow for tests around core functions, as well as the ability to use the GPS physical simulation functionality in custom use cases, such as creating paths from a pre-existing OD pair dataset.

osrm-extract and contract execution error

I tried to run the docker file but I got "executor failed running [/bin/sh -c /trip-simulator/node_modules/osrm/lib/binding/osrm-extract" error using node:11 in dockerfile. Would you please let me know how I can resolve this issue?

Simulate with custom OD data?

Trying to use the tool to simulate trajectories with a dataset of real OD data.
Is it possible with the current command line arguments?
If yes how should I prepare my OD data?

Missing first timestamp?

I received a bug report that occasionally the first timestamp is not populated or possibly null.

configuration

I would like to expose all variables that might be impacted by the type of driver and hardware being simulated, with the goal to support multiple types of vehicles. The following represent medians for normal distributions used by the simulation:

  • horizontal accuracy
  • accuracy variance
  • probe frequency
  • frequency variance
  • routing type (car, bike, ped, other)
  • wait between trips
  • distance between trips (eg: 0 for dockless bikes and scooters / 0.5km for taxis)
  • trip distance
  • speed deviation (+- % duration from routed ETA prediction)
  • fleet size
  • trips per vehicle per day

CLI interface

Move away from the hardcoded makefile to a CLI. This will make it easier to generate data for multiple areas.

trip-simulator --config ./taxi.json --osm ./nyc.osm.pbf --out ./data
# creates ./data dir
# extracts & contracts graph from nyc.osm.pbf
# outputs trips to ./data/trips.json
# outputs status_changes to ./data/status_changes.json

installation fails at osrm

I'm having trouble installing trip-simulator using the npm install -g trip-simulator command.

System details:-
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

node -v
v12.6.0

npm -v
6.9.0

npm install -g trip-simulator
/usr/bin/trip-simulator -> /usr/lib/node_modules/trip-simulator/src/cli.js

[email protected] install /usr/lib/node_modules/trip-simulator/node_modules/osrm
node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/trip-simulator/node_modules/osrm/lib/binding'
node-pre-gyp ERR! System Linux 4.9.125-linuxkit
node-pre-gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/trip-simulator/node_modules/osrm/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build=false"
node-pre-gyp ERR! cwd /usr/lib/node_modules/trip-simulator/node_modules/osrm
node-pre-gyp ERR! node -v v12.6.0
node-pre-gyp ERR! node-pre-gyp -v v0.12.0
node-pre-gyp ERR! not ok
EACCES: permission denied, mkdir '/usr/lib/node_modules/trip-simulator/node_modules/osrm/lib/binding'
mkdir: cannot create directory 'build': Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-07-09T16_44_36_224Z-debug.log

I have changed the npm global installation location to a local directory. The installation still fails. Appreciate all the help.

simulate OD pairs

I would like to try simulating the OD pairs in addition to the paths. This would allow for the removal of the dependency on real world TLC data, and allow simulations to be created in other regions or even globally. Pairs could be generated probabilistically based on node density, which can be calculated from the OSM data the tool already needs for operation.

random from seed

We're using the chance lib under the hood for providing pseudo-random values and distributions throughout the model. This lib allows a fixed seed string to be provided for reproducible output. This is useful for reproducing reported errors and behavior from the community, and will make it easier to write unit tests with meaningful assertions.

custom configs

We currently support default configs for cars, bikes, and scooters, however, I often find myself needing to tweak various values to test edge cases. For example, I may need to simulate a scooter company that has more frequent breakdowns than usual or a taxi company that uses lofi GPS units.

This proposal would add support for a file path as the config, with the existing keywords maintained.

trip-simulator --config bike
trip-simulator --config ./bike-with-faulty-wheels.json

remove unavailable vehicles after a period of time

Unavailable vehicles should eventually be removed from the street. This should be a configurable parameter to define the distribution, and each vehicle should spawn with a different time to pickup, weighted to that distribution.

urban canyon noise

Agent GPS can use surrounding building density and height to weight horizontal accuracy towards higher skew. The data is already available to the algorithm, since it is used in OD selection, but may require an additional quadtree aggregator at a higher zoom with average height aggregated as well.

timestamp interpolation

Timestamps should be interpolated from route leg ETAs to provide realistic speeds with some amount of variance per vehicle, per trip, and per leg.

[Bug/Question] Heap issue

Hi I'm trying to run a simple example over Stockholm, Sweden and keep running into a heap space issue.

node ./src/cli.js --max-old-space-size=12192 --config car --pbf stockholm_sweden.osm.pbf --graph ../../data/sweden-latest.osrm --agents 2 --iterations 400

<--- Last few GCs --->

[72008:0x102803800]    53467 ms: Mark-sweep 1407.5 (1449.4) -> 1407.5 (1449.4) MB, 1140.7 / 0.0 ms  allocation failure GC in old space requested
[72008:0x102803800]    54866 ms: Mark-sweep 1407.5 (1449.4) -> 1407.5 (1433.4) MB, 1398.3 / 0.0 ms  last resort GC in old space requested
[72008:0x102803800]    56185 ms: Mark-sweep 1407.5 (1433.4) -> 1407.5 (1433.4) MB, 1319.1 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x2685a130427d]
Security context: 0x2dfbe80206a9 <JSObject>
    1: /* anonymous */ [<redacted>/node_modules/trip-simulator/src/simulation.js:~44] [pc=0x2685a13698ba](this=0x2dfb4fe1d251 <JSGlobal Object>,item=0x2dfbd1a9b2c1 <Object map = 0x2dfb28eefe41>)
    2: arguments adaptor frame: 3->1
    3: forEach(this=0x2dfbbd605569 <JSArray[2405817]>)
    4: /* anonymous */ [<redacted>...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [<redacted>/nodejs/10.0.0/bin/node]
 2: node::FatalTryCatch::~FatalTryCatch() [<redacted>/nodejs/10.0.0/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [<redacted>/nodejs/10.0.0/bin/node]
 4: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [<redacted>/nodejs/10.0.0/bin/node]
 5: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [<redacted>/nodejs/10.0.0/bin/node]
 6: 0x2685a130427d
 7: 0x2685a13698ba
Abort trap: 6

I've tried with node 8.5 and 10 (OSRM didn't work with 12). Do you have any suggestions on which node version to use?

Br,
Mats

[question] trips.json schema and 1000 stepSize attribute

I can see in the src how each trip in trips.json is assembled:

trip-simulator/src/agent.js

Lines 183 to 184 in a1497e6

trip_duration: this.path.duration / 1000,
trip_distance: this.path.distance * 1000,

Where does the 1000 constant in the denominator come from? I think it's related to the stepSize from the simulation being hardcoded to 1000:

this.stepSize = 1000;

If so, are the trip_duration and trip_distance values the in seconds and meters, respectively?

I ask because I'd assume the time would converted /60 (min) /360 (hrs), so wondering where the 1000 is coming from.

Same question roughly with distance value.

prettier

Add linter for style consistency.

Trip end time before drop off change event time

πŸ‘‹hey @morganherlocker - thanks for this amazing tool πŸ™‡

Wanted to report a small issue that I've observed: the change event time for user_drop_off is always greater than the trip end_time. This appears to be happening due to this code section: https://github.com/sharedstreets/trip-simulator/blob/master/src/agent.js#L200-L232

if (this.simulation.time >= this.next) {
...
  if (this.changes) {
  ..
    event_time: this.simulation.time
  ..
  }
if (this.trips) {
  const trip = {
    ..
    end_time: this.next,
    ..
}

Apart from the values being different, the end time is also a floating point number instead of an int.

I've locally tested a fix

    end_time: this.simulation.time,

and it works - but I wanted to check with you incase there was a reason to log them differently?

behavior around traffic circles

Seeing some unexpectedly jagged traces when I simulate Dupont Circle in DC using the car profile.

image
image

The noise simulation seems like a reasonable approach to the problem, though not a particularly realistic one (looking at some actual telemetry I see a lot more parallelism than random jitter, perhaps due to either environmental RF echoes or the tendency of the location services black box trying to smooth its output by keeping heading relatively constant).

Assuming realism isn't a particular goal, I'll throw out two possible changes. Are there other ways of tackling this?

  • having the location error as a cumulative vector that is adjusted at each step along a trip rather than a random error added at each step
  • multiplying the error by a function of between-node distance to diminish its effect around circles

I'm also curious why the heading for the noise is normally distributed.

Happy to take a crack at a PR if any of this sounds like a good idea.

install fails

Running on Ubuntu 16.04 LTS,

Is the problem npm version or my OS?

$ cd trip-simulator/
$ npm version
{
'trip-simulator': '3.0.1',
npm: '6.14.13',
ares: '1.17.1',
brotli: '1.0.9',
cldr: '39.0',
icu: '69.1',
llhttp: '2.1.3',
modules: '83',
napi: '8',
nghttp2: '1.42.0',
node: '14.17.1',
openssl: '1.1.1k',
tz: '2021a',
unicode: '13.0',
uv: '1.41.0',
v8: '8.4.371.23-node.67',
zlib: '1.2.11'
}

$ npm install -g trip-simulator
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/michael/.npm/_logs/2021-06-22T23_52_43_665Z-debug.log

So tried sudo:
$ sudo npm install -g trip-simulator
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
/usr/bin/trip-simulator -> /usr/lib/node_modules/trip-simulator/src/cli.js

[email protected] install /usr/lib/node_modules/trip-simulator/node_modules/osrm
node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh

node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/trip-simulator/node_modules/osrm/lib/binding'
node-pre-gyp ERR! System Linux 4.15.0-142-generic
node-pre-gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/trip-simulator/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build=false"
node-pre-gyp ERR! cwd /usr/lib/node_modules/trip-simulator/node_modules/osrm
node-pre-gyp ERR! node -v v14.17.1
node-pre-gyp ERR! node-pre-gyp -v v1.0.5
node-pre-gyp ERR! not ok
EACCES: permission denied, mkdir '/usr/lib/node_modules/trip-simulator/node_modules/osrm/lib/binding'
Needs cmake to build from source
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-pre-gyp install --fallback-to-build=false || ./scripts/node_install.sh
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /home/michael/.npm/_logs/2021-06-22T23_55_37_670Z-debug.log

skip first line

First line of the TLC data contains a CSV header, which causes some error noise when the date parsing is attempted.

include timestamps array

Let's add timestamp interpolation to traces, like we do for MDS style trips. This will bring us into compliance with the TraceJSON specification.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.