Пример #1
0
 def test_writing_using_core(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.io.segy.tests.test_segy.
     """
     for file, _ in self.files.items():
         file = os.path.join(self.path, file)
         # Read the file with the internal SEGY representation.
         segy_file = _read_segy_internal(file)
         # Read again using core.
         st = _read_segy(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 and catch header warnings
                 with WarningsCapture():
                     warnings.simplefilter("ignore")
                     segy_file.write(out_file1)
                     _write_segy(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])
Пример #2
0
 def test_writing_using_core(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.io.segy.tests.test_segy.
     """
     for file, _ in self.files.items():
         file = os.path.join(self.path, file)
         # Read the file with the internal SEGY representation.
         segy_file = _read_segy_internal(file)
         # Read again using core.
         st = _read_segy(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 and catch header warnings
                 with warnings.catch_warnings(record=True):
                     segy_file.write(out_file1)
                     _write_segy(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])
Пример #3
0
 def test_reading_using_core(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.io.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.items():
         file = os.path.join(self.path, file)
         # Read the file with the internal SEGY representation.
         segy_file = _read_segy_internal(file)
         # Read again using core.
         st = _read_segy(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__.items():
             self.assertEqual(getattr(st.stats.binary_file_header,
                              key), value)
         for key, value in \
                 segy_file.traces[0].header.__dict__.items():
             self.assertEqual(getattr(st[0].stats.segy.trace_header, key),
                              value)
Пример #4
0
 def test_reading_using_core(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.io.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.items():
         file = os.path.join(self.path, file)
         # Read the file with the internal SEGY representation.
         segy_file = _read_segy_internal(file)
         # Read again using core.
         st = _read_segy(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__.items():
             self.assertEqual(getattr(st.stats.binary_file_header,
                              key), value)
         for key, value in \
                 segy_file.traces[0].header.__dict__.items():
             self.assertEqual(getattr(st[0].stats.segy.trace_header, key),
                              value)