Skip to content

Commit

Permalink
80 default out pth argument in transport performanceosmosm utilspy (#142
Browse files Browse the repository at this point in the history
)

* refactor: Output path & typesetting in func signature

* refactor: Test uses tmpdir, prints on directory creation 49fd2a9
  • Loading branch information
SergioRec committed Sep 28, 2023
1 parent 8947374 commit b689664
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
20 changes: 13 additions & 7 deletions _modules/transport_performance/osm/osm_utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ <h1>Source code for transport_performance.osm.osm_utils</h1><div class="highligh
<span></span><span class="sd">&quot;&quot;&quot;Utility functions for OSM files.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">from</span> <span class="nn">pyprojroot</span> <span class="kn">import</span> <span class="n">here</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Union</span>
<span class="kn">import</span> <span class="nn">pathlib</span>

<span class="kn">from</span> <span class="nn">transport_performance.utils.defence</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">_type_defence</span><span class="p">,</span>
Expand All @@ -100,12 +102,16 @@ <h1>Source code for transport_performance.osm.osm_utils</h1><div class="highligh
<div class="viewcode-block" id="filter_osm">
<a class="viewcode-back" href="../../../reference/_autosummary/transport_performance.osm.osm_utils.filter_osm.html#transport_performance.osm.osm_utils.filter_osm">[docs]</a>
<span class="k">def</span> <span class="nf">filter_osm</span><span class="p">(</span>
<span class="n">pbf_pth</span><span class="o">=</span><span class="n">here</span><span class="p">(</span><span class="s2">&quot;tests/data/newport-2023-06-13.osm.pbf&quot;</span><span class="p">),</span>
<span class="n">out_pth</span><span class="o">=</span><span class="s2">&quot;filtered.osm.pbf&quot;</span><span class="p">,</span>
<span class="n">bbox</span><span class="o">=</span><span class="p">[</span><span class="o">-</span><span class="mf">3.01</span><span class="p">,</span> <span class="mf">51.58</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.99</span><span class="p">,</span> <span class="mf">51.59</span><span class="p">],</span>
<span class="n">tag_filter</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">install_osmosis</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="p">):</span>
<span class="n">pbf_pth</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">PosixPath</span><span class="p">]</span> <span class="o">=</span> <span class="n">here</span><span class="p">(</span>
<span class="s2">&quot;tests/data/newport-2023-06-13.osm.pbf&quot;</span>
<span class="p">),</span>
<span class="n">out_pth</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">PosixPath</span><span class="p">]</span> <span class="o">=</span> <span class="n">here</span><span class="p">(</span>
<span class="s2">&quot;outputs/osm/filtered.osm.pbf&quot;</span>
<span class="p">),</span>
<span class="n">bbox</span><span class="p">:</span> <span class="nb">list</span> <span class="o">=</span> <span class="p">[</span><span class="o">-</span><span class="mf">3.01</span><span class="p">,</span> <span class="mf">51.58</span><span class="p">,</span> <span class="o">-</span><span class="mf">2.99</span><span class="p">,</span> <span class="mf">51.59</span><span class="p">],</span>
<span class="n">tag_filter</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
<span class="n">install_osmosis</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Filter an osm.pbf file to a bbox. Relies on homebrew with osmosis.</span>

<span class="sd"> Parameters</span>
Expand All @@ -114,7 +120,7 @@ <h1>Source code for transport_performance.osm.osm_utils</h1><div class="highligh
<span class="sd"> Path to the open street map pbf to be filtered. Defaults to</span>
<span class="sd"> here(&quot;tests/data/newport-2023-06-13.osm.pbf&quot;).</span>
<span class="sd"> out_pth: ((str, pathlib.PosixPath), optional)</span>
<span class="sd"> Path to write to. Defaults to &quot;filtered.osm.pbf&quot;.</span>
<span class="sd"> Path to write to. Defaults to here(&quot;outputs/osm/filtered.osm.pbf&quot;).</span>
<span class="sd"> bbox: (list, optional)</span>
<span class="sd"> Bounding box used to perform the filter, in left, bottom, right top</span>
<span class="sd"> order. Defaults to [-3.01, 51.58, -2.99, 51.59].</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@
<h1>filter_osm<a class="headerlink" href="#filter-osm" title="Link to this heading"></a></h1>
<dl class="py function">
<dt class="sig sig-object py" id="transport_performance.osm.osm_utils.filter_osm">
<span class="sig-prename descclassname"><span class="pre">transport_performance.osm.osm_utils.</span></span><span class="sig-name descname"><span class="pre">filter_osm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pbf_pth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">PosixPath('/home/runner/work/transport-network-performance/transport-network-performance/tests/data/newport-2023-06-13.osm.pbf')</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">out_pth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'filtered.osm.pbf'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bbox</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[-3.01,</span> <span class="pre">51.58,</span> <span class="pre">-2.99,</span> <span class="pre">51.59]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tag_filter</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">install_osmosis</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/transport_performance/osm/osm_utils.html#filter_osm"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#transport_performance.osm.osm_utils.filter_osm" title="Link to this definition"></a></dt>
<span class="sig-prename descclassname"><span class="pre">transport_performance.osm.osm_utils.</span></span><span class="sig-name descname"><span class="pre">filter_osm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pbf_pth</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">PosixPath</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">PosixPath('/home/runner/work/transport-network-performance/transport-network-performance/tests/data/newport-2023-06-13.osm.pbf')</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">out_pth</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">PosixPath</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">PosixPath('/home/runner/work/transport-network-performance/transport-network-performance/outputs/osm/filtered.osm.pbf')</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bbox</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">list</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">[-3.01,</span> <span class="pre">51.58,</span> <span class="pre">-2.99,</span> <span class="pre">51.59]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tag_filter</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">install_osmosis</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bool</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="../../_modules/transport_performance/osm/osm_utils.html#filter_osm"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#transport_performance.osm.osm_utils.filter_osm" title="Link to this definition"></a></dt>
<dd><p>Filter an osm.pbf file to a bbox. Relies on homebrew with osmosis.</p>
<section id="parameters">
<h2>Parameters<a class="headerlink" href="#parameters" title="Link to this heading"></a></h2>
<dl class="simple">
<dt>pbf_pth: ((str, pathlib.PosixPath), optional)</dt><dd><p>Path to the open street map pbf to be filtered. Defaults to
here(“tests/data/newport-2023-06-13.osm.pbf”).</p>
</dd>
<dt>out_pth: ((str, pathlib.PosixPath), optional)</dt><dd><p>Path to write to. Defaults to filtered.osm.pbf”.</p>
<dt>out_pth: ((str, pathlib.PosixPath), optional)</dt><dd><p>Path to write to. Defaults to here(“outputs/osm/filtered.osm.pbf”).</p>
</dd>
<dt>bbox: (list, optional)</dt><dd><p>Bounding box used to perform the filter, in left, bottom, right top
order. Defaults to [-3.01, 51.58, -2.99, 51.59].</p>
Expand Down
Loading

0 comments on commit b689664

Please sign in to comment.