def test_writingUsingCore(self): """ Tests the writing of SEGY rev1 files using obspy.core. It just compares the output of writing using obspy.core with the output of writing the files using the internal SEGY object which is thoroughly tested in obspy.segy.tests.test_segy. """ for file, _ in self.files.iteritems(): file = os.path.join(self.path, file) # Read the file with the internal SEGY representation. segy_file = readSEGYInternal(file) # Read again using core. st = readSEGY(file) # Create two temporary files to write to. with NamedTemporaryFile() as tf1: out_file1 = tf1.name with NamedTemporaryFile() as tf2: out_file2 = tf2.name # Write twice. segy_file.write(out_file1) writeSEGY(st, out_file2) # Read and delete files. with open(out_file1, 'rb') as f1: data1 = f1.read() with open(out_file2, 'rb') as f2: data2 = f2.read() # Test if they are equal. self.assertEqual(data1[3200:3600], data2[3200:3600])
def test_readingUsingCore(self): """ This tests checks whether or not all necessary information is read during reading with core. It actually just assumes the internal SEGYFile object, which is thoroughly tested in obspy.segy.tests.test_segy, is correct and compared all values to it. This seems to be the easiest way to test everything. """ for file, _ in self.files.iteritems(): file = os.path.join(self.path, file) # Read the file with the internal SEGY representation. segy_file = readSEGYInternal(file) # Read again using core. st = readSEGY(file) # They all should have length one because all additional traces # have been removed. self.assertEqual(len(st), 1) # Assert the data is the same. np.testing.assert_array_equal(segy_file.traces[0].data, st[0].data) # Textual header. self.assertEqual(segy_file.textual_file_header, st.stats.textual_file_header) # Textual_header_encoding. self.assertEqual(segy_file.textual_header_encoding, st.stats.textual_file_header_encoding) # Endianness. self.assertEqual(segy_file.endian, st.stats.endian) # Data encoding. self.assertEqual(segy_file.data_encoding, st.stats.data_encoding) # Test the file and trace binary headers. for key, value in segy_file.binary_file_header.__dict__.iteritems(): self.assertEqual(getattr(st.stats.binary_file_header, key), value) for key, value in segy_file.traces[0].header.__dict__.iteritems(): self.assertEqual(getattr(st[0].stats.segy.trace_header, key), value)
def test_writingUsingCore(self): """ Tests the writing of SEGY rev1 files using obspy.core. It just compares the output of writing using obspy.core with the output of writing the files using the internal SEGY object which is thoroughly tested in obspy.segy.tests.test_segy. """ for file, _ in self.files.iteritems(): file = os.path.join(self.path, file) # Read the file with the internal SEGY representation. segy_file = readSEGYInternal(file) # Read again using core. st = readSEGY(file) # Create two temporary files to write to. out_file1 = NamedTemporaryFile().name out_file2 = NamedTemporaryFile().name # Write twice. segy_file.write(out_file1) writeSEGY(st, out_file2) # Read and delete files. with open(out_file1, 'rb') as f1: data1 = f1.read() with open(out_file2, 'rb') as f2: data2 = f2.read() os.remove(out_file1) os.remove(out_file2) # Test if they are equal. self.assertEqual(data1[3200:3600], data2[3200:3600])
def test_readingUsingCore(self): """ This tests checks whether or not all necessary information is read during reading with core. It actually just assumes the internal SEGYFile object, which is thoroughly tested in obspy.segy.tests.test_segy, is correct and compared all values to it. This seems to be the easiest way to test everything. """ for file, _ in self.files.iteritems(): file = os.path.join(self.path, file) # Read the file with the internal SEGY representation. segy_file = readSEGYInternal(file) # Read again using core. st = readSEGY(file) # They all should have length one because all additional traces # have been removed. self.assertEqual(len(st), 1) # Assert the data is the same. np.testing.assert_array_equal(segy_file.traces[0].data, st[0].data) # Textual header. self.assertEqual(segy_file.textual_file_header, st.stats.textual_file_header) # Textual_header_encoding. self.assertEqual(segy_file.textual_header_encoding, st.stats.textual_file_header_encoding) # Endianness. self.assertEqual(segy_file.endian, st.stats.endian) # Data encoding. self.assertEqual(segy_file.data_encoding, st.stats.data_encoding) # Test the file and trace binary headers. for key, value in \ segy_file.binary_file_header.__dict__.iteritems(): self.assertEqual(getattr(st.stats.binary_file_header, key), value) for key, value in \ segy_file.traces[0].header.__dict__.iteritems(): self.assertEqual(getattr(st[0].stats.segy.trace_header, key), value)