Ejemplo n.º 1
0
 def test_readWriteXY(self):
     """
     Tests for ascii sac io
     """
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         tfile = os.path.join(os.path.dirname(__file__), 'data', 'test.sac')
         with open(tfile, "rb") as fh:
             t = SacIO(fh)
         with open(tempfile, "wb") as fh:
             t.write_sac_xy(fh)
         with open(tempfile, "rb") as fh:
             d = SacIO(fh, alpha=True)
         e = SacIO()
         with open(tempfile, "rb") as fh:
             e.read_sac_xy(fh)
         self.assertEqual(e.get_header_value('npts'),
                          d.get_header_value('npts'))
         with open(tempfile, "rb") as fh:
             self.assertEqual(e.is_valid_xy_sac_file(fh), True)
         with open(tempfile, "rb") as fh:
             self.assertEqual(e.is_valid_sac_file(fh), False)
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         with open(tempfile, "wb") as fh:
             d.write_sac_binary(fh)
         size1 = os.stat(tempfile)[6]
         size2 = os.stat(tfile)[6]
     self.assertEqual(size1, size2)
     np.testing.assert_array_almost_equal(t.seis, d.seis, decimal=5)
Ejemplo n.º 2
0
 def test_readWriteXY(self):
     """
     Tests for ascii sac io
     """
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         tfile = os.path.join(os.path.dirname(__file__), 'data', 'test.sac')
         with open(tfile, "rb") as fh:
             t = SacIO(fh)
         with open(tempfile, "wb") as fh:
             t.write_sac_xy(fh)
         with open(tempfile, "rb") as fh:
             d = SacIO(fh, alpha=True)
         e = SacIO()
         with open(tempfile, "rb") as fh:
             e.read_sac_xy(fh)
         self.assertEqual(e.get_header_value('npts'),
                          d.get_header_value('npts'))
         with open(tempfile, "rb") as fh:
             self.assertEqual(e.is_valid_xy_sac_file(fh), True)
         with open(tempfile, "rb") as fh:
             self.assertEqual(e.is_valid_sac_file(fh), False)
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         with open(tempfile, "wb") as fh:
             d.write_sac_binary(fh)
         size1 = os.stat(tempfile)[6]
         size2 = os.stat(tfile)[6]
     self.assertEqual(size1, size2)
     np.testing.assert_array_almost_equal(t.seis, d.seis, decimal=5)
Ejemplo n.º 3
0
 def test_readXYheader(self):
     tfile = os.path.join(os.path.dirname(__file__), 'data', 'test.sac')
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         with open(tfile, "rb") as fh:
             t = SacIO(fh)
         with open(tempfile, 'wb') as fh:
             t.write_sac_xy(fh)
         with open(tempfile, "rb") as fh:
             d = SacIO(fh, alpha=True)
         e = SacIO()
         with open(tempfile, "rb") as fh:
             e.read_sac_xy_header(fh)
         self.assertEqual(e.get_header_value('npts'),
                          d.get_header_value('npts'))
         self.assertEqual(e.get_header_value('depmen'),
                          d.get_header_value('depmen'))
         self.assertEqual(e.starttime, d.starttime)
         self.assertNotEqual(e.seis.size, d.seis.size)
         with open(tempfile, "rb") as fh:
             c = SacIO(fh, alpha=True, headonly=True)
     self.assertEqual(e.seis.size, c.seis.size)
Ejemplo n.º 4
0
 def test_readXYheader(self):
     tfile = os.path.join(os.path.dirname(__file__), 'data', 'test.sac')
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         with open(tfile, "rb") as fh:
             t = SacIO(fh)
         with open(tempfile, 'wb') as fh:
             t.write_sac_xy(fh)
         with open(tempfile, "rb") as fh:
             d = SacIO(fh, alpha=True)
         e = SacIO()
         with open(tempfile, "rb") as fh:
             e.read_sac_xy_header(fh)
         self.assertEqual(e.get_header_value('npts'),
                          d.get_header_value('npts'))
         self.assertEqual(e.get_header_value('depmen'),
                          d.get_header_value('depmen'))
         self.assertEqual(e.starttime, d.starttime)
         self.assertNotEqual(e.seis.size, d.seis.size)
         with open(tempfile, "rb") as fh:
             c = SacIO(fh, alpha=True, headonly=True)
     self.assertEqual(e.seis.size, c.seis.size)