Skip to content

Commit

Permalink
Merge bfbbc96 into 8b9029b
Browse files Browse the repository at this point in the history
  • Loading branch information
sfarrens committed Oct 10, 2019
2 parents 8b9029b + bfbbc96 commit bece8c2
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 8 deletions.
60 changes: 52 additions & 8 deletions examples/astro/galaxy_deconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,82 @@
In this tutorial we will deconvolve the PSF effects from an example galaxy
image.
Import astro data
-----------------
Import Dependencies
-------------------
The example galaxy image is convolved with the example PSF and random noise is
added simulating an observation with SNR~5.
Import functions from PySAP and ModOpt.
"""

import numpy as np
from pysap import Image
from pysap.data import get_sample_data
from pysap.plugins.astro.deconvolve.deconvolve import sparse_deconv_condatvu
from pysap.plugins.astro.deconvolution.deconvolve import sparse_deconv_condatvu
from modopt.signal.noise import add_noise
from modopt.math.convolve import convolve

#############################################################################
# Load astro data
# ---------------
#
# Load the example images

galaxy = get_sample_data('astro-galaxy')
psf = get_sample_data('astro-psf')

#############################################################################
# Show the clean galaxy image

galaxy.show()

# Generate a noisy observed image
#############################################################################
# Generate noisy observation
# --------------------------
#
# Convolve the image with a point spread function (PSF) using the `convolve`
# function. Then add random Gaussian noise with standard deviation 0.0005
# using the `add_noise` function.

obs_data = add_noise(convolve(galaxy.data, psf.data), sigma=0.0005)

#############################################################################
# Create a PySAP image object

image_obs = Image(data=np.abs(obs_data))

#############################################################################
# Show the noisy galaxy image

image_obs.show()

# Deconvolve the observed image
#############################################################################
# Deconvolve
# ----------
#
# Use the `sparse_deconv_condatvu` function to deconvolve the noisy image and
# set the maximum number of iterations to 3000.

deconv_data = sparse_deconv_condatvu(obs_data, psf.data, n_iter=3000)

#############################################################################
# Create a PySAP image object for the result

image_rec = Image(data=np.abs(deconv_data))

#############################################################################
# Show the deconvolved galaxy image

image_rec.show()

# Show the residual
#############################################################################
# Residual
# --------
#
# Create a PySAP image object for the residual

residual = Image(data=np.abs(galaxy.data - deconv_data))

#############################################################################
# Show the residual

residual.show()
83 changes: 83 additions & 0 deletions examples/astro/galaxy_denoising.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
Galaxy Image Denoising
======================
Credit: S. Farrens
In this tutorial we will remove the noise from an example galaxy image.
Import Dependencies
-------------------
Import functions from PySAP and ModOpt.
"""

import numpy as np
from pysap import Image
from pysap.data import get_sample_data
from pysap.plugins.astro.denoising.denoise import denoise
from modopt.signal.noise import add_noise

#############################################################################
# Load the image of galaxy NGC2997

galaxy = get_sample_data('astro-ngc2997')


#############################################################################
# Show the clean galaxy image

galaxy.show()

#############################################################################
# Generate noisy observation
# --------------------------
#
# Convolve the image with a point spread function (PSF) using the `convolve`
# function. Then add random Gaussian noise with standard deviation 0.0005
# using the `add_noise` function.

obs_data = add_noise(galaxy.data, sigma=100)

#############################################################################
# Create a PySAP image object

image_obs = Image(data=np.abs(obs_data))

#############################################################################
# Show the noisy galaxy image

image_obs.show()

#############################################################################
# Deconvolve
# ----------
#
# Use the `sparse_deconv_condatvu` function to deconvolve the noisy image and
# set the maximum number of iterations to 3000.

denoise_data = denoise(obs_data, n_scales=4)

#############################################################################
# Create a PySAP image object for the result

image_rec = Image(data=np.abs(denoise_data))

#############################################################################
# Show the deconvolved galaxy image

image_rec.show()

#############################################################################
# Residual
# --------
#
# Create a PySAP image object for the residual

residual = Image(data=np.abs(galaxy.data - denoise_data))

#############################################################################
# Show the residual

residual.show()

0 comments on commit bece8c2

Please sign in to comment.