Skip to content

Commit

Permalink
Merge pull request #124 from jaidevd/jd-test-postproc
Browse files Browse the repository at this point in the history
Add a couple of tests for the postprocessing functions
  • Loading branch information
jaidevd committed Mar 8, 2016
2 parents 7e6f18b + 4159e16 commit 28547d6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
1 change: 1 addition & 0 deletions continuous_integration/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ scipy
matplotlib
nose
libgfortran
scikit-image
20 changes: 10 additions & 10 deletions tftb/processing/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def hough_transform(image, m=None, n=None):
:type image:
:type m:
:type n:
:return:
:rtype:
:return:
:rtype:
"""
xmax, ymax = image.shape
if m is None:
Expand Down Expand Up @@ -78,8 +78,8 @@ def renyi_information(tfr, timestamps=None, freq=None, alpha=3.0):
:type timestamps:
:type freq:
:type alpha:
:return:
:rtype:
:return:
:rtype:
"""
if alpha == 1 and tfr.min().min() < 0:
raise ValueError("Distribution with negative values not allowed.")
Expand Down Expand Up @@ -109,8 +109,8 @@ def ideal_tfr(iflaws, timestamps=None, n_fbins=None):
:type iflaws:
:type timestamps:
:type n_fbins:
:return:
:rtype:
:return:
:rtype:
"""
ifrow, ifcol = iflaws.shape
if timestamps is None:
Expand Down Expand Up @@ -141,8 +141,8 @@ def friedman_density(tfr, re_mat, timestamps=None):
:type tfr:
:type re_mat:
:type timestamps:
:return:
:rtype:
:return:
:rtype:
"""
tfrrow, tfrcol = tfr.shape
hatrow, hatcol = re_mat.shape
Expand Down Expand Up @@ -174,8 +174,8 @@ def ridges(tfr, re_mat, timestamps=None, method='rsp'):
:type re_mat:
:type timestamps:
:type method:
:return:
:rtype:
:return:
:rtype:
"""
method = method.lower()
tfrrow, tfrcol = tfr.shape
Expand Down
54 changes: 54 additions & 0 deletions tftb/processing/tests/test_postprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Cube26 product code
#
# (C) Copyright 2015 Cube26 Software Pvt Ltd
# All right reserved.
#
# This file is confidential and NOT open source. Do not distribute.
#

"""
Tests for tftb.processing.postprocessing
"""

from tftb.tests.base import TestBase
from tftb.generators import atoms, fmlin
from tftb.processing import WignerVilleDistribution
from tftb.processing import postprocessing as pproc
from skimage.transform import hough_line_peaks, hough_line
import numpy as np
import unittest


class TestPostprocessing(TestBase):

def test_renyi_information(self):
"""Check if Renyi entropy computation is correct."""
sig = atoms(128, np.array([[64., 0.25, 20., 1.]]))
tfr, _, _ = WignerVilleDistribution(sig).run()
R1 = pproc.renyi_information(tfr)
sig = atoms(128, np.array([[32., 0.25, 20., 1.],
[96., 0.25, 20., 1.]]))
tfr, _, _ = WignerVilleDistribution(sig).run()
R2 = pproc.renyi_information(tfr)
self.assertAlmostEqual(R2 - R1, 0.98, places=1)

def test_ideal_tfr(self):
"""Test if the ideal TFR can be found using the instantaneous frequency
laws."""
_, iflaw1 = fmlin(128, 0.0, 0.2)
_, iflaw2 = fmlin(128, 0.3, 0.5)
iflaws = np.c_[iflaw1, iflaw2].T
tfr, _, _ = pproc.ideal_tfr(iflaws)
tfr[tfr == 1] = 255
tfr = tfr.astype(np.uint8)
hspace, angles, dists = hough_line(tfr)
for x in hough_line_peaks(hspace, angles, dists):
self.assertEqual(len(x), 2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 28547d6

Please sign in to comment.