Skip to content

Commit

Permalink
feat: allow for use of viz_stops in MGTFS without stop_code column;fe…
Browse files Browse the repository at this point in the history
…at: add new tests (#236)

Co-authored-by: r-leyshon <[email protected]> 7cc6c62
  • Loading branch information
r-leyshon committed Jan 22, 2024
1 parent d08c406 commit 705e071
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions _modules/transport_performance/gtfs/multi_validation.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h1>Source code for transport_performance.gtfs.multi_validation</h1><div class="
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>

<span class="kn">from</span> <span class="nn">geopandas</span> <span class="kn">import</span> <span class="n">GeoDataFrame</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
Expand Down Expand Up @@ -675,6 +676,13 @@ <h1>Source code for transport_performance.gtfs.multi_validation</h1><div class="
<span class="c1"># combine stop tables</span>
<span class="n">parts</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">inst</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">instances</span><span class="p">:</span>
<span class="c1"># copy the gtfs instance in case data is manipulated</span>
<span class="n">inst</span> <span class="o">=</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">inst</span><span class="p">)</span>
<span class="c1"># create a synthesized stop_code column if it does not exist</span>
<span class="k">if</span> <span class="s2">&quot;stop_code&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">inst</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">stops</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="n">inst</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">stops</span><span class="p">[</span><span class="s2">&quot;stop_code&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
<span class="sa">f</span><span class="s2">&quot;ID</span><span class="si">{</span><span class="n">sid</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">sid</span> <span class="ow">in</span> <span class="n">inst</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">stops</span><span class="p">[</span><span class="s2">&quot;stop_id&quot;</span><span class="p">]</span>
<span class="p">]</span>
<span class="n">subset</span> <span class="o">=</span> <span class="n">inst</span><span class="o">.</span><span class="n">feed</span><span class="o">.</span><span class="n">stops</span><span class="p">[</span>
<span class="p">[</span><span class="s2">&quot;stop_lat&quot;</span><span class="p">,</span> <span class="s2">&quot;stop_lon&quot;</span><span class="p">,</span> <span class="s2">&quot;stop_name&quot;</span><span class="p">,</span> <span class="s2">&quot;stop_id&quot;</span><span class="p">,</span> <span class="s2">&quot;stop_code&quot;</span><span class="p">]</span>
<span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
Expand All @@ -683,6 +691,8 @@ <h1>Source code for transport_performance.gtfs.multi_validation</h1><div class="
<span class="n">subset</span> <span class="o">=</span> <span class="n">subset</span><span class="p">[</span><span class="n">subset</span><span class="o">.</span><span class="n">stop_id</span><span class="o">.</span><span class="n">isin</span><span class="p">(</span><span class="n">valid_ids</span><span class="p">)]</span>
<span class="n">subset</span><span class="p">[</span><span class="s2">&quot;gtfs_path&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">inst</span><span class="o">.</span><span class="n">gtfs_path</span><span class="p">)</span>
<span class="n">parts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">subset</span><span class="p">)</span>
<span class="c1"># clean up copied instance</span>
<span class="k">del</span> <span class="n">inst</span>

<span class="n">all_stops</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span>

Expand Down

0 comments on commit 705e071

Please sign in to comment.