Skip to content

Commit

Permalink
Merge pull request #370 from jGaboardi/matrix_storage
Browse files Browse the repository at this point in the history
distance matrix and tree storage
  • Loading branch information
jGaboardi committed Jan 4, 2020
2 parents 02386ea + 5377d70 commit 7a3d9d6
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 212 deletions.
145 changes: 79 additions & 66 deletions docs/_modules/spaghetti/network.html

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions docs/generated/spaghetti.Network.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
<dt><strong>pointpatterns</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are a string name of the pattern and values are
<code class="docutils literal notranslate"><span class="pre">PointPattern</span></code> class instances.</p>
</dd>
<dt><strong>alldistances</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the vertex IDs (int). Values are tuples with two
elements as follows (1) a list of the shortest path distances;
(2) a dict with the key being the id of the destination vertex
and the value being a list of the shortest path.</p>
<dt><strong>distance_matrix</strong><span class="classifier"><a class="reference external" href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="(in NumPy v1.17)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></a></span></dt><dd><p>All network vertices (non-observations) distance matrix.</p>
</dd>
<dt><strong>distancematrix</strong><span class="classifier"><a class="reference external" href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="(in NumPy v1.17)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.ndarray</span></code></a></span></dt><dd><p>All network vertices (non-observations) distance matrix.</p>
<dt><strong>network_trees</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the vertex IDs (int). Values are dictionaries
with the keys being the IDs of the destination vertex
and the value being a list of the shortest path.</p>
</dd>
<dt><strong>edges</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">list</span></code></a></span></dt><dd><p>Tuples of graph edge ids.</p>
<dt><strong>edges</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">list</span></code></a></span></dt><dd><p>Tuples of graph edge IDs.</p>
</dd>
<dt><strong>edge_lengths</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the graph edge ids (tuple). Values are the graph edge
<dt><strong>edge_lengths</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the graph edge IDs (tuple). Values are the graph edge
length (float).</p>
</dd>
<dt><strong>non_articulation_points</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">list</span></code></a></span></dt><dd><p>All vertices with degree 2 that are not in an isolated
Expand Down Expand Up @@ -636,6 +635,7 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
<p>Create a network instance.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">spaghetti</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">libpysal</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ntw</span> <span class="o">=</span> <span class="n">spaghetti</span><span class="o">.</span><span class="n">Network</span><span class="p">(</span><span class="n">examples</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s2">&quot;streets.shp&quot;</span><span class="p">))</span>
</pre></div>
</div>
Expand Down Expand Up @@ -663,15 +663,15 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
<span class="gp">... </span> <span class="n">examples</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="s2">&quot;schools.shp&quot;</span><span class="p">),</span> <span class="s2">&quot;schools&quot;</span><span class="p">,</span> <span class="n">attribute</span><span class="o">=</span><span class="kc">False</span>
<span class="gp">... </span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s2d_dist</span> <span class="o">=</span> <span class="n">ntw</span><span class="o">.</span><span class="n">allneighbordistances</span><span class="p">(</span><span class="s2">&quot;crimes&quot;</span><span class="p">,</span> <span class="n">destpattern</span><span class="o">=</span><span class="s2">&quot;schools&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s2d_dist</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">s2d_dist</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
<span class="go">(4520.72353741989, 6340.422971967315)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">numpy</span><span class="o">.</span><span class="n">round</span><span class="p">((</span><span class="n">s2d_dist</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span> <span class="n">s2d_dist</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">]),</span> <span class="mi">5</span><span class="p">)</span>
<span class="go">array([4520.72354, 6340.42297])</span>
</pre></div>
</div>
<p>Shortest paths can also be reconstructed when desired by
setting the <code class="docutils literal notranslate"><span class="pre">gen_tree</span></code> keyword argument to <code class="docutils literal notranslate"><span class="pre">True</span></code>. Here
it is shown that the shortest path between school <code class="docutils literal notranslate"><span class="pre">6</span></code> and
school <code class="docutils literal notranslate"><span class="pre">7</span></code> flows along network arcs through network
vertices <code class="docutils literal notranslate"><span class="pre">173</span></code> and <code class="docutils literal notranslate"><span class="pre">64</span></code>. The <code class="docutils literal notranslate"><span class="pre">ntw.alldistances</span></code> attribute
vertices <code class="docutils literal notranslate"><span class="pre">173</span></code> and <code class="docutils literal notranslate"><span class="pre">64</span></code>. The <code class="docutils literal notranslate"><span class="pre">ntw.network_trees</span></code> attribute
may then be queried for the network elements comprising that path.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">d2d_dist</span><span class="p">,</span> <span class="n">tree</span> <span class="o">=</span> <span class="n">ntw</span><span class="o">.</span><span class="n">allneighbordistances</span><span class="p">(</span><span class="s2">&quot;schools&quot;</span><span class="p">,</span> <span class="n">gen_tree</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tree</span><span class="p">[(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">)]</span>
Expand All @@ -698,9 +698,9 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl>
<dt><strong>d1</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#float" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">float</span></code></a></span></dt><dd><p>The distance to vtx0. Always the vertex with the lesser id.</p>
<dt><strong>d1</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#float" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">float</span></code></a></span></dt><dd><p>The distance to vtx0. Always the vertex with the lesser ID.</p>
</dd>
<dt><strong>d2</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#float" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">float</span></code></a></span></dt><dd><p>The distance to vtx1. Always the vertex with the greater id.</p>
<dt><strong>d2</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#float" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">float</span></code></a></span></dt><dd><p>The distance to vtx1. Always the vertex with the greater ID.</p>
</dd>
</dl>
</dd>
Expand All @@ -717,7 +717,7 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
<dd class="field-odd"><dl>
<dt><strong>pattern</strong><span class="classifier"><a class="reference internal" href="spaghetti.PointPattern.html#spaghetti.PointPattern" title="spaghetti.PointPattern"><code class="xref py py-obj docutils literal notranslate"><span class="pre">spaghetti.PointPattern</span></code></a></span></dt><dd><p>The point pattern object.</p>
</dd>
<dt><strong>idx</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">int</span></code></a></span></dt><dd><p>The point id.</p>
<dt><strong>idx</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">int</span></code></a></span></dt><dd><p>The point ID.</p>
</dd>
</dl>
</dd>
Expand Down Expand Up @@ -1054,9 +1054,9 @@ <h1>spaghetti.Network<a class="headerlink" href="#spaghetti-network" title="Perm
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl>
<dt><strong>nearest</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Nearest neighbor distances keyed by the source point id with
<dt><strong>nearest</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Nearest neighbor distances keyed by the source point ID with
the value as as tuple of lists containing
nearest destination point ids and distance.</p>
nearest destination point ID(s) and distance.</p>
</dd>
</dl>
</dd>
Expand Down
10 changes: 5 additions & 5 deletions docs/generated/spaghetti.PointPattern.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ <h1>spaghetti.PointPattern<a class="headerlink" href="#spaghetti-pointpattern" t
</dd>
<dt class="field-even">Attributes</dt>
<dd class="field-even"><dl>
<dt><strong>points</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the point ids (int). Values are the x,y
<dt><strong>points</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the point IDs (int). Values are the x,y
coordinates (tuple).</p>
</dd>
<dt><strong>npoints</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">int</span></code></a></span></dt><dd><p>The number of points.</p>
</dd>
<dt><strong>obs_to_arc</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are arc ids (tuple). Values are snapped point information
<dt><strong>obs_to_arc</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are arc IDs (tuple). Values are snapped point information
(<code class="docutils literal notranslate"><span class="pre">dict</span></code>). Within the snapped point information (<code class="docutils literal notranslate"><span class="pre">dict</span></code>)
keys are observation ids (<code class="docutils literal notranslate"><span class="pre">int</span></code>), and values are snapped
keys are observation IDs (<code class="docutils literal notranslate"><span class="pre">int</span></code>), and values are snapped
coordinates.</p>
</dd>
<dt><strong>obs_to_vertex</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">list</span></code></a></span></dt><dd><p>List of incident network vertices to snapped observation points
Expand All @@ -168,12 +168,12 @@ <h1>spaghetti.PointPattern<a class="headerlink" href="#spaghetti-pointpattern" t
simplified to a list in the form
[netvtx1, netvtx2, netvtx1, netvtx2, …].</p>
</dd>
<dt><strong>dist_to_vertex</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are observations ids (<code class="docutils literal notranslate"><span class="pre">int</span></code>). Values are distance lookup
<dt><strong>dist_to_vertex</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are observations IDs (<code class="docutils literal notranslate"><span class="pre">int</span></code>). Values are distance lookup
(<code class="docutils literal notranslate"><span class="pre">dict</span></code>). Within distance lookup (<code class="docutils literal notranslate"><span class="pre">dict</span></code>) keys are the two
incident vertices of the arc and values are distance to each of
those arcs.</p>
</dd>
<dt><strong>snapped_coordinates</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the point ids (int). Values are the snapped x,y
<dt><strong>snapped_coordinates</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="docutils literal notranslate"><span class="pre">dict</span></code></a></span></dt><dd><p>Keys are the point IDs (int). Values are the snapped x,y
coordinates (tuple).</p>
</dd>
<dt><strong>snap_dist</strong><span class="classifier"><a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#bltin-boolean-values" title="(in Python v3.7)"><span class="xref std std-ref">bool</span></a></span></dt><dd><p>Flag as <code class="docutils literal notranslate"><span class="pre">True</span></code> to include the distance from the original
Expand Down
6 changes: 3 additions & 3 deletions docs/generated/spaghetti.element_as_gdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ <h1>spaghetti.element_as_gdf<a class="headerlink" href="#spaghetti-element-as-gd
<dd class="field-even"><dl>
<dt><strong>points</strong><span class="classifier"><a class="reference external" href="https://geopandas.readthedocs.io/en/latest/reference/geopandas.GeoDataFrame.html#geopandas.GeoDataFrame" title="(in GeoPandas v0.6.1+30.g0da3a7d)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">geopandas.GeoDataFrame</span></code></a></span></dt><dd><p>Network point elements (either vertices or <code class="docutils literal notranslate"><span class="pre">network.PointPattern</span></code>
points) as a <code class="docutils literal notranslate"><span class="pre">geopandas.GeoDataFrame</span></code> of <code class="docutils literal notranslate"><span class="pre">shapely.geometry.Point</span></code>
objects with an <code class="docutils literal notranslate"><span class="pre">id</span></code> column and <code class="docutils literal notranslate"><span class="pre">geometry</span></code> column.</p>
objects with an <code class="docutils literal notranslate"><span class="pre">&quot;id&quot;</span></code> column and <code class="docutils literal notranslate"><span class="pre">&quot;geometry&quot;&quot;</span></code> column.</p>
</dd>
<dt><strong>lines</strong><span class="classifier"><a class="reference external" href="https://geopandas.readthedocs.io/en/latest/reference/geopandas.GeoDataFrame.html#geopandas.GeoDataFrame" title="(in GeoPandas v0.6.1+30.g0da3a7d)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">geopandas.GeoDataFrame</span></code></a></span></dt><dd><p>Network arc elements as a <code class="docutils literal notranslate"><span class="pre">geopandas.GeoDataFrame</span></code> of
<code class="docutils literal notranslate"><span class="pre">shapely.geometry.LineString</span></code> objects with an <code class="docutils literal notranslate"><span class="pre">id</span></code> column and
<code class="docutils literal notranslate"><span class="pre">geometry</span></code> column.</p>
<code class="docutils literal notranslate"><span class="pre">shapely.geometry.LineString</span></code> objects with an <code class="docutils literal notranslate"><span class="pre">&quot;id&quot;</span></code>
column and <code class="docutils literal notranslate"><span class="pre">&quot;geometry&quot;</span></code> column.</p>
</dd>
</dl>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

0 comments on commit 7a3d9d6

Please sign in to comment.