rustalgos
Low-level internals. These are the Rust-backed structures and functions that power cityseer. They carry no stability guarantee and are subject to breaking changes from time to time. Users are encouraged to use the higher-level wrappers instead, which are more stable: the CityNetwork class, or the metrics and tools modules. The basic information below is provided for those who do wish to work with the lower-level internals.
Cityseer high-performance algorithms implemented in Rust.
avg_distances_for_betas
Calculate the mean distance corresponding to given beta parameters.
Parameters
parameters.
Optional cutoff weight .
Returns
The average walking distance for each beta.
Notes
from cityseer import rustalgos
distances = [100, 200, 400, 800, 1600]
betas = rustalgos.betas_from_distances(distances)
print("betas", betas)
# betas [0.04, 0.02, 0.01, 0.005, 0.0025]
avg = rustalgos.avg_distances_for_betas(betas)
print("avg", avg)
betas_from_distances
Convert distance thresholds () to decay parameters (betas). Requires distances > 0 and sorted in strictly increasing order. Uses a default minimum weight threshold.
Parameters
values (> 0, strictly increasing) to convert.
Optional cutoff weight (default: ~0.0183).
Returns
Corresponding decay parameters .
Raises
If inputs are invalid (empty, non-positive, not increasing).
Notes
from cityseer import rustalgos
distances = [200, 400, 800, 1600]
betas = rustalgos.betas_from_distances(distances)
print(betas) # prints: [0.02, 0.01, 0.005, 0.0025]
The parameter controls the strength of exponential distance decay:
This reflects a decreasing willingness to walk correspondingly farther distances. For example, if were to represent a person’s willingness to walk to a bus stop, then a location 100m distant would be weighted at 60% and a location 400m away would be weighted at 13.5%.

Uses the formula:
The default min_threshold_wt of yields conveniently rounded values, for example:
| 200m | 0.02 |
| 400m | 0.01 |
| 800m | 0.005 |
| 1600m | 0.0025 |
Overriding the default will adjust the accordingly.
check_numerical_data
Validates that all elements in a 2D numerical array are finite.
Raises
If any element is not finite (NaN or infinity).
clip_wts_curve
Calculate upper weight bounds for clipping distance decay curves based on spatial tolerance. Used when data point location has uncertainty defined by spatial_tolerance. Determine the upper weights threshold of the distance decay curve for a given based on the spatial_tolerance parameter. This is used by downstream functions to determine the upper extent at which weights derived for spatial impedance functions are flattened and normalised. This functionality is only intended for situations where the location of datapoints is uncertain for a given spatial tolerance.
Use distance based clipping with caution for smaller distance thresholds. For example, if using a 200m distance threshold clipped by 100m, then substantial distortion is introduced by the process of clipping and normalising the distance decay curve. More generally, smaller distance thresholds should generally be avoided for situations where datapoints are not located with high spatial precision.
Parameters
Distance thresholds ().
Decay parameters ().
Spatial buffer distance (uncertainty).
Returns
Maximum weights for clipping the decay curve for each beta.
clipped_beta_wt
Calculate a single weight using beta decay, clipped by a maximum weight. Applies , ensuring the result does not exceed max_curve_wt.
Parameters
The decay parameter .
The maximum allowed weight (from clip_wts_curve).
The distance to the data point.
Returns
The calculated (potentially clipped) weight. Returns 0.0 if calculation fails.
distances_from_betas
Convert decay parameters (betas) to distance thresholds (). Requires betas > 0 and sorted in strictly decreasing order. Uses a default minimum weight threshold.
Parameters
values (> 0, strictly decreasing) to convert.
Optional cutoff weight (default: ~0.0183).
Returns
Corresponding distance thresholds .
Raises
If inputs are invalid (empty, non-positive, not decreasing).
Notes
from cityseer import rustalgos
betas = [0.01, 0.02]
distances = rustalgos.distances_from_betas(betas)
print(distances) # prints: [400, 200]
Uses the formula:
The default min_threshold_wt of yields conveniently rounded distance thresholds, for example:
| 0.02 | 200m |
| 0.01 | 400m |
| 0.005 | 800m |
| 0.0025 | 1600m |
distances_from_seconds
Convert time in seconds to distance thresholds () based on speed.
It is generally not necessary to utilise this function directly.
The default speed_m_s of yields the following walking thresholds:
| 300 | 400m |
| 600 | 800m |
| 1200 | 1600m |
Setting the speed_m_s to a higher or lower number will affect the accordingly.]
Parameters
Time values in seconds.
Speed in meters per second.
Returns
Corresponding distance thresholds .
pair_distances_and_time
Resolve distances and seconds from either distances or minutes. Exactly one of distances or minutes must be provided.
Parameters
Walking speed in meters per second.
Distance thresholds in metres.
Time in minutes.
Returns
A tuple containing (distances, seconds).
Raises
If not exactly one of distances or minutes is provided, or if inputs are invalid.
seconds_from_distances
Convert distance thresholds () to time in seconds based on speed.
It is generally not necessary to utilise this function directly.
The default speed_m_s of yields the following walking times:
| 400m | 300 |
| 800m | 600 |
| 1600m | 1200 |
Setting the speed_m_s to a higher or lower number will affect the walking time accordingly.
Parameters
Distance thresholds .
Speed in meters per second.
Returns
Corresponding time values in seconds.