Skip to main content

The Human Mobility Index Python package - hmi

PyPiVersion Pyversions ReadTheDocs DOI

The hmi package is a python module that provides an interface to compute distances between locations based on Özak's (2018, 2010) Human Mobility Index. There are three main classes of computations based on the Human Mobility Index:

  • HMI: Only land based mobility
  • HMISea: Land based mobility and pre-1500CE seafaring technologies
  • HMIOcean: Land based mobility and post-1500CE seafaring technologies

It includes tools to

  • Compute distances between locations
  • Compute isolation measures for locations (see e.g. Ashraf, Galor, and Özak (2010))
  • Generate optimal routes as shape files
  • Export optimal travel times, routes, etc. to shape files, CSV files, etc

Install

The package depends on GDAL (through georasters and rasterio), which pip cannot build without a system GDAL library. The best way to install is to first create a mamba/conda environment with the geospatial dependencies from conda-forge:

mamba create --name HMI --override-channels -c conda-forge python=3.12 pip gdal geopandas georasters rasterio scikit-image requests tqdm

activate the environment

mamba activate HMI

then

pip install hmi

or

pip install git+https://github.com/human-mobility-index/hmi.git

The first time you import hmi, the package downloads the HMI cost surfaces (about 4.5 GB) from Zenodo into its data/ folder. This is done only once.

Example Usage: HMI

Sources and destinations are (Geo)Pandas data frames with latitude and longitude (or projected CEA x/y) columns. Distances are measured in weeks of travel.

import pandas as pd
import hmi

sources = pd.DataFrame({'name': ['Addis Ababa', 'London'],
                        'lat': [9.03, 51.51], 'lon': [38.74, -0.13]})
destinations = pd.DataFrame({'name': ['Cairo', 'Beijing', 'Sydney'],
                             'lat': [30.04, 39.90, -33.87], 'lon': [31.24, 116.41, 151.21]})

# Land-only mobility (use hmi.HMISea to add pre-1500CE seafaring)
A = hmi.HMI(sources, destinations, lat='lat', lon='lon')
A.correct_data()             # move points that fall off the cost surface onto it
A.HMIdistance(routes=True)   # travel times, isolation and optimal routes
A.hmidist                    # GeoDataFrame with one row per reachable pair

# Regions closest (in travel time) to each source
regions = A.voronoi()

correct_data(maxmove=100) moves each point that falls off the cost surface (e.g. a coastal city whose cell is in the sea) to the nearest valid cell within maxmove cells; points with no valid cell that close are left where they are. By default points are assigned to cells by rounding their coordinates, as in georasters; pass floor=True to hmi.HMI/hmi.HMISea to use the cell that contains each point instead.

Pairs that cannot be reached (e.g. London over land only, or points that are still off the cost surface) are dropped from hmidist. Use A.HMIdistance(export_shape=True, export_raster=True, path='./') to write the routes as GeoJSON and the travel-time surfaces as GeoTIFFs.

Testing

From a clone of the repository, inside the environment above:

pip install pytest
pytest

The tests compute HMI and HMISea distances, isolation, routes and Voronoi regions for a few world cities and compare them with known values.

Citation

If you use the package please cite:

Özak, Ömer. "Distance to the pre-industrial technological frontier and economic development." Journal of Economic Growth 23.2 (2018): 175-221.

Özak, Ömer. "The voyage of homo-economicus: Some economic measures of distance." Department of Economics, Brown University (2010).

and the package itself

Özak, Ömer. “The Human Mobility Index Python Package - hmi”. Zenodo, December 7, 2024. https://doi.org/10.5281/zenodo.14291912.

Issues

Find a bug? Report it via github issues by providing

  • a link to download the smallest possible raster and vector dataset necessary to reproduce the error
  • python code or command to reproduce the error
  • information on your environment: versions of python, gdal and numpy and system memory

Copyright

© Ömer Özak (2014)

This code and data is provided under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) License and GPLv3.

Metadata

Release files for hmi 0.3

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

Source distribution (sdist)

Source distribution for hmi 0.3
File Size Uploaded Provenance Actions
hmi-0.3.tar.gz 27.2 kB Without provenance Details for hmi-0.3.tar.gz

Built distribution (wheel)

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

Total release size: 50.9 kB

Release files / hmi-0.3.tar.gz

Download URL hmi-0.3.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8430bf8ad1690cb87096318e09b5a56e01c3d7629b2cf869fd0df5d52639c1b6
BLAKE2b-256 checksum
How to use checksums
8563d9c092a4d06c65e7b628bb2844e4b62b1ac93bff41098fc033e0d6658972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.17

Release files / hmi-0.3-py3-none-any.whl

Download URL hmi-0.3-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6e5f7038322b9f364148656ef32156a0b34764091f400f6e8fa12806c5e6ae7
BLAKE2b-256 checksum
How to use checksums
8a03361fe001b7d7d7aaaa77b8fa786ef4d472a83b2ed35cf75d764b757e055c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.17

Security for hmi 0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files No provenance

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