rustalgos

Coord

Class representing a coordinate.

Coord

Coord
(
x : float
y : float
)

Creates a Coord with x and y coordinates.

Parameters

`x`
x coordinate.
`y`
y coordinate.

xy

xy
(
self
)->[ float float ]

Returns the Coord as a tuple of x and y.

Returns

`xy`
tuple[float, float]

validate

validate
(
self
)->[ bool ]

Validates the Coord.

hypot

hypot
(
self
other_coord : cityseer.rustalgos.Coord
)->[ float ]

Returns the pythagorean distance from this Coord to another.

Parameters

`other_coord`
Coord

The other coordinate to which to compute the Pythagorean distance.

difference

difference
(
self
other_coord : cityseer.rustalgos.Coord
)->[ Coord ]

Returns the vector of the spatial difference between this Coord and another.

Parameters

`other_coord`
Coord

The other coordinate to which to compute the Pythagorean distance.

calculate_rotation

calculate_rotation
(
point_a : cityseer.rustalgos.Coord
point_b : cityseer.rustalgos.Coord
)->[ float ]

calculate_rotation_smallest

calculate_rotation_smallest
(
vec_a : cityseer.rustalgos.Coord
vec_b : cityseer.rustalgos.Coord
)->[ float ]

Calculates the angle between vec_a and vec_b.

Parameters

`vec_a`
Coord

The vector of vec_a.

`vec_b`
Coord

The vector of vec_b.

check_numerical_data

check_numerical_data
(
data_arr : list[float]
)

Checks the integrity of a numerical data array. data_arr: list[float]

distances_from_betas

distances_from_betas
(
betas : list[float]
min_threshold_wt : float | None = None
)->[ ist[int ]

Map distance thresholds dmaxd_{max} to equivalent decay parameters β\beta at the specified cutoff weight wminw_{min}. See distance_from_beta for additional discussion.

It is generally not necessary to utilise this function directly.

Parameters

distance
int | tuple[int]

dmaxd_{max} value/s to convert to decay parameters β\beta.

min_threshold_wt
float

The cutoff weight wminw_{min} on which to model the decay parameters β\beta.

Returns

tuple[float]

A numpy array of decay parameters β\beta.

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:

β=log(wmin)dmax\beta = -\frac{log(w_{min})}{d_{max}}

The default min_threshold_wt of wmin=0.01831563888873418w_{min}=0.01831563888873418 yields conveniently rounded β\beta parameters, for example:

dmaxd_{max}β\beta
200m0.02
400m0.01
800m0.005
1600m0.0025

betas_from_distances

betas_from_distances
(
distances : list[int]
min_threshold_wt : float | None = None
)->[ ist[float ]

Map decay parameters β\beta to equivalent distance thresholds dmaxd_{max} at the specified cutoff weight wminw_{min}.

It is generally not necessary to utilise this function directly.

Parameters

betas
list[float]

β\beta value/s to convert to distance thresholds dmaxd_{max}.

min_threshold_wt
float | None

An optional cutoff weight wminw_{min} at which to set the distance threshold dmaxd_{max}.

Returns

distances
list[int]

A list of distance thresholds dmaxd_{max}.

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:

weight=exp(βdistance)weight = exp(-\beta \cdot distance)

The strength of the decay is controlled by the β\beta parameter, which reflects a decreasing willingness to walk correspondingly farther distances. For example, if β=0.005\beta=0.005 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 wminw_{min}, and the corresponding maximum distance threshold by dmaxd_{max}.

Example beta decays

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:

dmax=log(wmin)βd_{max} = \frac{log(w_{min})}{-\beta}

The default min_threshold_wt of wmin=0.01831563888873418w_{min}=0.01831563888873418 yields conveniently rounded dmaxd_{max} walking thresholds, for example:

β\betadmaxd_{max}
0.02200m
0.01400m
0.005800m
0.00251600m

Overriding the default wminw_{min} will adjust the dmaxd_{max} accordingly, for example:

β\betawminw_{min}dmaxd_{max}
0.020.01230m
0.010.01461m
0.0050.01921m
0.00250.011842m

pair_distances_and_betas

pair_distances_and_betas
(
distances : list[int] | None = None
betas : list[float] | None = None
min_threshold_wt : float | None = None
)->[ ist[int] list[float ]

Pair distances and betas, where one or the other parameter is provided.

Parameters

distances
list[int] | tuple[int]

Distances corresponding to the local dmaxd_{max} thresholds to be used for calculations. The β\beta parameters (for distance-weighted metrics) will be determined implicitly. If the distances parameter is not provided, then the beta parameter must be provided instead.

betas
tuple[float]

A β\beta, or array of β\beta 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.

min_threshold_wt
float

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
tuple[int]

Distances corresponding to the local dmaxd_{max} thresholds to be used for calculations. The β\beta parameters (for distance-weighted metrics) will be determined implicitly. If the distances parameter is not provided, then the beta parameter must be provided instead.

betas
tuple[float]

A β\beta, or array of β\beta 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

avg_distances_for_betas
(
betas : list[float]
min_threshold_wt : float | None = None
)->[ ist[float ]

Calculate the mean distance for a given β\beta parameter.

Parameters

beta
tuple[float]

β\beta representing a spatial impedance / distance decay for which to compute the average walking distance.

min_threshold_wt
float

The cutoff weight wminw_{min} on which to model the decay parameters β\beta.

Returns

tuple[float]

The average walking distance for a given β\beta.

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

clip_wts_curve
(
distances : list[int]
betas : list[float]
spatial_tolerance : int
)->[ ist[float ]

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 β\beta 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

distances
tuple[int]

An array of distances corresponding to the local dmaxd_{max} thresholds to be used for calculations.

betas
tuple[float]

An array of β\beta to be used for the exponential decay function for weighted metrics.

spatial_tolerance
int

The spatial buffer distance corresponding to the tolerance for spatial inaccuracy.

Returns

max_curve_wts
tuple[float]

An array of maximum weights at which curves for corresponding β\beta will be clipped.

clipped_beta_wt

clipped_beta_wt
(
beta : float
max_curve_wt : float
data_dist : float
)->[ float ]

DataEntry

DataEntry

DataEntry
(
data_key : str
x : float
y : float
data_id : str | None = None
nearest_assign : int | None = None
next_nearest_assign : int | None = None
)

is_assigned

is_assigned
(
self
)->[ bool ]

DataMap

DataMap

DataMap
( )

progress_init

progress_init
(
self
/
)

progress

progress
(
self
)->[ int ]

insert

insert
(
self
data_key : str
x : float
y : float
data_id : str | None = None
nearest_assign : int | None = None
next_nearest_assign : int | None = None
)

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

entry_keys
(
self
)->[ ist[str ]

get_entry

get_entry
(
self
data_key : str
)->[ DataEntry | None ]

get_data_coord

get_data_coord
(
self
data_key : str
)->[ Coord | None ]

count

count
(
self
)->[ int ]

is_empty

is_empty
(
self
)->[ bool ]

all_assigned

all_assigned
(
self
)->[ bool ]

none_assigned

none_assigned
(
self
)->[ bool ]

set_nearest_assign

set_nearest_assign
(
self
data_key : str
assign_idx : int
)

set_next_nearest_assign

set_next_nearest_assign
(
self
data_key : str
assign_idx : int
)

aggregate_to_src_idx

aggregate_to_src_idx
(
self
netw_src_idx : int
network_structure : cityseer.rustalgos.NetworkStructure
max_dist : int
jitter_scale : float | None = None
angular : bool | None = None
)->[ dict[str float ]

accessibility

accessibility
(
self
network_structure : cityseer.rustalgos.NetworkStructure
landuses_map : dict[str, str]
accessibility_keys : list[str]
distances : list[int] | None = None
betas : list[float] | None = None
angular : bool | None = None
spatial_tolerance : int | None = None
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ dict[str AccessibilityResult ]

mixed_uses

mixed_uses
(
self
network_structure : cityseer.rustalgos.NetworkStructure
landuses_map : dict[str, str]
compute_hill : bool | None = True
compute_hill_weighted : bool | None = True
compute_shannon : bool | None = False
compute_gini : bool | None = False
distances : list[int] | None = None
betas : list[float] | None = None
angular : bool | None = None
spatial_tolerance : int | None = None
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ MixedUsesResult ]

stats

stats
(
self
network_structure : cityseer.rustalgos.NetworkStructure
numerical_map : dict[str, float]
distances : list[int] | None = None
betas : list[float] | None = None
angular : bool | None = None
spatial_tolerance : int | None = None
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ StatsResult ]

AccessibilityResult

AccessibilityResult

AccessibilityResult
( )

MixedUsesResult

MixedUsesResult

MixedUsesResult
( )

StatsResult

StatsResult

StatsResult
( )

hill_diversity

hill_diversity
(
class_counts : list[int]
q : float
)->[ float ]

hill_diversity_branch_distance_wt

hill_diversity_branch_distance_wt
(
class_counts : list[int]
class_distances : list[float]
q : float
beta : float
max_curve_wt : float
)->[ float ]

hill_diversity_pairwise_distance_wt

hill_diversity_pairwise_distance_wt
(
class_counts : list[int]
class_distances : list[float]
q : float
beta : float
max_curve_wt : float
)->[ float ]

gini_simpson_diversity

gini_simpson_diversity
(
class_counts : list[int]
)->[ float ]

shannon_diversity

shannon_diversity
(
class_counts : list[int]
)->[ float ]

raos_quadratic_diversity

raos_quadratic_diversity
(
class_counts : list[int]
wt_matrix : list[list[float]]
alpha : float
beta : float
)->[ float ]

NodePayload

NodePayload

NodePayload
( )

validate

validate
(
self
)->[ bool ]

EdgePayload

EdgePayload

EdgePayload
( )

validate

validate
(
self
)->[ bool ]

NetworkStructure

NetworkStructure

NetworkStructure
( )

dijkstra_tree_shortest

dijkstra_tree_shortest
(
self
src_idx : int
max_dist : int
jitter_scale : float | None = None
)->[ ist[int] NodeVisit ]

dijkstra_tree_simplest

dijkstra_tree_simplest
(
self
src_idx : int
max_dist : int
jitter_scale : float | None = None
)->[ ist[int] NodeVisit ]

dijkstra_tree_segment

dijkstra_tree_segment
(
self
src_idx : int
max_dist : int
jitter_scale : float | None = None
)->[ ist[int] list[int] NodeVisit] EdgeVisit ]

local_node_centrality_shortest

local_node_centrality_shortest
(
self
distances : list[int] | None = None
betas : list[float] | None = None
compute_closeness : bool | None = True
compute_betweenness : bool | None = True
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ CentralityShortestResult ]

local_node_centrality_simplest

local_node_centrality_simplest
(
self
distances : list[int] | None = None
betas : list[float] | None = None
compute_closeness : bool | None = True
compute_betweenness : bool | None = True
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ CentralitySimplestResult ]

local_segment_centrality

local_segment_centrality
(
self
distances : list[int] | None = None
betas : list[float] | None = None
compute_closeness : bool | None = True
compute_betweenness : bool | None = True
min_threshold_wt : float | None = None
jitter_scale : float | None = None
pbar_disabled : bool | None = None
)->[ CentralitySegmentResult ]

progress_init

progress_init
(
self
/
)

progress

progress
(
self
)->[ int ]

add_node

add_node
(
self
node_key : str
x : float
y : float
live : bool
weight : float
)->[ int ]

Parameters

node_key
str

The node key as str.

x
float

The node’s x coordinate.

y
float

The node’s y coordinate.

live
bool

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_payload
(
self
node_idx : int
)->[ NodePayload ]

get_node_weight

get_node_weight
(
self
/
node_idx
)

is_node_live

is_node_live
(
self
node_idx : int
)->[ bool ]

node_count

node_count
(
self
)->[ int ]

node_indices

node_indices
(
self
)->[ ist[int ]

add_edge

add_edge
(
self
start_nd_idx : int
end_nd_idx : int
edge_idx : int
start_nd_key : str
end_nd_key : str
length : float
angle_sum : float
imp_factor : float
in_bearing : float
out_bearing : float
)->[ int ]

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

start_node_idx
str

Node index for the starting node.

end_node_idx
str

Node index for the ending node.

edge_idx
int

The edge index, such that multiple edges can span between the same node pair.

start_node_key
str

Node key for the starting node.

end_node_key
str

Node key for the ending node.

length
float

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 dmaxd_{max} 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.

angle_sum
float

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.

imp_factor
float

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.

in_bearing
float

The edge’s inwards angular bearing.

out_bearing
float

The edge’s outwards angular bearing.

edge_references

edge_references
(
self
)->[ ist[tuple[int int int ]

get_edge_payload

get_edge_payload
(
self
start_nd_idx : int
end_nd_idx : int
edge_idx : int
)->[ EdgePayload ]

validate

validate
(
self
)->[ bool ]

Validate Network Structure.

find_nearest

find_nearest
(
self
data_coord
max_dist : float
)->[ int | None float int | None ]

road_distance

road_distance
(
self
data_coord
nd_a_idx : int
nd_b_idx : int
)->[ float int | None int | None ]

closest_intersections

closest_intersections
(
self
data_coord
pred_map : list[int | None]
last_nd_idx : int
)->[ float int | None int | None ]

assign_to_network

assign_to_network
(
self
data_coord
max_dist : float
)->[ int | None int | None ]

node_xs: list[float]

node_xys: list[tuple[float, float]]

node_lives: list[bool]

node_ys: list[float]

CentralityShortestResult

CentralityShortestResult

CentralityShortestResult
( )

CentralitySimplestResult

CentralitySimplestResult

CentralitySimplestResult
( )

CentralitySegmentResult

CentralitySegmentResult

CentralitySegmentResult
( )

Viewshed

Viewshed

Viewshed
( )

progress_init

progress_init
(
self
/
)

progress

progress
(
self
)->[ int ]

visibility_graph

visibility_graph
(
self
bldgs_rast
view_distance : int
pbar_disabled : bool = False
)->[ Any]] Any]]] bool int float complex str bytes Union[bool int float complex str bytes]]] Any]] Any]]] bool int float complex str bytes Union[bool int float complex str bytes]]] Any]] Any]]] bool int float complex str bytes Union[bool int float complex str bytes ]

viewshed

viewshed
(
self
bldgs_rast
view_distance : int
origin_x : int
origin_y : int
pbar_disabled : bool = False
)->[ dtype[Any]] dtype[Any]]] bool int float complex str bytes _NestedSequence[Union[bool int float complex str bytes ]