Skip to content

Commit

Permalink
upd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marius committed Aug 23, 2017
1 parent 2348d37 commit 7a40279
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 170 deletions.
5 changes: 5 additions & 0 deletions src/quadtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ def clearLeafBlacklist(self):
self.config.leaf_blacklist = []

def blacklistLeaves(self, leaves):
''' Blacklist a leaf and exclude it from the tree
:param leaves: Leaf instances
:type leaves: list
'''
self.config.leaf_blacklist.extend(leaves)
self._log.debug('Blacklisted leaves: %s'
% ', '.join(self.config.leaf_blacklist))
Expand Down
29 changes: 8 additions & 21 deletions test/test_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,22 @@
import unittest
import numpy as num
import matplotlib.pyplot as plt
import os

from kite import Scene, TestScene
from .common import Benchmark
from . import common

benchmark = Benchmark()
benchmark = common.Benchmark()


class TestCovariance(unittest.TestCase):

def setUp(self):
file = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'data/20110214_20110401_ml4_sm.unw.geo_ig_dsc_ionnocorr.mat')
@classmethod
def setUpClass(cls):
file = common.get_test_data(
'20110214_20110401_ml4_sm.unw.geo_ig_dsc_ionnocorr.mat')
cls.sc = Scene.import_data(file)

self.sc = Scene.import_data(file)
self.sc.meta.scene_title = 'Matlab Input - Myanmar 2011-02-14'
self.sc._log.setLevel('CRITICAL')

# self.sc.quadtree.epsilon = .05
# self.sc.quadtree.tile_size_limit = (250, 12e3)
# self.sc = TestScene.createGauss(ny=250)

def __setUp(self):
self.sc = TestScene.createGauss()
# self.sc._log.setLevel('CRITICAL')

# @unittest.skip('Skipped')
def testCovariance(self):
def test_covariance(self):
cov = self.sc.covariance
cov.epsilon = .02
cov.subsampling = 24
Expand Down
7 changes: 5 additions & 2 deletions test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
filenames = {
'matlab': 'myanmar_alos_dsc_ionocorr.mat',
'gmtsar': 'gmtsar/',
# 'roi_pac': None,
# 'gamma': None,
# 'isce': None,
}


Expand All @@ -26,7 +29,7 @@ def tearDownClass(cls):
shutil.rmtree(cls.tmp_dir)


def _make_function(fmt, filename):
def _create_test_func(fmt, filename):
def f(self):
fn = common.get_test_data(filename)
if isinstance(fn, list):
Expand All @@ -52,4 +55,4 @@ def f(self):
setattr(
SceneIOTest,
'test_import_%s' % fmt,
_make_function(fmt, filename))
_create_test_func(fmt, filename))
114 changes: 0 additions & 114 deletions test/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,120 +39,6 @@ def testQuadtree(self):
qt.tile_size_min = 20
qt.tile_size_max = s

def testIO(self):
import tempfile
import shutil

tmp_dir = tempfile.mkdtemp(prefix='kite')
file = os.path.join(tmp_dir, self.__class__.__name__)
sc1 = self.sc

sc1.quadtree.epsilon = .120
sc1.quadtree.tile_size_min = 50
sc1.quadtree.tile_size_max = 23000
sc1.quadtree.nan_allowed = .9
try:
sc1.save(file)
sc2 = Scene()
sc2.setLogLevel('ERROR')
sc2.load(file)

self.assertEqual(sc1.quadtree.epsilon,
sc2.quadtree.epsilon)
self.assertEqual(sc1.quadtree.nan_allowed,
sc2.quadtree.nan_allowed)
self.assertEqual(sc1.quadtree.tile_size_min,
sc2.quadtree.tile_size_min)
self.assertEqual(sc1.quadtree.tile_size_max,
sc2.quadtree.tile_size_max)
self.assertEqual(sc1.quadtree.nleaves,
sc2.quadtree.nleaves)
self.assertEqual([l.id for l in sc1.quadtree.leaves],
[l.id for l in sc2.quadtree.leaves])

finally:
shutil.rmtree(tmp_dir)


class TestMatlabScene(unittest.TestCase):
def setUp(self):
file = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'data/20110214_20110401_ml4_sm.unw.geo_ig_dsc_ionnocorr.mat')

self.sc = Scene()
self.sc.setLogLevel('ERROR')
self.sc.import_data(file)
self.sc.meta.scene_title = 'Matlab Input - Myanmar 2011-02-14'

def testQuadtree(self):
qt = self.sc.quadtree
for e in num.linspace(0.118, .3, num=30):
qt.epsilon = e

for nan in num.linspace(0.1, 1., num=30):
qt.nan_allowed = nan

for s in num.linspace(100, 4000, num=30):
qt.tile_size_min = s
qt.tile_size_max = 5000

for s in num.linspace(200, 4000, num=30):
qt.tile_size_min = 0
qt.tile_size_max = 5000

def testIO(self):
import tempfile
import shutil

tmp_dir = tempfile.mkdtemp(prefix='kite')
# print(tmp_dir)
file = os.path.join(tmp_dir, self.__class__.__name__)
sc1 = self.sc

sc1.quadtree.epsilon = .076
sc1.quadtree.tile_size_min = 50
sc1.quadtree.tile_size_max = 12773
sc1.quadtree.nan_allowed = .8

sc1.covariance.config.a = 0.008
sc1.covariance.config.b = 300.2
sc1.covariance.config.variance = .2
sc1.covariance.covariance_matrix

try:
sc1.save(file)
sc2 = Scene()
sc2.setLogLevel('ERROR')
sc2.load(file)

self.assertEqual(sc1.quadtree.epsilon,
sc2.quadtree.epsilon)
self.assertEqual(sc1.quadtree.nan_allowed,
sc2.quadtree.nan_allowed)
self.assertEqual(sc1.quadtree.tile_size_min,
sc2.quadtree.tile_size_min)
self.assertEqual(sc1.quadtree.tile_size_max,
sc2.quadtree.tile_size_max)
self.assertEqual(sc1.quadtree.nleaves,
sc2.quadtree.nleaves)
self.assertEqual([l.id for l in sc1.quadtree.leaves],
[l.id for l in sc2.quadtree.leaves])

self.assertEqual(sc1.covariance.variance,
sc2.covariance.variance)
self.assertEqual(sc1.covariance.covariance_model,
sc2.covariance.covariance_model)
num.testing.assert_equal(sc1.covariance.weight_matrix_focal,
sc2.covariance.weight_matrix_focal)
num.testing.assert_equal(sc1.covariance.covariance_matrix_focal,
sc2.covariance.covariance_matrix_focal)
num.testing.assert_equal(sc1.covariance.covariance_matrix,
sc2.covariance.covariance_matrix)

finally:
shutil.rmtree(tmp_dir)


if __name__ == '__main__':
unittest.main()
22 changes: 14 additions & 8 deletions test/test_source_compound_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

km = 1e3
benchmark = Benchmark()
plot = False


class CompoundModelsTest(unittest.TestCase):
Expand Down Expand Up @@ -52,7 +53,8 @@ def runECM():
ax, ay, az, P, mu, lamda)
ue, un, uv, _, _ = runECM()

# self.plot_displacement(un.reshape(nrows, ncols))
if plot:
self._plot_displacement(un.reshape(nrows, ncols))

def test_ECM_against_Octave(self):
from scipy import io
Expand Down Expand Up @@ -104,8 +106,9 @@ def runECM():
# print [pym.min(), pym.max()], [m.min(), m.max()]
num.testing.assert_allclose(pym, m, rtol=1e-11)

# self.plot_displacement(uv)
# self.plot_displacement(mat['uv'])
if plot:
self._plot_displacement(uv)
self._plot_displacement(mat['uv'])

def testEllipsoidSource(self):
def r(lo, hi):
Expand Down Expand Up @@ -167,8 +170,9 @@ def run_pointCDM():
m = mat[comp]
# print [pym.min(), pym.max()], [m.min(), m.max()]
num.testing.assert_allclose(pym, m, rtol=1e-9)
# self.plot_displacement(mat['uv'])
# self.plot_displacement(uv)
if plot:
self._plot_displacement(mat['uv'])
self._plot_displacement(uv)

def testPointCompoundSourceSource(self):
def r(lo, hi):
Expand All @@ -182,10 +186,11 @@ def r(lo, hi):
src.regularize()
ms.addSource(src)

# self.plot_modelScene(ms)
if plot:
self._plot_modelScene(ms)

@staticmethod
def plot_modelScene(ms):
def _plot_modelScene(ms):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
Expand All @@ -196,7 +201,7 @@ def plot_modelScene(ms):
plt.show()

@staticmethod
def plot_displacement(u):
def _plot_displacement(u):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
Expand All @@ -206,5 +211,6 @@ def plot_displacement(u):


if __name__ == '__main__':
plot = True
unittest.main(exit=False)
print benchmark
19 changes: 11 additions & 8 deletions test/test_source_okada.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from kite import ModelScene, TestModelScene
from kite.sources import OkadaSource, OkadaPath

plot = False


class testSourceOkada(unittest.TestCase):
__name__ = 'SandboxTestOkada'
Expand All @@ -19,7 +21,7 @@ def tearDown(self):
return
shutil.rmtree(self.tmpdir)

def testOkadaSource(self):
def test_okada_source(self):
nsources = 2

def r(lo, hi):
Expand All @@ -39,10 +41,10 @@ def r(lo, hi):
length=length,
width=15. * length**.66,))

self.plotDisplacement(self.ms)
if plot:
self._plot_displacement(self.ms)

@unittest.skip
def testOkadaPath(self):
def _test_okada_path(self):
ok_path = OkadaPath(
easting=10000,
northing=24000,)
Expand All @@ -51,11 +53,11 @@ def testOkadaPath(self):
ok_path.addNode(22000, 34000)
# ok_path.insertNode(1, 22000, 34000)
self.ms.addSource(ok_path)

self.plotDisplacement(self.ms)
if plot:
self._plot_displacement(self.ms)

@staticmethod
def plotDisplacement(ms):
def _plot_displacement(ms):
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
fig = plt.figure()
Expand All @@ -79,9 +81,10 @@ def testModelSaveLoad(self):
msc = TestModelScene.randomOkada(nsources=2)
msc.save(filename=filename)

msc2 = ModelScene.load(filename=filename)
msd2 = ModelScene.load(filename=filename) # noqa
# print msc2.config


if __name__ == '__main__':
plot = True
unittest.main(exit=False)

0 comments on commit 7a40279

Please sign in to comment.