Skip to content

Commit

Permalink
Merge pull request #27 from hi-paris/develop
Browse files Browse the repository at this point in the history
Documentation and Sentinel-TOPS
  • Loading branch information
brash6 committed Apr 9, 2024
2 parents 3ddd467 + af642db commit 31d532c
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 35 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: documentation

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

# 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"


- name: Set up gdal
run : sudo apt-get install libgdal-dev

# 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 -e .
- name: Install gdal dependencies
run : pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`

- 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ In order to get the right model, the `model_name` has to be specified when build
This `model_name` can either be :
- `"spotlight"` for SAR images retrieved with spotlight mode
- `"stripmap"` for SAR images retrieved with stripmap mode
- `"Sentinel-TOPS"` for SAR images retrieved with TOPS mode


During the preprocessing steps of the noisy image for MERLIN, the real and the imaginary parts are <strong>"symetrised"</strong> (to match the theoretical assumptions of MERLIN). To skip this step, you can set the `symetrise` parameter to `False`

Expand All @@ -47,7 +49,7 @@ from deepdespeckling.merlin.merlin_denoiser import MerlinDenoiser

# Path to one image (cos or npy file)
image_path="path/to/cosar/image"
# Model name, can be "spotlight" or "stripmap"
# Model name, can be "spotlight", "stripmap" or "Sentinel-TOPS"
model_name = "spotlight"
symetrise = True

Expand Down
19 changes: 10 additions & 9 deletions deepdespeckling/despeckling.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
logging.basicConfig(level=logging.INFO)


def get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
def _get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
"""Get the right denoiser object from the model name
Args:
Expand All @@ -24,7 +24,7 @@ def get_denoiser(model_name: str, symetrise: bool = True) -> Denoiser:
Returns:
denoiser (Denoiser): the right denoiser, Sar2SarDenoiser or MerlinDenoiser
"""
if model_name in ["spotlight", "stripmap"]:
if model_name in ["spotlight", "stripmap", "Sentinel_TOPS"]:
denoiser = MerlinDenoiser(model_name=model_name, symetrise=symetrise)
elif model_name == "sar2sar":
denoiser = Sar2SarDenoiser()
Expand All @@ -41,7 +41,7 @@ def despeckle(sar_images_path: str, destination_directory_path: str, model_name:
Args:
sar_images_path (str): path of sar images
destination_directory_path (str): path of folder in which results will be stored
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
Expand All @@ -60,7 +60,7 @@ def despeckle(sar_images_path: str, destination_directory_path: str, model_name:
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing test results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)

Expand All @@ -73,7 +73,7 @@ def despeckle_from_coordinates(sar_images_path: str, coordinates_dict: dict, des
sar_images_path (str): path of sar images
coordinates_dict (dict): dictionary containing pixel boundaries of the area to despeckle (x_start, x_end, y_start, y_end)
destination_directory_path (str): path of folder in which results will be stored
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
Expand All @@ -92,7 +92,7 @@ def despeckle_from_coordinates(sar_images_path: str, coordinates_dict: dict, des
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing test results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)

Expand All @@ -106,7 +106,7 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
destination_directory_path (str): path of folder in which results will be stored
patch_size (int): patch size. Defaults to constant PATCH_SIZE.
stride_size (int): stride size. Defaults to constant STRIDE_SIZE.
model_name (str): model name, either "spotlight" or "stripmap" to select MERLIN model on the
model_name (str): model name, either "spotlight", "stripmap" or "Sentinel_TOPS" to select MERLIN model on the
right cosar image format or "sar2sar" for SAR2SAR model. Default to "spotlight"
fixed (bool) : If True, crop size is limited to 256*256. Defaults to True
symetrise (bool) : if using spotlight or stripmap model, if True, will symetrise the real and
Expand All @@ -119,7 +119,8 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
processed_images_path = create_empty_folder_in_directory(destination_directory_path=destination_directory_path,
folder_name="processed_images")

ext = "cos" if model_name in ["spotlight", "stripmap"] else "tiff"
ext = "cos" if model_name in ["spotlight",
"stripmap", "Sentinel_TOPS"] else "tiff"
images_paths = glob(os.path.join(sar_images_path, f"*.{ext}")) + \
glob(os.path.join(sar_images_path, "*.npy"))

Expand All @@ -139,6 +140,6 @@ def despeckle_from_crop(sar_images_path: str, destination_directory_path: str, m
logging.info(
f"Starting inference.. Collecting data from {sar_images_path} and storing results in {destination_directory_path}")

denoiser = get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser = _get_denoiser(model_name=model_name, symetrise=symetrise)
denoiser.denoise_images(images_to_denoise_path=processed_images_path, save_dir=destination_directory_path,
patch_size=patch_size, stride_size=stride_size)
5 changes: 4 additions & 1 deletion deepdespeckling/merlin/merlin_denoiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, model_name, symetrise, **params):
"""Initialize MerlinDenoiser class
Args:
model_name (str): name to be used, can be "spotlight" or "stripmap"
model_name (str): name to be used, can be "spotlight", "stripmap" or "Sentinel_TOPS"
"""
super().__init__(**params)
self.model_name = model_name
Expand All @@ -42,6 +42,9 @@ def init_model_weights_path(self) -> str:
elif self.model_name == "stripmap":
model_weights_path = os.path.join(
current_dir, "saved_models/stripmap.pth")
elif self.model_name == "Sentinel_TOPS":
model_weights_path = os.path.join(
current_dir, "saved_models/sentinel_tops.pth")
else:
raise ValueError(
"The model name doesn't refer to an existing model ")
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions deepdespeckling/test_deepdespeckling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
coordinates_dictionnary = {'x_start': 0,
'y_start': 0, 'x_end': 400, 'y_end': 400}

despeckle(image_path, destination_directory,
model_name="sar2sar")
"""despeckle(image_path, destination_directory,
model_name="sar2sar")"""
4 changes: 2 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
Expand Down
28 changes: 15 additions & 13 deletions docs/source/conf.py → docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import sys
import os
import deepdespeckling
import deepdespeckling.denoiser
import deepdespeckling.despeckling
import deepdespeckling.model
import deepdespeckling.utils
import deepdespeckling.utils.constants
import deepdespeckling.utils.load_cosar
import deepdespeckling.utils.utils
import deepdespeckling.sar2sar
import deepdespeckling.sar2sar.sar2sar_denoiser
import deepdespeckling.merlin
import deepdespeckling.merlin.merlin_denoiser

# Configuration file for the Sphinx documentation builder.
#
Expand All @@ -22,27 +34,17 @@
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon'
'sphinx.ext.napoleon',
'sphinx.ext.githubpages'
]

templates_path = ['_templates']
exclude_patterns = ["build", ".venv", ".vscode",
"dist", "deepdespeckling.egg-info", "img", "icons"]

language = 'English'

master_doc = "index"

autodoc_default_options = {
'members': True,
'undoc-members': True,
'show-inheritance': True,
}

add_module_names = True

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
2 changes: 1 addition & 1 deletion docs/source/index.rst → docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Welcome to deepdespeckling's documentation!
===========================================

.. toctree::
:maxdepth: 3
:maxdepth: 4
:caption: Contents:

modules
Expand Down
4 changes: 2 additions & 2 deletions docs/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modules.rst → docs/modules.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. toctree::
:maxdepth: 3
:maxdepth: 4
:caption: Contents:

deepdespeckling
Expand Down

0 comments on commit 31d532c

Please sign in to comment.