Skip to content

Commit

Permalink
Renames jitter_sdev & sets to default of zero.
Browse files Browse the repository at this point in the history
Adds jitter_scale to docs.

Removes progress bar test.
  • Loading branch information
songololo committed Nov 26, 2021
1 parent 3fd1052 commit 888873a
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 132 deletions.
12 changes: 6 additions & 6 deletions cityseer/algos/centrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def shortest_path_tree(edge_data: np.ndarray,
node_edge_map: Dict,
src_idx: int,
max_dist: float = np.inf,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False) -> Tuple[np.ndarray, np.ndarray]:
"""
All shortest paths to max network distance from source node
Expand Down Expand Up @@ -139,7 +139,7 @@ def shortest_path_tree(edge_data: np.ndarray,
# this will also happen for the first nodes that overshoot the boundary
# they will not be explored further because they have not been added to active
# jitter injects a small amount of stochasticity for rectlinear grids
jitter = np.random.normal(loc=0, scale=jitter_sdev)
jitter = np.random.normal(loc=0, scale=jitter_scale)
# shortest path heuristic differs for angular vs. not
if (angular and simpl_dist + jitter < tree_simpl_dist[nb_nd_idx]) or \
(not angular and short_dist + jitter < tree_short_dist[nb_nd_idx]):
Expand Down Expand Up @@ -255,7 +255,7 @@ def local_node_centrality(node_data: np.ndarray,
distances: np.ndarray,
betas: np.ndarray,
measure_keys: tuple,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False,
progress_proxy=None) -> np.ndarray:
# integrity checks
Expand Down Expand Up @@ -344,7 +344,7 @@ def local_node_centrality(node_data: np.ndarray,
node_edge_map,
src_idx,
max_dist=global_max_dist,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular)
tree_nodes = np.where(tree_map[:, 0])[0]
tree_preds = tree_map[:, 1]
Expand Down Expand Up @@ -437,7 +437,7 @@ def local_segment_centrality(node_data: np.ndarray,
distances: np.ndarray,
betas: np.ndarray,
measure_keys: tuple,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False,
progress_proxy=None) -> np.ndarray:
# integrity checks
Expand Down Expand Up @@ -516,7 +516,7 @@ def local_segment_centrality(node_data: np.ndarray,
node_edge_map,
src_idx,
max_dist=global_max_dist,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular)
tree_nodes = np.where(tree_map[:, 0])[0]
tree_preds = tree_map[:, 1]
Expand Down
12 changes: 6 additions & 6 deletions cityseer/algos/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def aggregate_to_src_idx(netw_src_idx: int,
node_edge_map: Dict,
data_map: np.ndarray,
max_dist: float,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False):
# this function is typically called iteratively, so do type checks from parent methods
netw_x_arr = node_data[:, 0]
Expand All @@ -311,7 +311,7 @@ def aggregate_to_src_idx(netw_src_idx: int,
node_edge_map,
netw_src_idx,
max_dist=max_dist,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular)
'''
Shortest tree dijkstra
Expand Down Expand Up @@ -380,7 +380,7 @@ def aggregate_landuses(node_data: np.ndarray,
mixed_use_other_keys: np.ndarray = np.array([]),
accessibility_keys: np.ndarray = np.array([]),
cl_disparity_wt_matrix: np.ndarray = np.array(np.full((0, 0), np.nan)),
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False,
progress_proxy=None) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""
Expand Down Expand Up @@ -498,7 +498,7 @@ def disp_check(disp_matrix):
node_edge_map,
data_map,
global_max_dist,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular)
# LANDUSES
mu_max_unique_cl = int(landuse_encodings.max() + 1)
Expand Down Expand Up @@ -587,7 +587,7 @@ def aggregate_stats(node_data: np.ndarray,
distances: np.ndarray,
betas: np.ndarray,
numerical_arrays: np.ndarray = np.array(np.full((0, 0), np.nan)),
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False,
progress_proxy=None) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray,
np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
Expand Down Expand Up @@ -655,7 +655,7 @@ def aggregate_stats(node_data: np.ndarray,
node_edge_map,
data_map,
global_max_dist,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular)
# IDW
# the order of the loops matters because the nested aggregations happen per distance per numerical array
Expand Down
14 changes: 10 additions & 4 deletions cityseer/metrics/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def compute_landuses(self,
accessibility_keys: list | tuple = None,
cl_disparity_wt_matrix: list | tuple | np.ndarray = None,
qs: list | tuple | np.ndarray = None,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False):
"""
This method wraps the underlying `numba` optimised functions for aggregating and computing various mixed-use and
Expand Down Expand Up @@ -464,6 +464,9 @@ def compute_landuses(self,
qs
The values of `q` for which to compute Hill diversity. This parameter is only required if computing one of
the Hill diversity mixed-use measures, by default None.
jitter_scale
The scale of random jitter to add to shortest path calculations, useful for situations with highly
rectilinear grids. `jitter_scale` is passed to the `scale` parameter of `np.random.normal`. Default of zero.
angular
Whether to use a simplest-path heuristic in-lieu of a shortest-path heuristic when calculating aggregations
and distances, by default False
Expand Down Expand Up @@ -648,7 +651,7 @@ def compute_landuses(self,
mixed_use_other_keys=np.array(mu_other_keys),
accessibility_keys=np.array(acc_keys),
cl_disparity_wt_matrix=np.array(cl_disparity_wt_matrix),
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular,
progress_proxy=progress_proxy)
if progress_proxy is not None:
Expand Down Expand Up @@ -760,7 +763,7 @@ def compute_stats(self,
stats_data_arrs: list | tuple | np.ndarray |
list[list | tuple | np.ndarray] |
tuple[list | tuple | np.ndarray],
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False):
"""
This method wraps the underlying `numba` optimised functions for computing statistical measures. The data is
Expand Down Expand Up @@ -837,6 +840,9 @@ def compute_stats(self,
[420, 300, 220, 250, 600] # occupants
]
```
jitter_scale
The scale of random jitter to add to shortest path calculations, useful for situations with highly
rectilinear grids. `jitter_scale` is passed to the `scale` parameter of `np.random.normal`. Default of zero.
angular
Whether to use a simplest-path heuristic in-lieu of a shortest-path heuristic when calculating aggregations
and distances, by default False
Expand Down Expand Up @@ -932,7 +938,7 @@ def compute_stats(self,
distances=np.array(self.Network.distances),
betas=np.array(self.Network.betas),
numerical_arrays=stats_data_arrs,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular,
progress_proxy=progress_proxy)
if progress_proxy is not None:
Expand Down
20 changes: 10 additions & 10 deletions cityseer/metrics/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,17 @@ def compute_centrality(self, **kwargs):
# provides access to the underlying centrality.local_centrality method
def node_centrality(self,
measures: list | tuple = None,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False):
"""
Parameters
----------
measures
A list or tuple of strings, containing any combination of the following `key` values, computed within the
respective distance thresholds of $d_{max}$.
jitter_sdev
The standard deviation for the amount of random jitter to add to shortest path calculations, useful for
situations with highly rectilinear grids. Set to zero to remove all jitter.
jitter_scale
The scale of random jitter to add to shortest path calculations, useful for situations with highly
rectilinear grids. `jitter_scale` is passed to the `scale` parameter of `np.random.normal`. Default of zero.
angular
A boolean indicating whether to use shortest or simplest path heuristics, by default False
Expand Down Expand Up @@ -827,7 +827,7 @@ def node_centrality(self,
np.array(self._distances),
np.array(self._betas),
measure_keys,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular,
progress_proxy=progress_proxy)
if progress_proxy is not None:
Expand All @@ -844,7 +844,7 @@ def node_centrality(self,
# provides access to the underlying centrality.local_centrality method
def segment_centrality(self,
measures: list | tuple = None,
jitter_sdev: float = 1.0,
jitter_scale: float = 0.0,
angular: bool = False):
"""
A list or tuple of strings, containing any combination of the following `key` values, computed within the
Expand All @@ -855,9 +855,9 @@ def segment_centrality(self,
measures
A list or tuple of strings, containing any combination of the following `key` values, computed within the
respective distance thresholds of $d_{max}$.
jitter_sdev
The standard deviation for the amount of random jitter to add to shortest path calculations, useful for
situations with highly rectilinear grids. Set to zero to remove all jitter.
jitter_scale
The scale of random jitter to add to shortest path calculations, useful for situations with highly
rectilinear grids. `jitter_scale` is passed to the `scale` parameter of `np.random.normal`. Default of zero.
angular
A boolean indicating whether to use shortest or simplest path heuristics, by default False
Expand Down Expand Up @@ -925,7 +925,7 @@ def segment_centrality(self,
np.array(self._distances),
np.array(self._betas),
measure_keys,
jitter_sdev=jitter_sdev,
jitter_scale=jitter_scale,
angular=angular,
progress_proxy=progress_proxy)
if progress_proxy is not None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='cityseer',
version='1.1.7',
version='1.2.0',
packages=['cityseer', 'cityseer.algos', 'cityseer.metrics', 'cityseer.tools'],
description='Computational tools for urban analysis',
url='https://github.com/benchmark-urbanism/cityseer-api',
Expand Down
Loading

0 comments on commit 888873a

Please sign in to comment.