Git Product home page Git Product logo

benchmark-urbanism / cityseer-api Goto Github PK

View Code? Open in Web Editor NEW
90.0 90.0 5.0 246.31 MB

Computational tools for urban analysis

Home Page: https://cityseer.benchmarkurbanism.com

License: GNU Affero General Public License v3.0

Python 77.46% Rust 22.54%
architecture centrality geographical-information-system landuse morphometrics network-analysis network-centralities network-topology networks networkx numba numpy openstreetmap osmnx python3 shapely spatial-analysis spatial-data spatial-data-analysis urban-planning

cityseer-api's People

Contributors

martinfleis avatar songololo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cityseer-api's Issues

Add geoms to plots

Display the geometries for segments when plotting.

Requires a bit more thought about whether to further formalise and refine the plotting options...

Add geometry split to consolidation method?

The crawl procedure has been removed from the graph consolidation method and replaced with a by_neighbours strategy. This strategy better preserves topology.

A subsequent improvement would be to split parallel geometries where nodes are out of lock-step. This may remove the need for decomposition steps prior to final consolidation, which might result in cleaner and quicker consolidation.

Catch zero-length graphs

Zero-length node maps are caught and reported by the checks module, though it may be good to flag this at an earlier stage of graph creation.

Negative coordinates raise an error in node_centrality

Describe the bug
When using a network that has coordinate values below 0, like in case of EPSG 5514, node_centrality raises an error as you have a check there for this case.

To Reproduce
Steps to reproduce the behavior:

import geopandas
import momepy
import networkx as nx

from cityseer.tools import graphs
from cityseer.metrics import networks

df = geopandas.read_file(momepy.datasets.get_path("bubenec"), layer="streets").to_crs(5514)
# get compatible graph
G = momepy.gdf_to_nx(df)
nx.set_node_attributes(G, {n: {"x":n[0], "y":n[1]} for n in G.nodes})
nx.set_edge_attributes(G, {(i, v, k): {"geom":a["geometry"]} for i, v, k, a in G.edges(data=True, keys=True)})

nodes_gdf, network_structure = graphs.network_structure_from_nx(G, crs=df.crs)

nodes_gdf = networks.node_centrality(
    measures=["node_harmonic", "node_betweenness"],
    network_structure=network_structure,
    nodes_gdf=nodes_gdf,
    distances=[400],
)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/martin/Git/momepy/Untitled-1.ipynb Cell 10 in <cell line: 1>()
----> 1 nodes_gdf = networks.node_centrality(
      2     measures=["node_harmonic", "node_betweenness"],
      3     network_structure=network_structure,
      4     nodes_gdf=nodes_gdf,
      5     distances=[400],
      6 )

File ~/mambaforge/envs/geo_dev/lib/python3.10/site-packages/cityseer/metrics/networks.py:499, in node_centrality(measures, network_structure, nodes_gdf, distances, betas, jitter_scale, angular, min_threshold_wt)
    423 def node_centrality(
    424     measures: Union[list[str], tuple[str]],
    425     network_structure: structures.NetworkStructure,
   (...)
    431     min_threshold_wt: float = MIN_THRESH_WT,
    432 ) -> gpd.GeoDataFrame:
    433     r"""
    434     Compute node-based network centrality.
    435 
   (...)
    497 
    498     """
--> 499     network_structure.validate()
    500     _distances, _betas = pair_distances_betas(distances, betas, min_threshold_wt)
    501     # see centrality.local_centrality for integrity checks on closeness and betweenness keys
    502     # typos are caught below

File ~/mambaforge/envs/geo_dev/lib/python3.10/site-packages/numba/experimental/jitclass/boxing.py:61, in _generate_method.<locals>.wrapper(*args, **kwargs)
     59 @wraps(func)
     60 def wrapper(*args, **kwargs):
---> 61     return method(*args, **kwargs)

File ~/mambaforge/envs/geo_dev/lib/python3.10/site-packages/cityseer/structures.py:92, in validate()
     90     raise ValueError("X, Y and 'live' arrays are not the same length")
     91 if not np.all(np.isfinite(self.xs)) or not np.all(self.xs >= 0):
---> 92     raise ValueError("Missing or invalid start x data encountered.")
     93 if not np.all(np.isfinite(self.ys)) or not np.all(self.ys >= 0):
     94     raise ValueError("Missing or invalid start y data encountered.")

ValueError: Missing or invalid start x data encountered.

Expected behavior
The computation should normally work, this will not be the only use case where negative projected coordinates appear.

Issue with importing io

Hi,

When I try to import io using

from cityseer.tools import graphs, io

I am getting

TypeError: 'numpy._DTypeMeta' object is not subscriptable


Output from spyder call 'get_namespace_view':
/Users/mohammadalattar/opt/anaconda3/lib/python3.9/site-packages/spyder_kernels/utils/nsview.py:443: UserWarning: legacy printing option can currently only be '1.13', '1.21', or `False`
  np.set_printoptions(**np_printoptions

An error when importing cityseer

Hello,

I've successfully installed the cityseer, but when I tried to import graphs, io using

from cityseer.tools import graphs, io

an error occurred.
How could I handle it?
Many thanks

1675928103148

Consider distributed betweenness measures

Betweenness assigns a node to the (first) path on the shortest route.

Therefore, the node will be assigned to the first out of multiple equidistant routes from A to B.

When working with shortest or simplest paths, it is highly unlikely for exactly equal paths to exist; nevertheless, it would be nice to figure out a method for dispersing node assignments for routes that are approximately equal to each other. e.g. Manhattan-like grids where numerous approximately equal routes exist from A to B.

A drawback to the above is that this may substantially complicate the underlying shortest path algorithm because multiple predecessors have to be tracked if they are within some or another tolerance of each other...

A tempting strategy may be to modify the usual shortest path algorithm where updates to the routes in the shortest-path tree are randomly executed if within a small tolerance of the existing shortest path to the same node in the tree. e.g. assuming a 2% tolerance, then a newly found route of 98m would randomly override / not override an existing shortest-route of 100m. The problem with this approach is that all subsequent calculations for shortest / between paths will follow this same route... i.e. it is the same problem as before, just that the route isn't necessarily the first option.

Switch to rtree filter

It is worth comparing performance if switching from a simple pythagorean spatial filter to the shapely rtree filter.

Python 3.12 support

Hi,

I've noticed that cityseer pins requires-python = ">=3.10, <3.12". What is blocking support of Python 3.12?

Edit: The reason I am asking is that pip install cityseer tries to pull 1.2.1 because that seems to be the last one without that pin. And that version is broken due to #39. Even if it wasn't, it is quite out of date :).

Progress not updating when computing the shortest path node centrality on windows

Describe the bug
when running the shortest path node centrality the progress does not update. Running on VS code on windows 10
Capture

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

Add networkx conversion from momepy street network?

@martinfleis

I'm wondering about adding a conversion function for a momepy street network GeoDataFrame to cityseer compatible networkx MultiGraph .

Here is an initial sketch of what this might look like: momepy_to_cityseer

This would mainly be intended for people who want to:

  • run street network centralities on larger street networks
  • calculate network centralities using cityseer's methods which adapt the shortest-path algorithms to work for some situations which aren't necessarily covered by e.g. networkX (e.g. shortest path sidestepping issue)
  • calculate landuse accessibilities over the street network (weighted and unweighted)
  • calculate mixed-uses over the street network (weighted and unweighted)
  • aggregate statistics (e.g. building form metrics from momepy) using the street network as a backbone

I'm curious what your thoughts are on things to take into account so that this is useful, e.g.

  • would there be use cases where people might want to do a round-trip - e.g. momepy GeoDataFrame to cityseer then back to momepy? If so, the edge ids would need to be chained through. The drawback to a round-trip is that network cleaning or decomposition can't be done without losing the association.
  • the current conversion function doesn't take primal or dual into account, it just builds a network from the edges. This is probably a non-issue unless doing a round-trip as people can simply manipulate the graphs either end depending on what they want to do.
  • would there be more interest in going straight from a GeoDataFrame or would there be cases where it is better to go from a momepy formatted networkx Graph?

There are probably other things but that's all that comes to mind for now...

Add type checking for statistical data

Is your feature request related to a problem? Please describe.

Add type checking for statistical data aggregation - e.g. catch None and other invalid (per numpy / numba) data types

Convert numba selective workflow to Function types

Numba is introducing support for functions as first-class types. This means that the workflows in the core centrality and landuse methods can be parcelled into functions which can then be placed in a list depending on selected options.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.