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_readWrite(self):
     """
     Tests for SacIO read and write
     """
     sacfile = os.path.join(self.path, 'test.sac')
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         t = SacIO()
         with open(sacfile, "rb") as fh:
             t.read_sac_file(fh)
         self.assertEqual(t.get_header_value('npts'), 100)
         self.assertEqual(t.get_header_value("kcmpnm"), "Q       ")
         self.assertEqual(t.get_header_value("kstnm"), "STA     ")
         t.set_header_value("kstnm", "spiff")
         self.assertEqual(t.get_header_value('kstnm'), 'spiff   ')
         with open(tempfile, "wb") as fh:
             t.write_sac_binary(fh)
         self.assertEqual(os.stat(sacfile)[6], os.stat(tempfile)[6])
         self.assertEqual(os.path.exists(tempfile), True)
         with open(tempfile, "rb") as fh:
             t.read_sac_header(fh)
         self.assertEqual((t.hf is not None), True)
         t.set_header_value("kstnm", "spoff")
         self.assertEqual(t.get_header_value('kstnm'), 'spoff   ')
         # Open with modification!
         with open(tempfile, "rb+") as fh:
             t.write_sac_header(fh)
         t.set_header_value_in_file(tempfile, "kcmpnm", 'Z       ')
         self.assertEqual(t.get_header_value_from_file(tempfile, "kcmpnm"),
                          'Z       ')
         with open(tempfile, "rb") as fh:
             self.assertEqual(
                 SacIO(fh, headonly=True).get_header_value('kcmpnm'),
                 'Z       ')
         with open(tempfile, "rb") as fh:
             self.assertEqual(t.is_valid_sac_file(fh), True)
         self.assertEqual(t.is_valid_xy_sac_file(tempfile), False)
         self.assertEqual(
             SacIO().get_header_value_from_file(sacfile, 'npts'), 100)
         with open(sacfile, "rb") as fh:
             self.assertEqual(SacIO(fh).get_header_value('npts'), 100)
Ejemplo n.º 4
0
 def test_readWrite(self):
     """
     Tests for SacIO read and write
     """
     sacfile = os.path.join(self.path, 'test.sac')
     with NamedTemporaryFile() as tf:
         tempfile = tf.name
         t = SacIO()
         with open(sacfile, "rb") as fh:
             t.read_sac_file(fh)
         self.assertEqual(t.get_header_value('npts'), 100)
         self.assertEqual(t.get_header_value("kcmpnm"), "Q       ")
         self.assertEqual(t.get_header_value("kstnm"), "STA     ")
         t.set_header_value("kstnm", "spiff")
         self.assertEqual(t.get_header_value('kstnm'), 'spiff   ')
         with open(tempfile, "wb") as fh:
             t.write_sac_binary(fh)
         self.assertEqual(os.stat(sacfile)[6], os.stat(tempfile)[6])
         self.assertEqual(os.path.exists(tempfile), True)
         with open(tempfile, "rb") as fh:
             t.read_sac_header(fh)
         self.assertEqual((t.hf is not None), True)
         t.set_header_value("kstnm", "spoff")
         self.assertEqual(t.get_header_value('kstnm'), 'spoff   ')
         # Open with modification!
         with open(tempfile, "rb+") as fh:
             t.write_sac_header(fh)
         t.set_header_value_in_file(tempfile, "kcmpnm", 'Z       ')
         self.assertEqual(t.get_header_value_from_file(tempfile, "kcmpnm"),
                          'Z       ')
         with open(tempfile, "rb") as fh:
             self.assertEqual(
                 SacIO(fh, headonly=True).get_header_value('kcmpnm'),
                 'Z       ')
         with open(tempfile, "rb") as fh:
             self.assertEqual(t.is_valid_sac_file(fh), True)
         self.assertEqual(t.is_valid_xy_sac_file(tempfile), False)
         self.assertEqual(
             SacIO().get_header_value_from_file(sacfile, 'npts'), 100)
         with open(sacfile, "rb") as fh:
             self.assertEqual(SacIO(fh).get_header_value('npts'), 100)