API
Module h3_od.config
h3_od.config
Configuration loader for the project.
Reads settings from YAML configuration files in the config/ directory using
a singleton pattern so the files are parsed once and reused across modules.
The YAML config supports environment-specific sections defined under the
environments key in config.yml. Add, rename, or remove environments
by editing that YAML block — no Python changes required. Change the
:pydata:ENVIRONMENT constant below — or set the PROJECT_ENV environment
variable — to select the active environment.
Usage::
from h3_od.config import config, secrets, ENVIRONMENT
# dot-notation access
log_level = config.logging.level
# dict-style access
input_path = config["data"]["aoi_polygon"]
# secrets (loaded from config/secrets.yml)
gis_url = secrets.esri.gis_url
# check current environment
print(f"Running in {ENVIRONMENT} mode")
ENVIRONMENT = os.environ.get('PROJECT_ENV', 'dev')
module-attribute
ConfigNode
Immutable, attribute-accessible wrapper around nested dictionaries.
Supports both dot-notation (cfg.logging.level) and dict-style
(cfg["logging"]["level"]) access for convenience.
Source code in src/h3_od/config.py
get(key, default=None)
to_dict()
Recursively convert back to a plain dictionary.
Source code in src/h3_od/config.py
get_available_environments(config_path=None)
Return the environment names defined in config.yml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path | str | None
|
Explicit path to a YAML file. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: Sorted list of environment keys found under the |
list[str]
|
|
list[str]
|
"olympia_walk"]``). |
Source code in src/h3_od/config.py
load_config(config_path=None, environment=None)
Load the main project configuration for a given environment.
Top-level keys (e.g. project) are always loaded. Then the
environment-specific section (environments.<env>) is deep-merged on
top, so environment values override any shared defaults.
Available environments are introspected from the environments key in
config.yml — add or remove sections there to define your own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path | str | None
|
Explicit path to a YAML file. Defaults to
|
None
|
environment
|
str | None
|
One of the keys under |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ConfigNode |
ConfigNode
|
A recursively accessible configuration object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the requested environment is not defined in
|
Source code in src/h3_od/config.py
load_secrets(secrets_path=None)
Load project secrets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
secrets_path
|
Path | str | None
|
Explicit path to a YAML file. Defaults to
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ConfigNode |
ConfigNode
|
A recursively accessible secrets object. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the secrets file does not exist. Copy
|
Source code in src/h3_od/config.py
Module h3_od.proximity
Proximity streamlines the process of calculating distance metrics using Esri Network Analyst.
get_aoi_h3_origin_destination_distance_parquet(area_of_interest, h3_resolution, parquet_path, network_dataset=None, travel_mode='Walking Distance', max_distance=5.0, search_distance=1.0, origin_batch_size=250, output_batch_size=250, append=True)
Create an origin-destination matrix and save it to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
area_of_interest
|
Union[str, Path, Geometry, List[Geometry]]
|
Feature Clas or Geometry object describing the area of interest to generate an origin-destination matrix for using H3 indices. |
required |
h3_resolution
|
int
|
H3 resolution to use when generating an origin-destination matrix. |
required |
parquet_path
|
Union[str, Path]
|
Path where the origin-destination table will be saved as Parquet. |
required |
network_dataset
|
Optional[Path]
|
Optional path to network dataset to use. |
None
|
travel_mode
|
Optional[str]
|
Travel mode to use with the network dataset. Default is |
'Walking Distance'
|
max_distance
|
Optional[float]
|
Maximum distance (in miles) to search from the origin to the destinations. Default is |
5.0
|
search_distance
|
Optional[float]
|
Distance to search from the origin or destination locations to find a routable edge.
Default is |
1.0
|
origin_batch_size
|
Optional[int]
|
Number of origins to look up per batch. Default is |
250
|
output_batch_size
|
Optional[int]
|
Number of origin locations to output from a solve at a time. This frequently is the
bottleneck causing memory overruns, so if troubleshooting, try reducing this size first. The default is
|
250
|
append
|
Optional[bool]
|
Whether to append or replace existing results. The default is |
True
|
.. note::
If encountering memory errors during solves, try reducing the ``output_batch_size``. This reduces the number
of records saved to memory before being written to disk. If still encountering issues, also try reducing the
``origin_batch_size``. This is the number of origins submitted to each solve operation.
Returns:
| Type | Description |
|---|---|
Path
|
Path to where Parquet dataset is saved. |
Source code in src/h3_od/proximity.py
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | |
get_h3_neighbors(origin_destination_dataset, h3_origin, distance=3.75, warn_on_fail=False)
Get neighbor H3 indices with distance from an origin H3 index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_destination_dataset
|
Union[Dataset, str, Path]
|
Origin-destination PyArrow dataset or path to Parquet dataset. |
required |
h3_origin
|
str
|
Origin H3 index. |
required |
distance
|
float
|
Distance around origin to search for. Default is |
3.75
|
warn_on_fail
|
bool
|
Whether to warn if no results found. Default is |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Pandas dataframe with destination indices and distance. |
Source code in src/h3_od/proximity.py
get_h3_origin_destination_distance(origin_destination_dataset, h3_origin, h3_destination=None, add_geometry=False, warn_on_fail=True)
Given an origin and destination H3 index, get the distance between the indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_destination_dataset
|
Union[str, Path]
|
Origin-destination PyArrow dataset or path to Parquet dataset. |
required |
h3_origin
|
str
|
Origin H3 index. |
required |
h3_destination
|
Optional[str]
|
Destination H3 index. Optional. If not provided, all potential H3 destinations will be returned. |
None
|
add_geometry
|
Optional[bool]
|
Whether to add a destination indices' geometry. This will return a Spatially Enabled Dataframe. |
False
|
warn_on_fail
|
Optional[bool]
|
Whether to warn if no results found. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Distance and travel time between H3 indices. |
Source code in src/h3_od/proximity.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 | |
get_h3_origin_destination_distance_using_coordinates(origin_destination_dataset, origin_coordinates, destination_coordinates, h3_resolution=10, warn_on_fail=True)
Given origin and destination coordinates, get the distance between using an H3 lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_destination_dataset
|
Union[Dataset, str, Path]
|
Origin-destination PyArrow dataset or path to Parquet dataset. |
required |
origin_coordinates
|
Union[Tuple[float], List[float]]
|
Origin coordinates in WGS84. |
required |
destination_coordinates
|
Union[Tuple[float], List[float]]
|
Destination coordinates in WGS84. |
required |
h3_resolution
|
int
|
H3 resolution origin-destination dataset is using. |
10
|
warn_on_fail
|
bool
|
Whether to warn if no results found. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Distance between origin and destination locations. |
Source code in src/h3_od/proximity.py
get_nearest_origin_destination_neighbor(origin_destination_dataset, origin_id, distance=0.5, warn_on_fail=False)
Get nearest neighbor unique identifier to an origin identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_destination_dataset
|
Union[Dataset, str, Path]
|
Origin-destination PyArrow dataset or path to Parquet dataset. |
required |
origin_id
|
int
|
Unique identifier for origin. |
required |
distance
|
float
|
Distance around origin to search for. Default is |
0.5
|
warn_on_fail
|
bool
|
Whether to warn if no results found. Default is |
False
|
Returns:
| Type | Description |
|---|---|
Union[str, int]
|
Unique identifier for the destination. |
Source code in src/h3_od/proximity.py
get_network_dataset_layer(network_dataset=None)
Get a network dataset layer, optionally using default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dataset
|
Optional[Path]
|
Optional path to network dataset being used. |
None
|
Note
If not specified, uses network solver set in Environment settings.
Returns:
| Type | Description |
|---|---|
Layer
|
NAX Layer. |
Source code in src/h3_od/proximity.py
get_network_travel_modes(network_dataset=None)
Get the travel modes, which can be used when solving for a network.
Note
If not specified, uses network solver set in Environment settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dataset
|
Optional[Path]
|
Optional path to network dataset being used. |
None
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of travel mode name strings available for the network dataset. |
Source code in src/h3_od/proximity.py
get_origin_destination_cost_matrix_solver(network_dataset=None, travel_mode='Walking Distance', max_distance=5.0, search_distance=0.25)
Create and configure an ArcPy NAX Origin-Destination Cost Matrix solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_dataset
|
Optional[Path]
|
Optional path to network dataset to use. |
None
|
travel_mode
|
Optional[str]
|
Travel mode to use with the network dataset. Default is |
'Walking Distance'
|
max_distance
|
Optional[float]
|
Maximum distance (in miles) to search from the origin to the destinations. Default is |
5.0
|
search_distance
|
Optional[float]
|
Distance to search from the origin or destination locations to find a routable edge.
Default is |
0.25
|
Returns:
| Type | Description |
|---|---|
OriginDestinationCostMatrix
|
ArcPy NAX Origin-Destination Matrix Solver. |
Source code in src/h3_od/proximity.py
get_origin_destination_distance_parquet_from_arcgis_features(h3_features, parquet_path, h3_index_column='GRID_ID', network_dataset=None, travel_mode='Walking Distance', max_distance=5.0, search_distance=1.0)
Create an origin-destination matrix from ArcGIS features, a Feature Class with H3 indices, and save it to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h3_features
|
Union[str, Path]
|
Path to H3 feature class created for area of interest using ArcGIS Pro. |
required |
parquet_path
|
Union[str, Path]
|
Path where the origin-destination table will be saved as Parquet. |
required |
h3_index_column
|
str
|
Column in H3 feature class containing the H3 indices. Default is |
'GRID_ID'
|
network_dataset
|
Optional[Path]
|
Optional path to network dataset to use. |
None
|
travel_mode
|
str
|
Travel mode to use with the network dataset. Default is |
'Walking Distance'
|
max_distance
|
float
|
Maximum distance (in miles) to search from the origin to the destinations. Default is |
5.0
|
search_distance
|
float
|
Distance to search from the origin or destination locations to find a routable edge.
Default is |
1.0
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to where Parquet dataset is saved. |
Source code in src/h3_od/proximity.py
get_origin_destination_neighbors(origin_destination_dataset, origin_id, distance=0.5, warn_on_fail=False)
Get neighbor unique identifiers surrounding an origin identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_destination_dataset
|
Union[Dataset, str, Path]
|
Origin-destination PyArrow dataset or path to Parquet dataset. |
required |
origin_id
|
int
|
Unique identifier for origin identifier. |
required |
distance
|
float
|
Distance around origin to search for. Default is |
0.5
|
warn_on_fail
|
bool
|
Whether to warn if no results found. Default is |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Pandas dataframe with destination indices and distance. |
Source code in src/h3_od/proximity.py
get_origin_destination_oid_col(input_features, id_column)
Determine the unique identifier column for origin or destination features.
Resolves the appropriate identifier column name depending on the input type.
For feature classes and layers, falls back to the OID field when no column is
explicitly provided. For DataFrames the first column is used, and for other
iterables the default "oid" is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
Union[Layer, str, Path, Iterable, DataFrame]
|
The origin or destination features as a layer, feature class path, iterable, or Spatially Enabled DataFrame. |
required |
id_column
|
str
|
Explicit column name to use as the unique identifier. When
|
required |
Returns:
| Type | Description |
|---|---|
str
|
Name of the unique identifier column for the given input features. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the explicitly provided |
Source code in src/h3_od/proximity.py
get_origin_destination_parquet(origin_h3_indices, parquet_path, destination_h3_indices=None, network_dataset=None, travel_mode='Walking Distance', max_distance=5.0, search_distance=0.25, origin_batch_size=250, output_batch_size=250, append=True)
Create an origin-destination matrix between two lists of H3 indices and save to parquet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin_h3_indices
|
Union[list, tuple]
|
Origin H3 indices, the starting locations, for the origin-destination solve. |
required |
parquet_path
|
Union[str, Path]
|
Path where the origin-destination table will be saved as Parquet. |
required |
destination_h3_indices
|
Optional[Iterable]
|
Destination H3 indices, the ending locations, for the origin-destination solve. |
None
|
network_dataset
|
Optional[Path]
|
Optional path to network dataset to use. |
None
|
travel_mode
|
Optional[str]
|
Travel mode to use with the network dataset. Default is |
'Walking Distance'
|
max_distance
|
Optional[float]
|
Maximum distance (in miles) to search from the origin to the destinations. Default is |
5.0
|
search_distance
|
Optional[float]
|
Distance to search from the origin or destination locations to find a routable edge.
Default is |
0.25
|
origin_batch_size
|
Optional[int]
|
Number of origin locations to use per origin-destination solve. If experiencing memory
overruns, reduce the batch size. The default is |
250
|
output_batch_size
|
Optional[int]
|
Number of origin locations to output from a solve at a time. This frequently is the
bottleneck causing memory overruns, so if troubleshooting, try reducing this size first. The default is
|
250
|
append
|
Optional[bool]
|
Whether to append or replace existing results. The default is |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to where Parquet dataset is saved. |
Source code in src/h3_od/proximity.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |
validate_h3_index_list(input_features)
Validate and normalize a list of H3 indices into tuples of index strings and point geometries.
Handles H3 indices provided as hexadecimal strings, integer strings, or native integers,
converting them to a consistent list of (h3_index, PointGeometry) tuples suitable for
use with ArcPy network analysis workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
List[Union[str, int]]
|
List of H3 indices as hexadecimal strings, numeric strings, or integers. |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[str, PointGeometry]]
|
List of tuples where each element is an H3 index string paired with its corresponding |
List[Tuple[str, PointGeometry]]
|
|
Source code in src/h3_od/proximity.py
validate_origin_destination_inputs(input_features)
Validate and normalize origin or destination input features for network analysis.
Accepts a variety of input formats — H3 index lists, identifier-geometry tuples, ArcPy layers, Spatially Enabled DataFrames, or paths to feature classes — and converts them into a consistent format (layer path or feature set) that can be consumed by the ArcPy NAX origin-destination cost matrix solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
Union[List[Union[int, str]], Iterable[Tuple[Union[int, str], Geometry]], Layer, DataFrame, str, Path]
|
Input features in one of the following forms:
|
required |
Returns:
| Type | Description |
|---|---|
Union[Layer, str, FeatureSet]
|
The validated input features as an |
Union[Layer, str, FeatureSet]
|
layer reference, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If geometry type is not Point or Polygon, or if a DataFrame fails spatial validation. |
Source code in src/h3_od/proximity.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
Module h3_od.distance_decay
Functions enabling calculation of distance decay, applying a S-shaped sigmoid curve to model distance decay.
get_bus_stop_distance_decay_index(distance)
Get the distance decay coefficient for a bus stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
Union[float, int]
|
Walking distance in miles to the bus stop. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Sigmoid distance decay index between 0.0 and 1.0 for the given bus stop distance. |
Source code in src/h3_od/distance_decay.py
get_light_rail_stop_distance_decay_index(distance)
Get the distance decay coefficient for a light rail stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
Union[float, int]
|
Walking distance in miles to the light rail stop or station. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Sigmoid distance decay index between 0.0 and ~0.98 for the given light rail stop distance. |
Source code in src/h3_od/distance_decay.py
get_sigmoid_distance_decay_index(distance, steepness, offset)
Get sigmoid distance decay index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
Union[float, int]
|
Distance to calculate decay for. |
required |
steepness
|
Union[float, int]
|
Controls how sharply the decay curve transitions from 1 to 0. Higher values produce a steeper drop-off. |
required |
offset
|
Union[float, int]
|
Distance value at which the decay index equals 0.5, shifting the midpoint of the sigmoid curve along the distance axis. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Sigmoid distance decay index between 0.0 and 1.0. |
Source code in src/h3_od/distance_decay.py
Module h3_od.utils
get_arcgis_polygon_for_h3_index(h3_index)
For a single H3 index, get the ArcGIS Polygon geometry for the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h3_index
|
Union[str, int]
|
H3 index. |
required |
Returns:
| Type | Description |
|---|---|
Polygon
|
ArcGIS Polygon geometry for the index. |
Source code in src/h3_od/utils/h3_arcgis.py
get_logger(logger_name=None, level='INFO', logfile_path=None, log_format='%(asctime)s | %(name)s | %(levelname)s | %(message)s', propagate=True, add_stream_handler=True, add_arcpy_handler=False)
Get Python :class:Logger<logging.Logger> configured to provide stream, file or, if available, ArcPy output.
The way the method is set up, logging will be routed through ArcPy messaging using :class:ArcpyHandler if
ArcPy is available. If ArcPy is not available, messages will be sent to the console using a
:class:StreamHandler<logging.StreamHandler>. Next, if the logfile_path is provided, log messages will also
be written to the provided path to a logfile using a :class:FileHandler<logging.FileHandler>.
Valid log_level inputs include:
* DEBUG - Detailed information, typically of interest only when diagnosing problems.
* INFO - Confirmation that things are working as expected.
* WARNING or WARN - An indication that something unexpected happened, or indicative of some problem in the
near future (e.g. "disk space low"). The software is still working as expected.
* ERROR - Due to a more serious problem, the software has not been able to perform some function.
* CRITICAL - A serious error, indicating that the program itself may be unable to continue running.
Note
Logging levels can be provided as strings (e.g. 'DEBUG'), corresponding integer values or using the
logging module constants (e.g. logging.DEBUG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger_name
|
Optional[str]
|
Name of the logger. If |
None
|
level
|
Optional[Union[str, int]]
|
Logging level to use. Default is INFO. |
'INFO'
|
log_format
|
Optional[str]
|
Format string for the logging messages. Default is |
'%(asctime)s | %(name)s | %(levelname)s | %(message)s'
|
propagate
|
bool
|
If |
True
|
logfile_path
|
Union[Path, str]
|
Where to save the logfile if file output is desired. |
None
|
add_stream_handler
|
bool
|
If |
True
|
add_arcpy_handler
|
bool
|
If |
False
|
logger = get_logger('DEBUG')
logger.debug('nauseatingly detailed debugging message')
logger.info('something actually useful to know')
logger.warning('The sky may be falling')
logger.error('The sky is falling.')
logger.critical('The sky appears to be falling because a giant meteor is colliding with the earth.')
Source code in src/h3_od/utils/_logging.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_pyarrow_dataset_from_parquet(dataset_path)
Load a Parquet dataset from disk into a PyArrow Dataset.
Convenience wrapper around pyarrow.dataset.dataset that applies Hive-style
partitioning, which is the partitioning scheme used by the origin-destination
Parquet outputs in this project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
Path
|
Path to the Parquet file or directory containing the partitioned Parquet dataset. |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
A |