Skip to main content

Weighted aggregations along the local street network

Project description

pandana2

An example aggregating home values in Oakland. This is a screenshot - click here and scroll to the bottom for an interative map.

Screenshot 2025-04-11 at 4 48 27 PM

Motivating use case

The motivating use case of this library is to perform a mean of home prices (or anything else) in cities using local street networks. This solves two problems:

  1. We use network distance instead of "crows flies" distance because home prices on opposite sides of a freeway, for instance, are not as related as homes on a locally connected street network.
  2. Using smoothly overlapping distances along the street network reduces discontinuities that occur when observations are aggregated into polygons.

In short, the goal of this library is to compute weighted aggregations of all the observations within a certain network distance (e.g. 1500 meters or so) from every origin street intersection along the local street network. Weighted averages are easily computed so that observations closer to the origin node can be weighted higher.

Relationship to 2015 pandana

The original pandana was written during my graduate research with Paul Waddell at UC Berkeley. It leverages a huge C++ library for Contraction Hierachies which I eventually realized was useful to the routing queries but not useful to the aggregation queries. 10 years later, I finally got around to rewriting the library to not use C++ and only do the aggregations.

The "get nodes within X meters of each origin node in the network" part is written in numba. The rest is vanilla pandas. This should greatly ease extension and maintenance of the library since it's less than 1000 lines of code so far and much easier to deploy since it doesn't have to be compiled.

This version has feature parity with the 2015 version for the aggregations: it supports sum, mean, median, standard deviation, min, and max with no decay, linear decay and exponential decay. This version has weighted mean, weighted median, and weighted standard deviation which the previous version did not have. Additional aggregations and decays should be quite easy to add.

Example Notebook

The example Notebook is the best place to start to use this library. View the very short example Notebook here. Note the interactive map at the bottom of the notebook.

Documentation

There's just not a ton of documentation requred. Follow the example to see how to get a network and how to map data to the network. Otherwise, the only method that matters is:

def aggregate(
  values: pd.Series,
  decay_func: PandanaDecayFunction,
  aggregation: Aggregation | dict[str, Aggregation],
) -> pd.Series | pd.DataFrame:

values is a series where the index is node_ids from the nodes of the network and the values are floating point values you want to aggregate. In other words, it's the values and the node_ids they are located at (use the nearest_nodes method to assign node ids). node_ids can and likely will be repeated in the index (i.e. not unique).

decay_func is either pandana2.NoDecay, pandana2.LinearDecay or pandana2.ExponentialDecay which defines how to map a distance along the network to a weight to be used in one of the aggregations. The idea is that observations futher away should matter less when doing each aggregation, or you can use NoDecay to weight them equallly.

aggregation is usually a string like "sum", "mean", "min", "max", "median", "std" (standard deviation). All of the aggregations can be weighted except min and max which will ignore the weights. You can pass a dict of aggregations to compute more than one aggregation for the same input Series.

The method will return a Series which is indexed the same as the nodes on the network. NaN will be returned if there are no observations within the distance requested. A DataFrame will be returned in the case the aggregation parameter is a dictionary.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandana2-0.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandana2-0.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pandana2-0.0.1.tar.gz.

File metadata

  • Download URL: pandana2-0.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pandana2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ed69d9d0ce7d757b671ed84e2291aa5bef45bfe6379e888fcf2c20fa4c98d711
MD5 41ba0f9856174ef10dd97496e6b0d08a
BLAKE2b-256 49404b78b44b8546a6aad3b67bd27985f2dd24cd2fd3da8fe23d721ee9a3bcd7

See more details on using hashes here.

File details

Details for the file pandana2-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pandana2-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pandana2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4861d26b9c8f86741bff613712e5d7d7c4d2f252ff0297250e5e90eea7e8c75d
MD5 4f56a427bdedf6bc2b02de51c4277413
BLAKE2b-256 6f3158a72402b2ba3780e2cc8eacf8be925de5a4b7d0fb21b20fb9d7a3fd9249

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page