Skip to content

Commit

Permalink
Merge pull request #6 from CEA-COSMIC/develop
Browse files Browse the repository at this point in the history
Version 0.0.1 patch release
  • Loading branch information
sfarrens authored Apr 20, 2021
2 parents 7d56509 + cfc3155 commit 41c6395
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 195 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: CI

on:
pull_request:
branches:
- develop
- master
- main

jobs:
test-full:
name: Full Test Suite
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.8]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Conda with Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
auto-activate-base: false

- name: Check Conda
shell: bash -l {0}
run: |
conda info
conda list
python --version
- name: Install macOS Dependencies
shell: bash -l {0}
if: runner.os == 'macOS'
run: |
brew install libomp
- name: Install Package Dependencies
shell: bash -l {0}
run: |
python --version
python -m pip install --upgrade pip
python -m pip install git+https://github.com/CEA-COSMIC/pysap@develop
python -m pip install coverage nose
python -m pip install pytest pytest-cov pytest-pycodestyle pytest-pydocstyle
python -m pip install twine
python -m pip install .
- name: Run Tests
shell: bash -l {0}
run: |
python setup.py test
- name: Save Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: unit-test-results-${{ matrix.os }}-${{ matrix.python-version }}
path: pytest.xml

- name: Check Distribution
shell: bash -l {0}
run: |
python setup.py sdist
twine check dist/*
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.xml
flags: unittests

test-basic:
name: Basic Test Suite
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.6, 3.7, 3.9]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Conda with Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
auto-activate-base: false

- name: Install macOS Dependencies
shell: bash -l {0}
if: runner.os == 'macOS'
run: |
brew install libomp
- name: Install Package Dependencies
shell: bash -l {0}
run: |
python --version
python -m pip install --upgrade pip
python -m pip install git+https://github.com/CEA-COSMIC/pysap@develop
python -m pip install coverage nose
python -m pip install pytest pytest-cov pytest-pycodestyle pytest-pydocstyle
python -m pip install .
- name: Run Tests
shell: bash -l {0}
run: |
python setup.py test
48 changes: 0 additions & 48 deletions .travis.yml

This file was deleted.

38 changes: 10 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,40 +1,22 @@

pySAP-astro
PySAP-Astro
===============

|travis| |coveralls| |python35| |python36| |python37|
|travis| |codecov| |pypi|

.. |travis| image:: https://travis-ci.org/CEA-COSMIC/pysap-astro.svg?branch=master
:target: https://travis-ci.org/CEA-COSMIC/pysap-astro

.. |coveralls| image:: https://coveralls.io/repos/github/CEA-COSMIC/pysap-astro/badge.svg?branch=master
:target: https://coveralls.io/github/CEA-COSMIC/pysap-astro

.. |python35| image:: https://img.shields.io/badge/python-3.5-green.svg
:target: https://www.python.org/

.. |python36| image:: https://img.shields.io/badge/python-3.6-green.svg
:target: https://www.python.org/

.. |python37| image:: https://img.shields.io/badge/python-3.7-green.svg
:target: https://www.python.org/
.. |codecov| image:: https://codecov.io/gh/CEA-COSMIC/pysap-astro/branch/master/graph/badge.svg?token=XHJIQXV7AX
:target: https://codecov.io/gh/CEA-COSMIC/pysap-astro

.. |pypi| image:: https://img.shields.io/pypi/v/pysap-astro
:target: https://pypi.org/project/pysap-astro/

Python Sparse data Analysis Package external ASTRO plugin.

This work is made available by a community of people, amoung which the
CEA Neurospin UNATI and CEA CosmoStat laboratories, in particular A. Grigis,
J.-L. Starck, P. Ciuciu, and S. Farrens.


Important links
===============

- Official pySAP source code repo: https://github.com/cea-cosmic/pysap
- pySAP HTML documentation (last stable release): http://cea-cosmic.github.io/pysap


Python Sparse data Analysis Package external ASTRO plugin.
This package is part of the PySAP plug-in framework and is not intended to
work as a stand-alone package.

This work is made available by a community of people, amoung which the
CEA Neurospin UNATI and CEA CosmoStat laboratories, in particular A. Grigis,
Expand All @@ -44,5 +26,5 @@ J.-L. Starck, P. Ciuciu, and S. Farrens.
Important links
===============

- Official pySAP source code repo: https://github.com/cea-cosmic/pysap
- pySAP HTML documentation (last stable release): http://cea-cosmic.github.io/pysap
- Official PySAP source code repo: https://github.com/CEA-COSMIC/pysap
- PySAP HTML documentation (last stable release): https://python-pysap.readthedocs.io/en/latest/
4 changes: 1 addition & 3 deletions astro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
# for details.
##########################################################################

"""
This module defines all the Astro related plugins.
"""
"""Module defines all the Astro related plugins."""

__all__ = ['deconvolution', 'denoising']

Expand Down
4 changes: 1 addition & 3 deletions astro/deconvolution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
# for details.
##########################################################################

"""
This module defines all the Astro deconvolution plugins.
"""
"""Module defines all the Astro deconvolution plugins."""

__all__ = ['deconvolve', 'linear', 'wavelet_filters']

Expand Down
72 changes: 48 additions & 24 deletions astro/deconvolution/deconvolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
# for details.
##########################################################################

"""
CONDA-VU Galaxy Image Deconvolution
"""
"""CONDA-VU Galaxy Image Deconvolution."""

# System import
import pysap
from .linear import WaveletConvolve2
from .wavelet_filters import get_cospy_filters
from pysap.plugins.astro.deconvolution.linear import WaveletConvolve2
from pysap.plugins.astro.deconvolution.wavelet_filters import get_cospy_filters
from pysap.utils import condatvu_logo

# Third party import
Expand All @@ -31,7 +29,7 @@


def psf_convolve(data, psf, psf_rot=False):
"""PSF Convolution
"""PSF Convolution.
Parameters
----------
Expand All @@ -47,15 +45,14 @@ def psf_convolve(data, psf, psf_rot=False):
np.ndarray convolved image
"""

if psf_rot:
psf = rotate(psf)

return convolve(data, psf)


def get_weights(data, psf, filters, wave_thresh_factor=np.array([3, 3, 4])):
"""Get Sparsity Weights
"""Get Sparsity Weights.
Parameters
----------
Expand All @@ -74,20 +71,27 @@ def get_weights(data, psf, filters, wave_thresh_factor=np.array([3, 3, 4])):
np.ndarray weights
"""

noise_est = sigma_mad(data)

filter_conv = filter_convolve(np.rot90(psf, 2), filters)

filter_norm = np.array([np.linalg.norm(a) * b * np.ones(data.shape)
for a, b in zip(filter_conv, wave_thresh_factor)])
filter_norm = np.array([
np.linalg.norm(a) * b * np.ones(data.shape)
for a, b in zip(filter_conv, wave_thresh_factor)
])

return noise_est * filter_norm


def sparse_deconv_condatvu(data, psf, n_iter=300, n_reweights=1, verbose=False,
progress=True):
"""Sparse Deconvolution with Condat-Vu
def sparse_deconv_condatvu(
data,
psf,
n_iter=300,
n_reweights=1,
verbose=False,
progress=True,
):
"""Sparse Deconvolution with Condat-Vu.
Parameters
----------
Expand All @@ -109,14 +113,15 @@ def sparse_deconv_condatvu(data, psf, n_iter=300, n_reweights=1, verbose=False,
np.ndarray deconvolved image
"""

# Print the algorithm set-up
if verbose:
print(condatvu_logo())

# Define the wavelet filters
filters = (get_cospy_filters(data.shape,
transform_name='LinearWaveletTransformATrousAlgorithm'))
filters = get_cospy_filters(
data.shape,
transform_name='LinearWaveletTransformATrousAlgorithm'
)

# Set the reweighting scheme
reweight = cwbReweight(get_weights(data, psf, filters))
Expand All @@ -126,8 +131,11 @@ def sparse_deconv_condatvu(data, psf, n_iter=300, n_reweights=1, verbose=False,
dual = np.ones(filters.shape)

# Set the gradient operators
grad_op = GradBasic(data, lambda x: psf_convolve(x, psf),
lambda x: psf_convolve(x, psf, psf_rot=True))
grad_op = GradBasic(
data,
lambda x: psf_convolve(x, psf),
lambda x: psf_convolve(x, psf, psf_rot=True),
)

# Set the linear operator
linear_op = WaveletConvolve2(filters)
Expand All @@ -137,13 +145,29 @@ def sparse_deconv_condatvu(data, psf, n_iter=300, n_reweights=1, verbose=False,
prox_dual_op = SparseThreshold(linear_op, reweight.weights)

# Set the cost function
cost_op = costObj([grad_op, prox_op, prox_dual_op], tolerance=1e-6,
cost_interval=1, plot_output=True, verbose=verbose)
cost_op = costObj(
[grad_op, prox_op, prox_dual_op],
tolerance=1e-6,
cost_interval=1,
plot_output=True,
verbose=verbose,
)

# Set the optimisation algorithm
alg = Condat(primal, dual, grad_op, prox_op, prox_dual_op, linear_op,
cost_op, rho=0.8, sigma=0.5, tau=0.5, auto_iterate=False,
progress=progress)
alg = Condat(
primal,
dual,
grad_op,
prox_op,
prox_dual_op,
linear_op,
cost_op,
rho=0.8,
sigma=0.5,
tau=0.5,
auto_iterate=False,
progress=progress,
)

# Run the algorithm
alg.iterate(max_iter=n_iter)
Expand Down
Loading

0 comments on commit 41c6395

Please sign in to comment.