Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sphinx documentation #24

Merged
merged 14 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: documentation

on: [push, pull_request, workflow_dispatch]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ghp-import sphinx sphinx_rtd_theme
- name: Build HTML
run: |
cd docs/
make html
- name: Run ghp-import
run: |
ghp-import -n -p -f docs/_build/html
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ instance/
# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ destination_directory="path/where/to/save/results"
despeckle(image_path, destination_directory, model_name="sar2sar")
```

## Documentation

To read a clean documentation of the package, you can generate it using sphinx files in the `docs` folder

1. `cd docs`
2. `make html `
3. open `build/index.html`

## Authors

* [Emanuele Dalsasso](https://emanueledalsasso.github.io/) (Researcher at ECEO, EPFL)
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file added docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file added docs/_build/doctrees/index.doctree
Binary file not shown.
Binary file added docs/_build/doctrees/modules.doctree
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/_build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: fdae4d25184fbbee4471ad780e47bfd2
tags: 645f666f9bcd5a90fca523b33c5a78b7
188 changes: 188 additions & 0 deletions docs/_build/html/_modules/deepdespeckling/denoiser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<!DOCTYPE html>

<html lang="English" data-content_root="../../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>deepdespeckling.denoiser &#8212; deepdespeckling 0.3 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=d1102ebc" />
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=12dfc556" />
<script src="../../_static/documentation_options.js?v=cb255500"></script>
<script src="../../_static/doctools.js?v=888ff710"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />

<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />





</head><body>


<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">


<div class="body" role="main">

<h1>Source code for deepdespeckling.denoiser</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>


<div class="viewcode-block" id="Denoiser">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser">[docs]</a>
<span class="k">class</span> <span class="nc">Denoiser</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Class to share parameters beyond denoising functions</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">device</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_device</span><span class="p">()</span>

<div class="viewcode-block" id="Denoiser.get_device">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.get_device">[docs]</a>
<span class="k">def</span> <span class="nf">get_device</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Get torch device to use depending on gpu&#39;s availability</span>

<span class="sd"> Returns:</span>
<span class="sd"> device (str): device to be used by torch</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">torch</span><span class="o">.</span><span class="n">backends</span><span class="o">.</span><span class="n">mps</span><span class="o">.</span><span class="n">is_available</span><span class="p">()</span> <span class="ow">and</span> <span class="n">torch</span><span class="o">.</span><span class="n">backends</span><span class="o">.</span><span class="n">mps</span><span class="o">.</span><span class="n">is_built</span><span class="p">():</span>
<span class="n">device</span> <span class="o">=</span> <span class="s2">&quot;mps&quot;</span>
<span class="k">elif</span> <span class="n">torch</span><span class="o">.</span><span class="n">cuda</span><span class="o">.</span><span class="n">is_available</span><span class="p">():</span>
<span class="n">device</span> <span class="o">=</span> <span class="s2">&quot;cuda:0&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">device</span> <span class="o">=</span> <span class="s2">&quot;cpu&quot;</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">device</span><span class="si">}</span><span class="s2"> device is used by torch&quot;</span><span class="p">)</span>

<span class="k">return</span> <span class="n">device</span></div>


<div class="viewcode-block" id="Denoiser.initialize_axis_range">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.initialize_axis_range">[docs]</a>
<span class="k">def</span> <span class="nf">initialize_axis_range</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image_axis_dim</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">patch_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">stride_size</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Initialize the convolution range for x or y axis</span>

<span class="sd"> Args:</span>
<span class="sd"> image_axis_dim (int): axis size</span>
<span class="sd"> patch_size (int): patch size</span>
<span class="sd"> stride_size (int): stride size</span>

<span class="sd"> Returns:</span>
<span class="sd"> axis_range (list) : pixel borders of each convolution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">image_axis_dim</span> <span class="o">==</span> <span class="n">patch_size</span><span class="p">:</span>
<span class="n">axis_range</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">axis_range</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span>
<span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">image_axis_dim</span> <span class="o">-</span> <span class="n">patch_size</span><span class="p">,</span> <span class="n">stride_size</span><span class="p">))</span>
<span class="k">if</span> <span class="p">(</span><span class="n">axis_range</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">patch_size</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">image_axis_dim</span><span class="p">:</span>
<span class="n">axis_range</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span>
<span class="nb">range</span><span class="p">(</span><span class="n">image_axis_dim</span> <span class="o">-</span> <span class="n">patch_size</span><span class="p">,</span> <span class="n">image_axis_dim</span> <span class="o">-</span> <span class="n">patch_size</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>

<span class="k">return</span> <span class="n">axis_range</span></div>


<div class="viewcode-block" id="Denoiser.save_despeckled_images">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.save_despeckled_images">[docs]</a>
<span class="k">def</span> <span class="nf">save_despeckled_images</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>


<div class="viewcode-block" id="Denoiser.denoise_image_kernel">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.denoise_image_kernel">[docs]</a>
<span class="k">def</span> <span class="nf">denoise_image_kernel</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>


<div class="viewcode-block" id="Denoiser.preprocess_denoised_image">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.preprocess_denoised_image">[docs]</a>
<span class="k">def</span> <span class="nf">preprocess_denoised_image</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>


<div class="viewcode-block" id="Denoiser.denoise_image">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.denoise_image">[docs]</a>
<span class="k">def</span> <span class="nf">denoise_image</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>


<div class="viewcode-block" id="Denoiser.denoise_images">
<a class="viewcode-back" href="../../modules.html#deepdespeckling.denoiser.Denoiser.denoise_images">[docs]</a>
<span class="k">def</span> <span class="nf">denoise_images</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>
</div>

</pre></div>

</div>

</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../../index.html">deepdespeckling</a></h1>








<h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">deepdespeckling</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../../index.html">Documentation overview</a><ul>
<li><a href="../index.html">Module code</a><ul>
</ul></li>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>








</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&#169;2024, Hadrien Mariaccia, Emanuele Delsasso.

|
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 7.2.6</a>
&amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>

</div>




</body>
</html>
Loading
Loading