spaghetti

SPAtial GrapHs: nETworks, Topology, & Inference

Spaghetti is an open-source python library for the analysis of network-based spatial data. Originating from the network module in PySAL (Python Spatial Analysis Library), it is under active development for the inclusion of newly proposed methods for building graph-theoretic networks and the analysis of network events.

Citing spaghetti

If you use PySAL-spaghetti in a scientific publication, we would appreciate using the following citation:

Bibtex entry:

@misc{Gaboardi2018,
  author = {Gaboardi, James D. and Laura, Jay and Rey, Sergio and Wolf, Levi John and Folch, David C. and Kang, Wei and Stephens, Philip and Schmidt, Charles},
  month = {oct},
  year = {2018},
  title = {pysal/spaghetti},
  url = {https://github.com/pysal/spaghetti},
  keywords = {graph-theory,network-analysis,python,spatial-networks,topology}
}

As of version 1.3, spaghetti supports Python 3.6 and 3.7 only. Please make sure that you are operating in a Python 3 environment.

Installation

Installing with Python Package Index

$ pip install spaghetti

or download the source distribution (.tar.gz) and decompress it to your selected destination. Open a command shell and navigate to the decompressed folder.

$ pip install .

Warning

When installing via pip, you have to ensure that the required dependencies for spaghetti are installed on your operating system. Details on how to install these packages are linked here. Using conda (above) avoids having to install the dependencies separately.

Install the most current development version of spaghetti by running:

$ pip install git+https://github.com/pysal/spaghetti

Development Version

Install the most current development version of spaghetti by running:

$ pip install git+https://github.com/pysal/spaghetti

You can also fork the pysal/spaghetti repo and create a local clone of your fork. By making changes to your local clone and submitting a pull request to pysal/spaghetti, you can contribute to the spaghetti development.


API reference

spaghetti.Network

spaghetti.Network.extract_components(self, w)

Extract connected component information from a libpysal.weights.weights.W object

spaghetti.Network.extractgraph(self)

Using the existing network representation, create a graph-theoretic representation by removing all vertices with a neighbor incidence of two (non-articulation points).

spaghetti.Network.contiguityweights(self[, …])

Create a contiguity-based libpysal W object.

spaghetti.Network.distancebandweights(self, …)

Create distance based weights.

spaghetti.Network.snapobservations(self, …)

Snap a point pattern shapefile to network object.

spaghetti.Network.compute_distance_to_vertices(…)

Given an observation on a network arc, return the distance to the two vertices that bound that end.

spaghetti.Network.compute_snap_dist(self, …)

Given an observation snapped to a network arc, calculate the distance from the original location to the snapped location.

spaghetti.Network.count_per_link(self, obs_on)

Compute the counts per arc or edge (link).

spaghetti.Network.simulate_observations(…)

Generate a simulated point pattern on the network.

spaghetti.Network.enum_links_vertex(self, v0)

Returns the arcs (links) around vertices.

spaghetti.Network.full_distance_matrix(self, …)

All vertex-to-vertex distances on a network.

spaghetti.Network.allneighbordistances(self, …)

Compute either all distances between i and j in a single point pattern or all distances between each i from a source pattern and all j from a destination pattern.

spaghetti.Network.nearestneighbordistances(…)

Compute the interpattern nearest neighbor distances or the intrapattern nearest neighbor distances between a source pattern and a destination pattern.

spaghetti.Network.split_arcs(self, distance)

Split all of the arcs in the network at either a

spaghetti.Network.savenetwork(self, filename)

Save a network to disk as a binary file.

spaghetti.Network.loadnetwork(filename)

Load a network from a binary file saved on disk.

spaghetti.Network.NetworkF(self, pointpattern)

Computes a network constrained F-Function

spaghetti.Network.NetworkG(self, pointpattern)

Computes a network constrained G-Function

spaghetti.Network.NetworkK(self, pointpattern)

Computes a network constrained K-Function

spaghetti.Network._evaluate_napts(self, …)

Evaluate one connected component in a network for non-articulation points (napts) and return an updated set of napts and unvisted vertices.

spaghetti.Network._extractnetwork(self)

Used internally to extract a network from a polyline shapefile of a geopandas.GeoDataFrame.

spaghetti.Network._newpoint_coords(self, …)

Used internally to compute new point coordinates during snapping.

spaghetti.Network._round_sig(self, v)

Used internally to round the vertex to a set number of significant digits.

spaghetti.Network._snap_to_link(self, …)

Used internally to snap point observations to network arcs.

spaghetti.Network._yield_napts(self)

Find all nodes with degree 2 that are not in an isolated island ring (loop) component.

spaghetti.Network._yieldneighbor(self, vtx, …)

Used internally, this method traverses a bridge arc to find the source and destination nodes.

spaghetti.PointPattern

spaghetti.PointPattern([in_data, …])

A stub point pattern class used to store a point pattern.

spaghetti.SimulatedPointPattern

spaghetti.SimulatedPointPattern()

Struct style class to mirror the PointPattern class.

spaghetti

spaghetti.element_as_gdf(net[, vertices, …])

Return a geopandas.GeoDataFrame of network elements.This can be (a) the vertices of a network; (b) the arcs of a network; (c) both the vertices and arcs of the network; (d) raw point pattern associated with the network; or (e) snapped point pattern of (d)..

References

Dij59

E. W. Dijkstra. A Note on Two Problems in Connexion with Graphs. Numerische Mathematik, 1(1):269–271, 1959. doi:10.1007/BF01386390.

OY01

Atsuyuki Okabe and Ikuho Yamada. The K-Function Method on a Network and Its Computational Implementation. Geographical Analysis, 33(3):271–290, 2001.