/[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 5073 - (show annotations)
Mon Jun 23 22:22:44 2014 UTC (5 years, 3 months ago) by caltinay
File MIME type: text/x-python
File size: 5144 byte(s)
fixing some py3 warnings.

1
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 TEST_DATA_ROOT=os.environ['DOWNUNDER_TEST_DATA_ROOT']
40 except KeyError:
41 TEST_DATA_ROOT='ref_data'
42
43 try:
44 WORKDIR=os.environ['DOWNUNDER_WORKDIR']
45 except KeyError:
46 WORKDIR='.'
47
48 writeFailMessage = "This feature (SimpleSEGYWriter.write()) depends on obspy, which is not installed, see https://github.com/obspy/obspy for install guide"
49
50
51 class TestSeismicTools(unittest.TestCase):
52 @unittest.skipIf(getMPISizeWorld() > 1,
53 "segywriters don't support multiple ranks")
54 def test_segy_writer1(self):
55 sw= SimpleSEGYWriter(receiver_group=[0.,1.,2.], source=1., sampling_interval=10*U.msec, text="testing")
56 self.assertRaises(ValueError, sw.addRecord, [1])
57 for i in range(713):
58 # Create some random data.
59 data = np.random.ranf(3)
60 sw.addRecord(data)
61 try:
62 sw.write(os.path.join(WORKDIR,"test1.sgy"))
63 except Exception as e:
64 if str(e) == writeFailMessage:
65 raise unittest.SkipTest("obspy not installed")
66 raise e
67
68 @unittest.skipIf(getMPISizeWorld() > 1,
69 "segywriters don't support multiple ranks")
70 def test_segy_writer2(self):
71 sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
72 self.assertRaises(ValueError, sw.addRecord, [1])
73 for i in range(411):
74 # Create some random data.
75 data = np.random.ranf(3)
76 sw.addRecord(data)
77 try:
78 sw.write(os.path.join(WORKDIR,"test2.sgy"))
79 except Exception as e:
80 if str(e) == writeFailMessage:
81 raise unittest.SkipTest("obspy not installed")
82 raise e
83
84 def test_ricker(self):
85 rw=Ricker(f_dom=40, t_dom=None)
86
87 self.assertLess(abs(rw.getValue(0)), 1e-6)
88 self.assertAlmostEqual(rw.getValue(rw.getCenter()), 1. )
89 self.assertLess(abs(rw.getAcceleration(0.)), 1.)
90
91 def test_wavebase(self):
92 class TestWave(WaveBase):
93 def _getAcceleration(self, t, u):
94 return -sin(t)
95 def check_values(self, tw, t_ref):
96 t, u=tw.update(t_ref)
97 self.assertLess(abs(t-t_ref), 1e-9)
98 self.assertLess(abs(u-sin(t_ref)), 1e-6)
99
100 tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
101 self.assertAlmostEqual(0.001, tw.getTimeStepSize())
102 for t in [0.005, 0.007, 0.0071, 0.01, 0.02, 0.5]:
103 check_values(self, tw, t)
104 self.assertRaises(ValueError, tw.update, t-1)
105
106 def sonicRunner(self, domain, label):
107 v_p=1.
108 sw = SonicWave(domain, v_p, Ricker(0.5), source_tag='sss')
109 u = sw.update(1.)[1]
110 self.assertIsInstance(u, Data,
111 "u is not Data instance for %s"%label)
112 self.assertEqual(u.getShape(), (),
113 "u is not shape () for %s"%label)
114 self.assertEqual(u.getFunctionSpace(), Solution(domain),
115 "functionspace != solution for %s"%label)
116
117 def test_sonicwave2D(self):
118 from esys.finley import Rectangle as fRect
119 from esys.ripley import Rectangle as rRect
120 for domType, impl in [(fRect, "finley"), (rRect, "ripley")]:
121 domain=domType(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
122 self.sonicRunner(domain, "%s.Rectangle"%impl)
123
124 def test_sonicwave3D(self):
125 from esys.finley import Brick as fBrick
126 from esys.ripley import Brick as rBrick
127 for domType, impl in [(fBrick, "finley"), (rBrick, "ripley")]:
128 domain=domType(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
129 self.sonicRunner(domain, "%s.Brick"%impl)
130
131 if __name__ == '__main__':
132 run_tests(__name__, exit_on_failure=True)
133

  ViewVC Help
Powered by ViewVC 1.1.26