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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4778 by sshaw, Thu Mar 20 00:41:58 2014 UTC revision 4782 by sshaw, Thu Mar 20 05:16:16 2014 UTC
# Line 44  try: Line 44  try:
44  except KeyError:  except KeyError:
45      WORKDIR='.'      WORKDIR='.'
46            
47    writeFailMessage = "This feature (SimpleSEGYWriter.write()) depends on obspy, which is not installed, see https://github.com/obspy/obspy for install guide"
48    
49    
50  class TestSeismicTools(unittest.TestCase):  class TestSeismicTools(unittest.TestCase):
# Line 57  class TestSeismicTools(unittest.TestCase Line 57  class TestSeismicTools(unittest.TestCase
57             sw.addRecord(data)             sw.addRecord(data)
58          try:          try:
59              sw.write(os.path.join(WORKDIR,"test1.sgy"))              sw.write(os.path.join(WORKDIR,"test1.sgy"))
60          except Exception:          except Exception as e:
61              raise unittest.SkipTest("obspy may not be installed")              if str(e) == writeFailMessage:
62                    raise unittest.SkipTest("obspy not installed")
63                raise e
64                    
65      def test_segy_writer2(self):      def test_segy_writer2(self):
66          sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")          sw= SimpleSEGYWriter(receiver_group=[(0.,0.),(1.,-1.),(2.,-2)], source=(3,3), sampling_interval=10*U.msec, text="testing")
# Line 69  class TestSeismicTools(unittest.TestCase Line 71  class TestSeismicTools(unittest.TestCase
71             sw.addRecord(data)             sw.addRecord(data)
72          try:          try:
73              sw.write(os.path.join(WORKDIR,"test2.sgy"))              sw.write(os.path.join(WORKDIR,"test2.sgy"))
74          except Exception:          except Exception as e:
75              raise unittest.SkipTest("obspy may not be installed")              if str(e) == writeFailMessage:
76                    raise unittest.SkipTest("obspy not installed")
77                raise e
78                    
79      def test_ricker(self):      def test_ricker(self):
80          rw=Ricker(f_dom=40, t_dom=None)          rw=Ricker(f_dom=40, t_dom=None)
81    
82          self.assertTrue(abs(rw.getValue(0)) < 1e-6)          self.assertLess(abs(rw.getValue(0)), 1e-6)
83          self.assertAlmostEquals(rw.getValue(rw.getCenter()), 1. )          self.assertAlmostEquals(rw.getValue(rw.getCenter()), 1. )
84          self.assertTrue(abs(rw.getAcceleration(0.)) < 1.)          self.assertLess(abs(rw.getAcceleration(0.)), 1.)
85    
86      def test_wavebase(self):      def test_wavebase(self):
87          class TestWave(WaveBase):          class TestWave(WaveBase):
88              def _getAcceleration(self, t, u):              def _getAcceleration(self, t, u):
89                  return -sin(t)                  return -sin(t)
90            def check_values(self, tw, t_ref):
91                t, u=tw.update(t_ref)
92                self.assertLess(abs(t-t_ref), 1e-9)
93                self.assertLess(abs(u-sin(t_ref)), 1e-6)
94                
95          tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)          tw=TestWave(dt=0.001, u0=0., v0=1., t0=0.)
96          self.assertAlmostEquals(0.001, tw.getTimeStepSize())          self.assertAlmostEquals(0.001, tw.getTimeStepSize())
97            for t in [0.005, 0.007, 0.0071, 0.01, 0.02, 0.5]:
98          t_ref=0.005              check_values(self, tw, t)
99          t, u=tw.update(t_ref)          self.assertRaises(ValueError, tw.update, t-1)
100          self.assertTrue(abs(t-t_ref) < 1e-9)  
101          self.assertTrue(abs(u-sin(t_ref)) < 1e-6)      def sonicRunner(self, domain, label):
102                v_p=1.
103          t_ref=0.007              sw = SonicWave(domain, v_p, Ricker(0.5), source_tag='sss')
104          t, u=tw.update(t_ref)              u = sw.update(1.)[1]
105          self.assertTrue(abs(t-t_ref) < 1e-9)              self.assertIsInstance(u, Data,
106          self.assertTrue(abs(u-sin(t_ref)) < 1e-6)                      "u is not Data instance for %s"%label)
107                self.assertEqual(u.getShape(), (),
108          t_ref=0.0071                      "u is not shape () for %s"%label)
109          t, u=tw.update(t_ref)              self.assertEqual(u.getFunctionSpace(), Solution(domain),
110          self.assertTrue(abs(t-t_ref) < 1e-9)                      "functionspace != solution for %s"%label)
         self.assertTrue(abs(u-sin(t_ref)) < 1e-6)  
   
         t_ref=0.01  
         t, u=tw.update(t_ref)  
         self.assertTrue(abs(t-t_ref) < 1e-9)  
         self.assertTrue(abs(u-sin(t_ref)) < 1e-6)  
   
         t_ref=0.02  
         t, u=tw.update(t_ref)  
         self.assertTrue(abs(t-t_ref) < 1e-9)  
         self.assertTrue(abs(u-sin(t_ref)) < 1e-6)  
   
         t_ref=0.5  
         t, u=tw.update(t_ref)  
         self.assertTrue(abs(t-t_ref) < 1e-9)  
         self.assertTrue(abs(u-sin(t_ref)) < 1e-6)  
   
         self.assertRaises(ValueError, tw.update, t_ref-1)  
111    
112      def test_sonicwave2D(self):      def test_sonicwave2D(self):
113          from esys.finley import Rectangle          from esys.finley import Rectangle as fRect
114            from esys.ripley import Rectangle as rRect
115            for domType, impl in [(fRect, "finley"), (rRect, "ripley")]:
116                domain=domType(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])
117                self.sonicRunner(domain, "%s.Rectangle"%impl)
118    
         domain=Rectangle(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])  
         v_p=1.  
   
         sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')  
         u=sw.update(1.)[1]  
         self.assertTrue(isinstance(u,Data))  
         self.assertEqual(u.getShape(), ())  
         self.assertEqual(u.getFunctionSpace(), Solution(domain))  
   
         from esys.ripley import Rectangle  
   
         domain=Rectangle(5,5, diracPoints=[(0.5,1.)], diracTags=['sss'])  
         v_p=1.  
   
         sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')  
         u=sw.update(1.)[1]  
         self.assertTrue(isinstance(u,Data))  
         self.assertEqual(u.getShape(), ())  
         self.assertEqual(u.getFunctionSpace(), Solution(domain))  
           
119      def test_sonicwave3D(self):      def test_sonicwave3D(self):
120          from esys.finley import Brick          from esys.finley import Brick as fBrick
121            from esys.ripley import Brick as rBrick
122          domain=Brick(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])          for domType, impl in [(fBrick, "finley"), (rBrick, "ripley")]:
123          v_p=1.              domain=domType(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])
124                self.sonicRunner(domain, "%s.Brick"%impl)
         sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')  
         u=sw.update(1.)[1]  
         self.assertTrue(isinstance(u,Data))  
         self.assertEqual(u.getShape(), ())  
         self.assertEqual(u.getFunctionSpace(), Solution(domain))  
           
         from esys.ripley import Brick  
   
         domain=Brick(5,5,5, diracPoints=[(0.5,0.5,1.)], diracTags=['sss'])  
         v_p=1.  
   
         sw=SonicWave( domain, v_p, Ricker(0.5), source_tag='sss')  
         u=sw.update(1.)[1]  
         self.assertTrue(isinstance(u,Data))  
         self.assertEqual(u.getShape(), ())  
         self.assertEqual(u.getFunctionSpace(), Solution(domain))  
                   
125                                                                        
126  if __name__ == "__main__":  if __name__ == "__main__":
127      suite = unittest.TestSuite()      suite = unittest.TestSuite()

Legend:
Removed from v.4778  
changed lines
  Added in v.4782

  ViewVC Help
Powered by ViewVC 1.1.26