/[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 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (20 months, 1 week ago) by jfenwick
File MIME type: text/x-python
File size: 5499 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

  ViewVC Help
Powered by ViewVC 1.1.26