rustalgos
Coord
Class representing a coordinate.
Coord
Creates a Coord
with x
and y
coordinates.
Parameters
xy
Returns the Coord
as a tuple
of x
and y
.
Returns
validate
Validates the Coord.
hypot
Returns the pythagorean distance from this Coord
to another.
Parameters
The other coordinate to which to compute the Pythagorean distance.
difference
Returns the vector of the spatial difference between this Coord
and another.
Parameters
The other coordinate to which to compute the Pythagorean distance.
calculate_rotation
calculate_rotation_smallest
Calculates the angle between vec_a
and vec_b
.
Parameters
The vector of vec_a
.
The vector of vec_b
.
check_numerical_data
Checks the integrity of a numerical data array. data_arr: list[float]
distances_from_betas
Map distance thresholds to equivalent decay parameters at the specified cutoff weight . See distance_from_beta
for additional discussion.
It is generally not necessary to utilise this function directly.
Parameters
value/s to convert to decay parameters .
The cutoff weight on which to model the decay parameters .
Returns
A numpy array of decay parameters .
Notes
from cityseer.metrics import networks
# a list of betas
distances = [400, 200]
# convert to betas
betas = networks.beta_from_distance(distances)
print(betas) # prints: array([0.01, 0.02])
Most networks
module methods can be invoked with either distances
or betas
parameters, but not both. If using the distances
parameter, then this function will be called in order to extrapolate the decay parameters implicitly, using:
The default min_threshold_wt
of yields conveniently rounded parameters, for example:
200m | 0.02 |
400m | 0.01 |
800m | 0.005 |
1600m | 0.0025 |
betas_from_distances
Map decay parameters to equivalent distance thresholds at the specified cutoff weight .
It is generally not necessary to utilise this function directly.
Parameters
value/s to convert to distance thresholds .
An optional cutoff weight at which to set the distance threshold .
Returns
A list of distance thresholds .
Notes
from cityseer import rustalgos
# a list of betas
betas = [0.01, 0.02]
# convert to distance thresholds
d_max = rustalgos.distances_from_betas(betas)
print(d_max)
# prints: [400, 200]
Weighted measures such as the gravity index, weighted betweenness, and weighted land-use accessibilities are computed using a negative exponential decay function in the form of:
The strength of the decay is controlled by the parameter, which 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%. After an initially rapid decrease, the weightings decay ever more gradually in perpetuity; thus, once a sufficiently small weight is encountered it becomes computationally expensive to consider locations any farther away. The minimum weight at which this cutoff occurs is represented by , and the corresponding maximum distance threshold by .
Most networks
module methods can be invoked with either distances
or betas
parameters, but not both. If using the betas
parameter, then this function will be called in order to extrapolate the distance thresholds implicitly, using:
The default min_threshold_wt
of yields conveniently rounded walking thresholds, for example:
0.02 | 200m |
0.01 | 400m |
0.005 | 800m |
0.0025 | 1600m |
Overriding the default will adjust the accordingly, for example:
0.02 | 0.01 | 230m |
0.01 | 0.01 | 461m |
0.005 | 0.01 | 921m |
0.0025 | 0.01 | 1842m |
pair_distances_and_betas
Pair distances and betas, where one or the other parameter is provided.
Parameters
Distances corresponding to the local thresholds to be used for calculations. The parameters (for distance-weighted metrics) will be determined implicitly. If the distances
parameter is not provided, then the beta
parameter must be provided instead.
A , or array of to be used for the exponential decay function for weighted metrics. The distance
parameters for unweighted metrics will be determined implicitly. If the betas
parameter is not provided, then the distance
parameter must be provided instead.
The default min_threshold_wt
parameter can be overridden to generate custom mappings between the distance
and beta
parameters. See distance_from_beta
for more information.
Returns
Distances corresponding to the local thresholds to be used for calculations. The parameters (for distance-weighted metrics) will be determined implicitly. If the distances
parameter is not provided, then the beta
parameter must be provided instead.
A , or array of to be used for the exponential decay function for weighted metrics. The distance
parameters for unweighted metrics will be determined implicitly. If the betas
parameter is not provided, then the distance
parameter must be provided instead.
Notes
Networks should be buffered according to the largest distance threshold that will be used for analysis. This protects nodes near network boundaries from edge falloffs. Nodes outside the area of interest but within these buffered extents should be set to ‘dead’ so that centralities or other forms of measures are not calculated. Whereas metrics are not calculated for ‘dead’ nodes, they can still be traversed by network analysis algorithms when calculating shortest paths and landuse accessibilities.
avg_distances_for_betas
Calculate the mean distance for a given parameter.
Parameters
representing a spatial impedance / distance decay for which to compute the average walking distance.
The cutoff weight on which to model the decay parameters .
Returns
The average walking distance for a given .
Notes
from cityseer.metrics import networks
import numpy as np
distances = [100, 200, 400, 800, 1600]
print('distances', distances)
# distances [ 100 200 400 800 1600]
betas = networks.beta_from_distance(distances)
print('betas', betas)
# betas [0.04 0.02 0.01 0.005 0.0025]
print('avg', networks.avg_distance_for_beta(betas))
# avg [ 35.11949 70.23898 140.47797 280.95593 561.91187]
clip_wts_curve
Calculate the upper bounds for clipping weights produced by spatial impedance functions. 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
An array of distances corresponding to the local thresholds to be used for calculations.
An array of to be used for the exponential decay function for weighted metrics.
The spatial buffer distance corresponding to the tolerance for spatial inaccuracy.
Returns
An array of maximum weights at which curves for corresponding will be clipped.
clipped_beta_wt
DataEntry
DataEntry
is_assigned
DataMap
DataMap
progress_init
progress
insert
data_key: str The key for the added node. data_x: float The x coordinate for the added node. data_y: float The y coordinate for the added node. data_id: str | None An optional key for each datapoint. Used for deduplication.
entry_keys
get_entry
get_data_coord
count
is_empty
all_assigned
none_assigned
set_nearest_assign
set_next_nearest_assign
aggregate_to_src_idx
accessibility
mixed_uses
stats
AccessibilityResult
AccessibilityResult
MixedUsesResult
MixedUsesResult
StatsResult
StatsResult
hill_diversity
hill_diversity_branch_distance_wt
hill_diversity_pairwise_distance_wt
gini_simpson_diversity
shannon_diversity
raos_quadratic_diversity
NodePayload
NodePayload
validate
EdgePayload
EdgePayload
validate
NetworkStructure
NetworkStructure
dijkstra_tree_shortest
dijkstra_tree_simplest
dijkstra_tree_segment
local_node_centrality_shortest
local_node_centrality_simplest
local_segment_centrality
progress_init
progress
add_node
Parameters
The node key as str
.
The node’s x
coordinate.
The node’s y
coordinate.
The live
node attribute identifying if this node falls within the areal boundary of interest as opposed to those that fall within the surrounding buffered area. See the edge-rolloff section in the guide.
get_node_payload
get_node_weight
is_node_live
node_count
node_indices
add_edge
Add an edge to the NetworkStructure
. Edges are directed, meaning that each bidirectional street is represented twice: once in each direction; start/end nodes and in/out bearings will differ accordingly.
Parameters
Node index for the starting node.
Node index for the ending node.
The edge index, such that multiple edges can span between the same node pair.
Node key for the starting node.
Node key for the ending node.
The length
edge attribute should always correspond to the edge lengths in metres. This is used when calculating the distances traversed by the shortest-path algorithm so that the respective maximum distance thresholds can be enforced: these distance thresholds are based on the actual network-paths traversed by the algorithm as opposed to crow-flies distances.
The angle_sum
edge bearing should correspond to the total angular change along the length of the segment. This is used when calculating angular impedances for simplest-path measures. The in_bearing
and out_bearing
attributes respectively represent the starting and ending bearing of the segment. This is also used when calculating simplest-path measures when the algorithm steps from one edge to another.
The imp_factor
edge attribute represents an impedance multiplier for increasing or diminishing the impedance of an edge. This is ordinarily set to 1, therefore not impacting calculations. By setting this to greater or less than 1, the edge will have a correspondingly higher or lower impedance. This can be used to take considerations such as street gradients into account, but should be used with caution.
The edge’s inwards angular bearing.
The edge’s outwards angular bearing.
edge_references
get_edge_payload
validate
Validate Network Structure.
find_nearest
road_distance
closest_intersections
assign_to_network
node_xs: list[float]
node_xys: list[tuple[float, float]]
node_lives: list[bool]
node_ys: list[float]