コード例 #1
0
ファイル: test_su.py プロジェクト: jmfee-usgs/obspy
 def test_reading_and_writing_different_byteorders(self):
     """
     Writing different byte orders should not change
     """
     # This file is little endian.
     file = os.path.join(self.path, "1.su_first_trace")
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # The following should both work.
         su = _read_su(file)
         data = su.traces[0].data
         # Also read the original file.
         with open(file, "rb") as f:
             org_data = f.read()
         self.assertEqual(su.endian, "<")
         # Write it little endian.
         su.write(outfile, endian="<")
         with open(outfile, "rb") as f:
             new_data = f.read()
         self.assertEqual(org_data, new_data)
         su2 = _read_su(outfile)
         self.assertEqual(su2.endian, "<")
         np.testing.assert_array_equal(data, su2.traces[0].data)
         # Write it big endian.
         su.write(outfile, endian=">")
         with open(outfile, "rb") as f:
             new_data = f.read()
         self.assertFalse(org_data == new_data)
         su3 = _read_su(outfile)
     self.assertEqual(su3.endian, ">")
     np.testing.assert_array_equal(data, su3.traces[0].data)
コード例 #2
0
ファイル: test_su.py プロジェクト: jmfee-usgs/obspy
 def test_enforcing_byteorders_while_reading(self):
     """
     Tests whether or not enforcing the byte order while reading and writing
     does something and works at all. Using the wrong byte order will most
     likely raise an Exception.
     """
     # This file is little endian.
     file = os.path.join(self.path, "1.su_first_trace")
     # The following should both work.
     su = _read_su(file)
     self.assertEqual(su.endian, "<")
     su = _read_su(file, endian="<")
     self.assertEqual(su.endian, "<")
     # The following not because it will unpack the header and try to unpack
     # the number of data samples specified there which will of course not
     # correct.
     self.assertRaises(SEGYTraceReadingError, _read_su, file, endian=">")
コード例 #3
0
ファイル: test_su.py プロジェクト: jmfee-usgs/obspy
 def test_read_bytes_io(self):
     """
     Tests reading from BytesIO instances.
     """
     # 1
     filename = os.path.join(self.path, "1.su_first_trace")
     with open(filename, "rb") as fp:
         data = fp.read()
     st = _read_su(io.BytesIO(data))
     self.assertEqual(len(st.traces[0].data), 8000)
コード例 #4
0
ファイル: test_su.py プロジェクト: jmfee-usgs/obspy
 def test_unpacking_su_data(self):
     """
     Unpacks data and compares them to data unpacked by Madagascar.
     """
     # This file has the same data as 1.sgy_first_trace.
     file = os.path.join(self.path, "1.su_first_trace")
     data_file = os.path.join(self.path, "1.sgy_first_trace.npy")
     su = _read_su(file)
     data = su.traces[0].data
     # The data is written as integer so it is also converted to float32.
     correct_data = np.require(np.load(data_file).ravel(), np.float32)
     # Compare both.
     np.testing.assert_array_equal(correct_data, data)
コード例 #5
0
ファイル: test_su.py プロジェクト: jmfee-usgs/obspy
 def test_read_and_write_su(self):
     """
     Reading and writing a SU file should not change it.
     """
     file = os.path.join(self.path, "1.su_first_trace")
     # Read the original file once.
     with open(file, "rb") as f:
         org_data = f.read()
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # Read the SU file.
         su = _read_su(file)
         # Write it.
         su.write(outfile)
         with open(outfile, "rb") as f:
             new_data = f.read()
     # Should be identical!
     self.assertEqual(org_data, new_data)