Skip to main content

Systematic comparison of trip distribution laws and models in Python

Project description

PyTDLM

Systematic comparison of trip distribution laws and models in Python

DOI Test Build and Distribution PyPI Version PyPI Downloads Conda Version Conda Downloads

Description

The main purpose of these packages is to provide a rigorous framework for fairly comparing trip distribution laws and models, as described in Lenormand et al. (2016). This general framework relies on a two-step approach to generate mobility flows, separating the trip distribution law, gravity or intervening opportunities, from the modeling approach used to derive flows from this law.

To make this framework more accessible, we developed both an R package and a Python package, which replace the original Java scripts and extend their functionality.

PyTDLM is a Python port of the TDLM R package, with numpy-based implementations and parallel processing support for multiple exponent values.

Installation

Using conda

conda install -c conda-forge pytdlm

Using pip

pip install PyTDLM

From source

git clone https://github.com/PyTDLM/TDLM.git
cd PyTDLM
pip install -e .

Quick start

import numpy as np
from TDLM import tdlm

# Prepare your data
mi = np.array([100, 200, 150])  # Origin masses
mj = np.array([80, 180, 120])   # Destination masses
dij = np.array([[0, 10, 15],    # Distance matrix
                [10, 0, 8], 
                [15, 8, 0]])
Oi = np.array([50, 80, 60])     # Out-trips
Dj = np.array([40, 90, 50])     # In-trips
Tij_observed = np.array([[0, 25, 25],  # Observed trip matrix
                         [30, 0, 50],
                         [35, 35, 0]])

# Run simulation
exponent = np.arange(0.1, 1.01, 0.01)
results = tdlm.run_law_model(
    law='NGravExp',
    mass_origin=mi,
    mass_destination=mj, 
    distance=dij,
    exponent=exponent,
    model='DCM',
    out_trips=Oi,
    in_trips=Dj,
    repli=100
)

# Calculate goodness-of-fit
gof_results = tdlm.gof(sim=results, obs=Tij_observed, distance=dij)

# Print results for a given exponent
print(gof_results[0.1].to_markdown(index=False))

Documentation

For detailed documentation and examples, visit: https://rtdlm.github.io/PyTDLM/

Citation

If you use this library in your research, please cite: [Reference to come].

@software{PyTDLM,
  author = {Perrier, R., Gargiulo, G., Jayet, C. and Lenormand, M.},
  title = {PyTDLM: Systematic comparison of trip distribution laws and models in Python},
  year = {2025},
  note = {Reference forthcoming}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytdlm-0.2.2.tar.gz (80.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytdlm-0.2.2-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file pytdlm-0.2.2.tar.gz.

File metadata

  • Download URL: pytdlm-0.2.2.tar.gz
  • Upload date:
  • Size: 80.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pytdlm-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c47019d135e107ce9cbe4085c9854a70e48bde66905876328b6f3bce0b92f93d
MD5 e407cb5df5a57deaf8b1451e3bae8c4a
BLAKE2b-256 4e60a9e178357d7ecdf5bb57d0ee55a655fded719e2e2be14dd1e577426cc8ba

See more details on using hashes here.

File details

Details for the file pytdlm-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pytdlm-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pytdlm-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 185eb41c8d2911bff070d56cd70bcc4b9331d47ec0172023fa3d4c8444b2deae
MD5 1f58adbb65008771e0d624219ed862b4
BLAKE2b-256 c8e44e2260b05e5f3a8acfd009d109f837e9fce008fdad965a23c18c5d121e06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page