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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5308 - (show annotations)
Fri Dec 5 04:58:53 2014 UTC (4 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 5500 byte(s)
more silly importerror fixes in tests
1 from __future__ import print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # 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 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 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 import esys.escriptcore.utestselect as unittest
26 from esys.escriptcore.testing import *
27 import numpy as np
28 import os
29 import sys
30 from esys.downunder import *
31 from esys.escript import unitsSI as U
32 from esys.escript import *
33 from esys.weipa import saveSilo
34
35 # this is mainly to avoid warning messages
36 logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
37
38 try:
39 from esys.ripley import Rectangle as rRect, Brick as rBrick
40 HAVE_RIPLEY = True
41 except ImportError:
42 HAVE_RIPLEY = False
43
44 try:
45 from esys.finley import Rectangle as fRect, Brick as fBrick
46 HAVE_FINLEY = True
47 except ImportError:
48 HAVE_FINLEY = False
49
50
51
52 try:
53 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
54 except KeyError:
55 TEST_DATA_ROOT='ref_data'
56
57 try:
58 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
59 except KeyError:
60 WORKDIR='.'
61
62 writeFailMessage = "This feature (SimpleSEGYWriter.write()) depends on obspy,"+\
63 " which is not installed, see https://github.com/obspy/obspy for install guide"
64
65
66 class TestSeismicTools(unittest.TestCase):
67 @unittest.skipIf(getMPISizeWorld() > 1,
68 "segywriters don't support multiple ranks")
69 def test_segy_writer1(self):
70 sw= SimpleSEGYWriter(receiver_group=[0.,1.,2.], source=1., sampling_interval=10*U.msec, text="testing")
71 self.assertRaises(ValueError, sw.addRecord, [1])
72 for i in range(713):
73 # Create some random data.
74 data = np.random.ranf(3)
75 sw.addRecord(data)
76 try:
77 sw.write(os.path.join(WORKDIR,"test1.sgy"))
78 except Exception as e:
79 if str(e) == writeFailMessage:
80 raise unittest.SkipTest("obspy not installed")
81 raise e
82
83 @unittest.skipIf(getMPISizeWorld() > 1,
84 "segywriters don't support multiple ranks")
85 def test_segy_writer2(self):
86 sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
87 self.assertRaises(ValueError, sw.addRecord, [1])
88 for i in range(411):
89 # Create some random data.
90 data = np.random.ranf(3)
91 sw.addRecord(data)
92 try:
93 sw.write(os.path.join(WORKDIR,"test2.sgy"))
94 except Exception as e:
95 if str(e) == writeFailMessage:
96 raise unittest.SkipTest("obspy not installed")
97 raise e
98
99 def test_ricker(self):
100 rw=Ricker(f_dom=40, t_dom=None)
101
102 self.assertLess(abs(rw.getValue(0)), 1e-6)
103 self.assertAlmostEqual(rw.getValue(rw.getCenter()), 1. )
104 self.assertLess(abs(rw.getAcceleration(0.)), 1.)
105
106 def test_wavebase(self):
107 class TestWave(WaveBase):
108 def _getAcceleration(self, t, u):
109 return -sin(t)
110 def check_values(self, tw, t_ref):
111 t, u=tw.update(t_ref)
112 self.assertLess(abs(t-t_ref), 1e-9)
113 self.assertLess(abs(u-sin(t_ref)), 1e-6)
114
115 tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
116 self.assertAlmostEqual(0.001, tw.getTimeStepSize())
117 for t in [0.005, 0.007, 0.0071, 0.01, 0.02, 0.5]:
118 check_values(self, tw, t)
119 self.assertRaises(ValueError, tw.update, t-1)
120
121 def sonicRunner(self, domain, label):
122 v_p=1.
123 sw = SonicWave(domain, v_p, Ricker(0.5), source_tag='sss')
124 u = sw.update(1.)[1]
125 self.assertIsInstance(u, Data,
126 "u is not Data instance for %s"%label)
127 self.assertEqual(u.getShape(), (),
128 "u is not shape () for %s"%label)
129 self.assertEqual(u.getFunctionSpace(), Solution(domain),
130 "functionspace != solution for %s"%label)
131
132 def test_sonicwave2D(self):
133 doms = []
134 if HAVE_RIPLEY:
135 doms.append((rRect, "ripley"))
136 if HAVE_FINLEY:
137 doms.append((fRect, "finley"))
138 for domType, impl in doms:
139 domain=domType(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
140 self.sonicRunner(domain, "%s.Rectangle"%impl)
141
142 def test_sonicwave3D(self):
143 doms = []
144 if HAVE_RIPLEY:
145 doms.append((rBrick, "ripley"))
146 if HAVE_FINLEY:
147 doms.append((fBrick, "finley"))
148 for domType, impl in doms:
149 domain=domType(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
150 self.sonicRunner(domain, "%s.Brick"%impl)
151
152 if __name__ == '__main__':
153 run_tests(__name__, exit_on_failure=True)
154

  ViewVC Help
Powered by ViewVC 1.1.26