Skip to content

Commit

Permalink
Deploying to gh-pages from @ 724e876 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed May 31, 2024
1 parent 6ec6dce commit 80e61bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
43 changes: 28 additions & 15 deletions _modules/geefcc/get_fcc.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ <h1>Source code for geefcc.get_fcc</h1><div class="highlight"><pre>
<span class="n">perc</span><span class="o">=</span><span class="mi">75</span><span class="p">,</span>
<span class="n">tile_size</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
<span class="c1"># crop_to_aoi=False,</span>
<span class="n">parallel</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">ncpu</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">output_file</span><span class="o">=</span><span class="s2">&quot;fcc.tif&quot;</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Get forest cover change data.</span>
Expand Down Expand Up @@ -153,6 +154,9 @@ <h1>Source code for geefcc.get_fcc</h1><div class="highlight"><pre>

<span class="sd"> :param tile_size: Tile size for parallel computing.</span>

<span class="sd"> :param parallel: Logical. Parallel (if ``True``) or sequential (if</span>
<span class="sd"> ``False``) computing. Default to ``False``.</span>

<span class="sd"> :param ncpu: Number of CPU to use for parallel computing. If None,</span>
<span class="sd"> it will be set to the number of cores on the computer minus</span>
<span class="sd"> one.</span>
Expand Down Expand Up @@ -206,23 +210,32 @@ <h1>Source code for geefcc.get_fcc</h1><div class="highlight"><pre>
<span class="n">out_dir_tiles</span> <span class="o">=</span> <span class="n">opj</span><span class="p">(</span><span class="n">out_dir</span><span class="p">,</span> <span class="s2">&quot;forest_tiles&quot;</span><span class="p">)</span>
<span class="n">make_dir</span><span class="p">(</span><span class="n">out_dir_tiles</span><span class="p">)</span>

<span class="c1"># Write tiles in parallel</span>
<span class="c1"># https://superfastpython.com/multiprocessing-pool-starmap_async/</span>
<span class="c1"># Message</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;get_fcc running, </span><span class="si">{</span><span class="n">ntiles</span><span class="si">}</span><span class="s2"> tiles .&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">flush</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1"># create and configure the process pool</span>
<span class="k">if</span> <span class="n">ncpu</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ncpu</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span>
<span class="k">with</span> <span class="n">mp</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">processes</span><span class="o">=</span><span class="n">ncpu</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>
<span class="c1"># prepare arguments</span>
<span class="n">args</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">,</span> <span class="n">ntiles</span><span class="p">,</span> <span class="n">forest</span><span class="p">,</span> <span class="n">proj</span><span class="p">,</span> <span class="n">scale</span><span class="p">,</span> <span class="n">out_dir_tiles</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">grid</span><span class="p">)]</span>
<span class="c1"># issue many tasks asynchronously to the process pool</span>
<span class="n">_</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">starmap_async</span><span class="p">(</span><span class="n">geeic2geotiff</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
<span class="c1"># close the pool</span>
<span class="n">pool</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="c1"># wait for all issued tasks to complete</span>
<span class="n">pool</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>

<span class="c1"># Sequential computing</span>
<span class="k">if</span> <span class="n">parallel</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
<span class="c1"># Loop on tiles</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">grid</span><span class="p">):</span>
<span class="n">geeic2geotiff</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">,</span> <span class="n">ntiles</span><span class="p">,</span> <span class="n">forest</span><span class="p">,</span> <span class="n">proj</span><span class="p">,</span> <span class="n">scale</span><span class="p">,</span> <span class="n">out_dir_tiles</span><span class="p">)</span>

<span class="c1"># Parallel computing</span>
<span class="k">if</span> <span class="n">parallel</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
<span class="c1"># Write tiles in parallel</span>
<span class="c1"># https://superfastpython.com/multiprocessing-pool-starmap_async/</span>
<span class="c1"># create and configure the process pool</span>
<span class="k">if</span> <span class="n">ncpu</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">ncpu</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span>
<span class="k">with</span> <span class="n">mp</span><span class="o">.</span><span class="n">Pool</span><span class="p">(</span><span class="n">processes</span><span class="o">=</span><span class="n">ncpu</span><span class="p">)</span> <span class="k">as</span> <span class="n">pool</span><span class="p">:</span>
<span class="c1"># prepare arguments</span>
<span class="n">args</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">,</span> <span class="n">ntiles</span><span class="p">,</span> <span class="n">forest</span><span class="p">,</span> <span class="n">proj</span><span class="p">,</span> <span class="n">scale</span><span class="p">,</span> <span class="n">out_dir_tiles</span><span class="p">)</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">ext</span><span class="p">)</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">grid</span><span class="p">)]</span>
<span class="c1"># issue many tasks asynchronously to the process pool</span>
<span class="n">_</span> <span class="o">=</span> <span class="n">pool</span><span class="o">.</span><span class="n">starmap_async</span><span class="p">(</span><span class="n">geeic2geotiff</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
<span class="c1"># close the pool</span>
<span class="n">pool</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="c1"># wait for all issued tasks to complete</span>
<span class="n">pool</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>

<span class="c1"># Geotiff from tiles</span>
<span class="n">geotiff_from_tiles</span><span class="p">(</span><span class="n">output_file</span><span class="p">)</span></div>
Expand Down
4 changes: 3 additions & 1 deletion python_api/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h3 id="searchlabel">Quick search</h3>

<dl class="py function">
<dt class="sig sig-object py" id="geefcc.get_fcc">
<span class="sig-name descname"><span class="pre">get_fcc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">aoi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buff</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">years</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[2000,</span> <span class="pre">2010,</span> <span class="pre">2020]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'tmf'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">75</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tile_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ncpu</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'fcc.tif'</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/geefcc/get_fcc.html#get_fcc"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#geefcc.get_fcc" title="Link to this definition"></a></dt>
<span class="sig-name descname"><span class="pre">get_fcc</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">aoi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buff</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">years</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">[2000,</span> <span class="pre">2010,</span> <span class="pre">2020]</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">source</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'tmf'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">75</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">tile_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parallel</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ncpu</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'fcc.tif'</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/geefcc/get_fcc.html#get_fcc"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#geefcc.get_fcc" title="Link to this definition"></a></dt>
<dd><p>Get forest cover change data.</p>
<blockquote>
<div><p>Produce a forest cover change raster file. One band for each
Expand All @@ -134,6 +134,8 @@ <h3 id="searchlabel">Quick search</h3>
<li><p><strong>perc</strong> – Tree cover threshold defining the forest for GFC
product.</p></li>
<li><p><strong>tile_size</strong> – Tile size for parallel computing.</p></li>
<li><p><strong>parallel</strong> – Logical. Parallel (if <code class="docutils literal notranslate"><span class="pre">True</span></code>) or sequential (if
<code class="docutils literal notranslate"><span class="pre">False</span></code>) computing. Default to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
<li><p><strong>ncpu</strong> – Number of CPU to use for parallel computing. If None,
it will be set to the number of cores on the computer minus
one.</p></li>
Expand Down
Loading

0 comments on commit 80e61bc

Please sign in to comment.