The Human Mobility Index Python package - hmi
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()
Pairs that cannot be reached (e.g. London over land only) 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:
and the package itself
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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hmi-0.2.tar.gz | 25.3 kB | Without provenance | Details for hmi-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hmi-0.2-py3-none-any.whl | Python 3 | none | any | Details for hmi-0.2-py3-none-any.whl |
Total release size: 48.3 kB
Release files / hmi-0.2.tar.gz
| Download URL | hmi-0.2.tar.gz |
|---|---|
| Size | 25.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17e451d2bed3f859b575c44d72a5cbc2ac3a0b4ffccf8827417d095c5bce9c28
|
|
BLAKE2b-256 checksum How to use checksums |
6fa6b081dc78b5e5c80813b582b3a58092be492265b0f332c9d9b1f1322d8cfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / hmi-0.2-py3-none-any.whl
| Download URL | hmi-0.2-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f957a7d427210c22d8153124195b5a8ba98866e63d634d1ea23a0523f03ebf0
|
|
BLAKE2b-256 checksum How to use checksums |
21d1683963e17561f964f1327780c173b19dc0c3d9246287c7e0d4f197c456df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for hmi 0.2
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.