Skip to main content

Traffic Generator

The tool generates a structured set of encounters for verifying automatic collision and grounding avoidance systems. Based on input parameters such as desired situation, relative speed, relative bearing etc, the tool will generate a set of traffic situations. The traffic situations may be written to files and/or inspected using plots.

A paper is written describing the background for the tool and how it works [paper]

For package documentation, see https://dnv-opensource.github.io/ship-traffic-generator/

Installation

To install Ship Traffic Generator, run this command in your terminal:

pip install trafficgen

This is the preferred method to install Traffic Generator, as it will always install the most recent stable release.

You can check your installation by running:

uv run trafficgen --help

Usage

For simplest usage, clone this repo, then run pip install -e . (you may want to do this in a local environment, such as a venv, see an example with uv below).

Then run: trafficgen gen-situation. You can add the option -v for visualization.

For further explanations, see the documentation pages of the Ship Traffic Generator.

Development Setup

Install UV

This project uses uv as package manager. If you haven't already, install uv, preferably using it's "Standalone installer" method:
..on Windows:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

..on MacOS and Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

(see docs.astral.sh/uv for all / alternative installation methods.)

Once installed, you can update uv to its latest version, anytime, by running:

uv self update

Install Python

The traffic generator requires Python 3.11 or later.

If you don't already have a compatible version installed on your machine, you way install Python through uv:

uv python install

This will install the latest stable version of Python into the uv Python directory, i.e. as a uv-managed version of Python.

Note: you can also do this after you clone the repo, see below.

Alternatively, and if you want a standalone version of Python on your machine, you can install Python either via winget:

winget install --id Python.Python

or you can download and install Python from the python.org website.

Clone the repository

Clone the traffig generator repository into your local development directory:

git clone https://github.com/dnv-opensource/ship-traffic-generator path/to/your/dir/ship-traffic-generator

Change into the project directory after cloning:

cd ship-traffic-generator

Install dependencies

Run uv sync -U to create a virtual environment and install all project dependencies into it:

uv sync -U

Note: Using --no-dev will omit installing development dependencies.

Note: You can also define the python environment at the same time, by running for example uv sync -U -p 3.12 to install Python 3.12.

Note: uv will create a new virtual environment called .venv in the project root directory when running uv sync the first time. Optionally, you can create your own virtual environment using e.g. uv venv, before running uv sync.

(Optional) Activate the virtual environment

When using uv, there is in almost all cases no longer a need to manually activate the virtual environment.
uv will find the .venv virtual environment in the working directory or any parent directory, and activate it on the fly whenever you run a command via uv inside your project folder structure:

uv run <command>

However, you still can manually activate the virtual environment if needed. When developing in an IDE, for instance, this can in some cases be necessary depending on your IDE settings. To manually activate the virtual environment, run one of the "known" legacy commands:
..on Windows:

.venv\Scripts\activate.bat

Note: If you use the cmd terminal in VS Code, it will show this activated venv as (trafficgen) at the start of every line command.

..on Linux:

source .venv/bin/activate

Install the package

uv pip install -e .

Test the install

In your virtual environment, or prepend uv run:

pytest .

Documentation

For pre-generated package documentation, see https://dnv-opensource.github.io/ship-traffic-generator/

To generate documentation from the source code, use:

uv run docs/make.bat html

The html documentation will then be available in docs/build/html/index.html

Contributing

  1. Any development should be associated to GitHub "issues" and done on new branches, which are tagged with the issue number. Branch off from dev (and also create PRs towards dev). The main branch is used for releases.

    • Example branch names: enh/1-improve-speed, bug/43-fix-cli-bug-about-something, etc.
  2. Whenever you make changes to files, please keep formatting the same (e.g. whitespaces etc.), and follow the conventions used in the file (and this project). The Pull Request checks/actions on GitHub will run ruff format/check, pyright and mypy. To prepare, you may wanna run these before committing your changes, to ensure you are adhering to the formatting rules. E.g.:

    uv run ruff format
    uv run ruff check
    uv run pyright
    uv run mypy
    
  3. Run the pytest to ensure you did not break any functionality, and ensure you have added new tests for new features:

    uv run pytest .
    
  4. When you create a Pull Request in GitHub:

    • Make sure your PR is set to merge into the dev branch.
    • Use closing keywords in your PR description, and link the relevant issue.
    • In the PR description, add a description of the changes, any tests you've done, and describe how reviewers can test your changes.
    • Add your contributions to the CHANGELOG.md
    • Resolve any issues that are found by the PR checks (ruff, pyright, mypy)
    • Assign some folks as Reviewers
    • Assign yourself as "Assignee", and follow up on reviews. You are responsible for resolving any issues that are found, and doing the final merge, after you get an approval from Reviewers.
    • If you are still working on the branch, make it a "Draft" PR - you can add/reach out to Reviewers if you want early feedback, or wait until the PR is ready before assigning Reviewers.
    • If a new release should be created, notify Tom Arne Pedersen.

Testing PRs

  1. Check out the PR branch

  2. Update dependencies, re-install latest package, and run tests (ensure all pass):

    .venv\Scripts\activate.bat
    uv self update
    uv sync -U
    uv pip install -e .
    uv run pytest .
    
  3. Run any additional tests you want / care about / related to PR topic (in your virtual env or prepend uv run) e.g.:

    trafficgen gen-situation -o test_output
    

    and make edits to config or change this command to test new functionalities.

Metadata

Release files for trafficgen 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trafficgen 0.9.1
File Size Uploaded
trafficgen-0.9.1.tar.gz 287.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trafficgen 0.9.1
File Interpreter ABI Platform
trafficgen-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 327.6 kB

Release files / trafficgen-0.9.1.tar.gz

Download URL trafficgen-0.9.1.tar.gz
Size 287.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2b7fc9b2c86f01760ff691a38201f88515b3397d6d0269b2e68ad0560fbdec0b
BLAKE2b-256 checksum
How to use checksums
eaff4bc114f21a6112457decd76e9a12cfaee8d5add63039d04c6930373533f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / trafficgen-0.9.1-py3-none-any.whl

Download URL trafficgen-0.9.1-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
061b0d80b3f17e57e83a530acdacdd59de2b292438e2e8ccbfa269f212bfee12
BLAKE2b-256 checksum
How to use checksums
5f2da70496149706b5a8a08b5a423a828cbb103304f2e1fe7aab0d124f875fda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page