Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Stolker committed Mar 2, 2019
1 parent af44905 commit fe8433e
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 82 deletions.
120 changes: 82 additions & 38 deletions pynpoint/processing/timedenoising.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
CWT based wavelet de-noising for speckle suppression in the time domain. The module acts as an
additional pre-processing step. For more information see Bonse et al. 2018.
Continuous wavelet transform (CWT) and discrete wavelet transform (DWT) denoising for speckle
suppression in the time domain. The module can be used as additional preprocessing step. See
Bonse et al. 2018 more information.
"""

from __future__ import absolute_import
Expand All @@ -16,18 +17,30 @@

class CwtWaveletConfiguration(object):
"""
Configuration capsule for a CWT based time de-noising. Standard configuration as in the original
paper.
Configuration capsule for a CWT based time denoising. Standard configuration as in the
original paper.
"""

def __init__(self,
wavelet="dog",
wavelet_order=2,
keep_mean=False,
resolution=0.5):
"""
:param wavelet: Wavelet.
:type wavelet: str
:param wavelet_order: Wavelet order.
:type wavelet_order: int
:param keep_mean: Keep mean.
:type keep_mean: bool
:param resolution: Resolution.
:type resolution: float
:return: None
"""

if wavelet not in ["dog", "morlet"]:
raise ValueError("CWT supports only dog and morlet wavelets")
raise ValueError("CWT supports only 'dog' and 'morlet' wavelets.")

self.m_wavelet = wavelet
self.m_wavelet_order = wavelet_order
Expand All @@ -37,13 +50,19 @@ def __init__(self,

class DwtWaveletConfiguration(object):
"""
Configuration capsule for a DWT based time de-noising. A cheap alternative of the CWT based
wavelet de-noising. However, the supported wavelets should perform worse compared to the
Configuration capsule for a DWT based time denoising. A cheap alternative of the CWT based
wavelet denoising. However, the supported wavelets should perform worse compared to the
CWT DOG wavelet.
"""

def __init__(self,
wavelet="db8"):
"""
:param wavelet: Wavelet.
:type wavelet: str
:return: None
"""

# create list of supported wavelets
supported = []
Expand All @@ -52,15 +71,15 @@ def __init__(self,

# check if wavelet is supported
if wavelet not in supported:
raise ValueError("DWT supports only " + str(supported) + " as input wavelet")
raise ValueError("DWT supports only " + str(supported) + " as input wavelet.")

self.m_wavelet = wavelet


class WaveletTimeDenoisingModule(ProcessingModule):
"""
Module for speckle subtraction in time domain used CWT or DWT wavelet shrinkage.
See Bonse et al 2018.
Module for speckle subtraction in the time domain by using CWT or DWT wavelet shrinkage
(see Bonse et al. 2018).
"""

def __init__(self,
Expand All @@ -77,14 +96,22 @@ def __init__(self,
:param wavelet_configuration: Instance of DwtWaveletConfiguration or CwtWaveletConfiguration
which gives the parameters of the wavelet transformation to be
used.
:param name_in: Module name
:param image_in_tag: Input tag in the central database
:param image_out_tag: Output tag in the central database
:param padding: Padding strategy can be (zero, mirror and none)
:param median_filter: If true a median filter in time gets applied which removes outliers
in time like cosmic rays
:type wavelet_configuration: pynpoint.processing.timedenoising.CwtWaveletConfiguration or
pynpoint.processing.timedenoising.DwtWaveletConfiguration
:param name_in: Unique name of the module instance.
:type name_in: str
:param image_in_tag: Tag of the database entry that is read as input.
:type image_in_tag: str
:param image_out_tag: Tag of the database entry that is written as output.
:type image_out_tag: str
:param padding: Padding method ("zero", "mirror", or "none").
:type padding: str
:param median_filter: If true a median filter in time is applied which removes outliers
in time like cosmic rays.
:type median_filter: bool
:param threshold_function: Threshold function used for wavelet shrinkage in the wavelet
space. Can be soft or hard.
space ("soft" or "hard").
:type threshold_function: str
:return: None
"""
Expand All @@ -105,23 +132,28 @@ def __init__(self,

def run(self):
"""
Run method of the module. Applies time de-noising using multiprocessing parallel on all
lines in time.
Run method of the module. Applies the time denoising for the lines in time in parallel.
:return: None
"""

if isinstance(self.m_wavelet_configuration, DwtWaveletConfiguration):
# use DWT denoising

if self.m_padding == "const_mean":
self.m_padding = "constant"

if self.m_padding == "none":
self.m_padding = "periodic"

def denoise_line_in_time(signal_in):
"""
Definition of temporal de-noising for DWT
:param signal_in: 1d signal
:return:
Definition of the temporal denoising for DWT.
:param signal_in: 1D input signal.
:type signal_in:
:return: Multilevel 1D inverse discrete wavelet transform.
:rtype: numpy.ndarray
"""

if self.m_threshold_function:
Expand All @@ -138,20 +170,27 @@ def denoise_line_in_time(signal_in):
threshold = sigma * np.sqrt(2 * np.log(len(signal_in)))

denoised = coef[:]

denoised[1:] = (pywt.threshold(i,
value=threshold,
mode=threshold_mode)
for i in denoised[1:])

return pywt.waverec(denoised,
wavelet=self.m_wavelet_configuration.m_wavelet,
mode=self.m_padding)

elif isinstance(self.m_wavelet_configuration, CwtWaveletConfiguration):

def denoise_line_in_time(signal_in):
"""
Definition of temporal de-noising for CWT
:param signal_in: 1d signal
:return:
Definition of temporal denoising for CWT.
:param signal_in: 1D input signal.
:type signal_in:
:return: 1D output signal.
:rtype: numpy.ndarray
"""

cwt_capsule = WaveletAnalysisCapsule(
Expand All @@ -168,9 +207,8 @@ def denoise_line_in_time(signal_in):
cwt_capsule.median_filter()

cwt_capsule.update_signal()
res_signal = cwt_capsule.get_signal()

return res_signal
return cwt_capsule.get_signal()

else:
return
Expand All @@ -191,13 +229,24 @@ def denoise_line_in_time(signal_in):

class TimeNormalizationModule(ProcessingModule):
"""
Module for normalization of global brightness variations of the detector (see Bonse et al 2018.)
Module for normalization of global brightness variations of the detector
(see Bonse et al. 2018).
"""

def __init__(self,
name_in="normalization",
image_in_tag="im_arr",
image_out_tag="im_arr_normalized"):
"""
:param name_in: Unique name of the module instance.
:type name_in: str
:param image_in_tag: Tag of the database entry that is read as input.
:type image_in_tag: str
:param image_out_tag: Tag of the database entry that is written as output.
:type image_out_tag: str
:return: None
"""

super(TimeNormalizationModule, self).__init__(name_in=name_in)

Expand All @@ -207,20 +256,15 @@ def __init__(self,
def run(self):
"""
Run method of the module.
:return: None
"""

def image_normalization(image_in):
"""
Subtract the median pixel value from the current image
"""

def _normalization(image_in):
median = np.median(image_in)
tmp_image = image_in - median

return tmp_image
return image_in - median

self.apply_function_to_images(image_normalization,
self.apply_function_to_images(_normalization,
self.m_image_in_port,
self.m_image_out_port,
"Running TimeNormalizationModule...")
Expand Down

0 comments on commit fe8433e

Please sign in to comment.