/[escript]/trunk/downunder/test/python/run_seismic.py
ViewVC logotype

Annotation of /trunk/downunder/test/python/run_seismic.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (hide annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 5246 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


1 gross 4539
2     ##############################################################################
3     #
4 jfenwick 4657 # Copyright (c) 2003-2014 by University of Queensland
5 gross 4539 # http://www.uq.edu.au
6     #
7     # Primary Business: Queensland, Australia
8     # Licensed under the Open Software License version 3.0
9     # http://www.opensource.org/licenses/osl-3.0.php
10     #
11     # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 gross 4539 #
15     ##############################################################################
16    
17 jfenwick 4657 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 gross 4539 http://www.uq.edu.au
19     Primary Business: Queensland, Australia"""
20     __license__="""Licensed under the Open Software License version 3.0
21     http://www.opensource.org/licenses/osl-3.0.php"""
22     __url__="https://launchpad.net/escript-finley"
23    
24     import logging
25 jfenwick 4938 import esys.escriptcore.utestselect as unittest
26 gross 4539 import numpy as np
27     import os
28     import sys
29     from esys.downunder import *
30     from esys.escript import unitsSI as U
31 gross 4544 from esys.escript import *
32 gross 4539 from esys.weipa import saveSilo
33    
34     # this is mainly to avoid warning messages
35     logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
36    
37     try:
38     TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
39     except KeyError:
40     TEST_DATA_ROOT='ref_data'
41    
42     try:
43     WORKDIR=os.environ['DOWNUNDER_WORKDIR']
44     except KeyError:
45     WORKDIR='.'
46    
47 sshaw 4782 writeFailMessage = "This feature (SimpleSEGYWriter.write()) depends on obspy, which is not installed, see https://github.com/obspy/obspy for install guide"
48 gross 4539
49    
50     class TestSeismicTools(unittest.TestCase):
51 sshaw 4858 @unittest.skipIf(getMPISizeWorld() > 1,
52     "segywriters don't support multiple ranks")
53 sshaw 4778 def test_segy_writer1(self):
54 gross 4539 sw= SimpleSEGYWriter(receiver_group=[0.,1.,2.], source=1., sampling_interval=10*U.msec, text="testing")
55     self.assertRaises(ValueError, sw.addRecord, [1])
56 sshaw 4576 for i in range(713):
57 gross 4539 # Create some random data.
58     data = np.random.ranf(3)
59     sw.addRecord(data)
60 sshaw 4778 try:
61     sw.write(os.path.join(WORKDIR,"test1.sgy"))
62 sshaw 4782 except Exception as e:
63     if str(e) == writeFailMessage:
64     raise unittest.SkipTest("obspy not installed")
65     raise e
66 sshaw 4858
67     @unittest.skipIf(getMPISizeWorld() > 1,
68     "segywriters don't support multiple ranks")
69 sshaw 4778 def test_segy_writer2(self):
70 gross 4539 sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
71     self.assertRaises(ValueError, sw.addRecord, [1])
72 sshaw 4576 for i in range(411):
73 gross 4539 # Create some random data.
74     data = np.random.ranf(3)
75     sw.addRecord(data)
76 sshaw 4778 try:
77     sw.write(os.path.join(WORKDIR,"test2.sgy"))
78 sshaw 4782 except Exception as e:
79     if str(e) == writeFailMessage:
80     raise unittest.SkipTest("obspy not installed")
81     raise e
82 gross 4541
83 sshaw 4778 def test_ricker(self):
84     rw=Ricker(f_dom=40, t_dom=None)
85 gross 4539
86 sshaw 4782 self.assertLess(abs(rw.getValue(0)), 1e-6)
87 sshaw 4778 self.assertAlmostEquals(rw.getValue(rw.getCenter()), 1. )
88 sshaw 4782 self.assertLess(abs(rw.getAcceleration(0.)), 1.)
89 gross 4544
90 sshaw 4778 def test_wavebase(self):
91     class TestWave(WaveBase):
92     def _getAcceleration(self, t, u):
93     return -sin(t)
94 sshaw 4782 def check_values(self, tw, t_ref):
95     t, u=tw.update(t_ref)
96     self.assertLess(abs(t-t_ref), 1e-9)
97     self.assertLess(abs(u-sin(t_ref)), 1e-6)
98    
99 sshaw 4778 tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
100     self.assertAlmostEquals(0.001, tw.getTimeStepSize())
101 sshaw 4782 for t in [0.005, 0.007, 0.0071, 0.01, 0.02, 0.5]:
102     check_values(self, tw, t)
103     self.assertRaises(ValueError, tw.update, t-1)
104 sshaw 4778
105 sshaw 4782 def sonicRunner(self, domain, label):
106     v_p=1.
107     sw = SonicWave(domain, v_p, Ricker(0.5), source_tag='sss')
108     u = sw.update(1.)[1]
109     self.assertIsInstance(u, Data,
110     "u is not Data instance for %s"%label)
111     self.assertEqual(u.getShape(), (),
112     "u is not shape () for %s"%label)
113     self.assertEqual(u.getFunctionSpace(), Solution(domain),
114     "functionspace != solution for %s"%label)
115 sshaw 4778
116     def test_sonicwave2D(self):
117 sshaw 4782 from esys.finley import Rectangle as fRect
118     from esys.ripley import Rectangle as rRect
119     for domType, impl in [(fRect, "finley"), (rRect, "ripley")]:
120     domain=domType(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
121     self.sonicRunner(domain, "%s.Rectangle"%impl)
122 sshaw 4778
123     def test_sonicwave3D(self):
124 sshaw 4782 from esys.finley import Brick as fBrick
125     from esys.ripley import Brick as rBrick
126     for domType, impl in [(fBrick, "finley"), (rBrick, "ripley")]:
127     domain=domType(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
128     self.sonicRunner(domain, "%s.Brick"%impl)
129 gross 4546
130 gross 4539 if __name__ == "__main__":
131     suite = unittest.TestSuite()
132     suite.addTest(unittest.makeSuite(TestSeismicTools))
133     s=unittest.TextTestRunner(verbosity=2).run(suite)
134     if not s.wasSuccessful(): sys.exit(1)
135    

  ViewVC Help
Powered by ViewVC 1.1.26