Пример #1
0
 def test_reading_and_writing_different_data_encodings(self):
     """
     Writes and reads different data encodings and checks if the data
     remains the same.
     """
     # The file uses IBM data encoding.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st = _read_segy(file)
     data = st[0].data
     # All working encodings with corresponding dtypes.
     encodings = {1: np.float32, 2: np.int32, 3: np.int16, 5: np.float32}
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         # Loop over all encodings.
         for data_encoding, dtype in encodings.items():
             this_data = np.require(data.copy(), dtype)
             st[0].data = this_data
             _write_segy(st, out_file, data_encoding=data_encoding)
             # Read again and compare data.
             this_stream = _read_segy(out_file)
             # Both should now be equal. Usually converting from IBM to IEEE
             # floating point numbers might result in small rounding errors
             # but in this case it seems to work. Might be different on
             # different computers.
             np.testing.assert_array_equal(this_data, this_stream[0].data)
Пример #2
0
 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.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_segyInternal(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.
                 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_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])
Пример #4
0
 def test_readingAndWritingDifferentDataEncodings(self):
     """
     Writes and reads different data encodings and checks if the data
     remains the same.
     """
     # The file uses IBM data encoding.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st = _read_segy(file)
     data = st[0].data
     # All working encodings with corresponding dtypes.
     encodings = {1: np.float32,
                  2: np.int32,
                  3: np.int16,
                  5: np.float32}
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         # Loop over all encodings.
         for data_encoding, dtype in encodings.items():
             this_data = np.require(data.copy(), dtype)
             st[0].data = this_data
             _write_segy(st, out_file, data_encoding=data_encoding)
             # Read again and compare data.
             this_stream = _read_segy(out_file)
             # Both should now be equal. Usually converting from IBM to IEEE
             # floating point numbers might result in small rounding errors
             # but in this case it seems to work. Might be different on
             # different computers.
             np.testing.assert_array_equal(this_data, this_stream[0].data)
Пример #5
0
 def test_large_sample_rate_interval_raises(self):
     """
     SEG Y supports a sample interval from 1 to 65535 microseconds in steps
     of 1 microsecond. Larger intervals cannot be supported due to the
     definition of the SEG Y format. Therefore the smallest possible
     sampling rate is ~ 15.26 Hz.
     """
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # Test for SEG Y.
         file = os.path.join(self.path, '1.sgy_first_trace')
         segy = _read_segy(file)
         segy.stats.textual_file_header = \
             _patch_header(segy.stats.textual_file_header)
         # Set the largest possible delta value which should just work.
         segy[0].stats.delta = 0.065535
         _write_segy(segy, outfile)
         # Slightly larger should raise.
         segy[0].stats.delta = 0.065536
         self.assertRaises(SEGYSampleIntervalError, _write_segy, segy,
                           outfile)
         # Same for SU.
         file = os.path.join(self.path, '1.su_first_trace')
         su = _read_su(file)
         # Set the largest possible delta value which should just work.
         su[0].stats.delta = 0.065535
         _write_su(su, outfile)
     # Slightly larger should raise.
     su[0].stats.delta = 0.065536
     self.assertRaises(SEGYSampleIntervalError, _write_su, su, outfile)
Пример #6
0
 def test_largeSampleRateIntervalRaises(self):
     """
     SEG Y supports a sample interval from 1 to 65535 microseconds in steps
     of 1 microsecond. Larger intervals cannot be supported due to the
     definition of the SEG Y format. Therefore the smallest possible
     sampling rate is ~ 15.26 Hz.
     """
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # Test for SEG Y.
         file = os.path.join(self.path, '1.sgy_first_trace')
         segy = _read_segy(file)
         # Set the largest possible delta value which should just work.
         segy[0].stats.delta = 0.065535
         _write_segy(segy, outfile)
         # Slightly larger should raise.
         segy[0].stats.delta = 0.065536
         self.assertRaises(SEGYSampleIntervalError, _write_segy, segy,
                           outfile)
         # Same for SU.
         file = os.path.join(self.path, '1.su_first_trace')
         su = _read_su(file)
         # Set the largest possible delta value which should just work.
         su[0].stats.delta = 0.065535
         _write_su(su, outfile)
     # Slightly larger should raise.
     su[0].stats.delta = 0.065536
     self.assertRaises(SEGYSampleIntervalError, _write_su, su, outfile)
Пример #7
0
 def test_writing_starttime_timestamp_0(self):
     """
     If the starttime of the Trace is UTCDateTime(0) it will be interpreted
     as a missing starttime is not written. Test if this holds True.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     # This file has a set date!
     with open(file, 'rb') as f:
         f.seek(3600 + 156, 0)
         date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'>5h', date_time)
     self.assertEqual([
         year == 2005, julday == 353, hour == 15, minute == 7, second == 54
     ], 5 * [True])
     # Read and set zero time.
     segy = _read_segy(file)
     segy.stats.textual_file_header = \
         _patch_header(segy.stats.textual_file_header)
     segy[0].stats.starttime = UTCDateTime(0)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_segy(segy, outfile)
         # Check the new date.
         with open(outfile, 'rb') as f:
             f.seek(3600 + 156, 0)
             date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'>5h', date_time)
     self.assertEqual(
         [year == 0, julday == 0, hour == 0, minute == 0, second == 0],
         5 * [True])
     # The same for SU.
     file = os.path.join(self.path, '1.su_first_trace')
     # This file has a set date!
     with open(file, 'rb') as f:
         f.seek(156, 0)
         date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'<5h', date_time)
     self.assertEqual([
         year == 2005, julday == 353, hour == 15, minute == 7, second == 54
     ], 5 * [True])
     # Read and set zero time.
     su = _read_su(file)
     su[0].stats.starttime = UTCDateTime(0)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_su(su, outfile)
         # Check the new date.
         with open(outfile, 'rb') as f:
             f.seek(156, 0)
             date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'<5h', date_time)
     self.assertEqual(
         [year == 0, julday == 0, hour == 0, minute == 0, second == 0],
         5 * [True])
Пример #8
0
 def test_writing_starttime_timestamp_0(self):
     """
     If the starttime of the Trace is UTCDateTime(0) it will be interpreted
     as a missing starttime is not written. Test if this holds True.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     # This file has a set date!
     with open(file, 'rb') as f:
         f.seek(3600 + 156, 0)
         date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'>5h', date_time)
     self.assertEqual([year == 2005, julday == 353, hour == 15, minute == 7,
                       second == 54], 5 * [True])
     # Read and set zero time.
     segy = _read_segy(file)
     segy.stats.textual_file_header = \
         _patch_header(segy.stats.textual_file_header)
     segy[0].stats.starttime = UTCDateTime(0)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_segy(segy, outfile)
         # Check the new date.
         with open(outfile, 'rb') as f:
             f.seek(3600 + 156, 0)
             date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'>5h', date_time)
     self.assertEqual([year == 0, julday == 0, hour == 0, minute == 0,
                       second == 0], 5 * [True])
     # The same for SU.
     file = os.path.join(self.path, '1.su_first_trace')
     # This file has a set date!
     with open(file, 'rb') as f:
         f.seek(156, 0)
         date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'<5h', date_time)
     self.assertEqual([year == 2005, julday == 353, hour == 15, minute == 7,
                       second == 54], 5 * [True])
     # Read and set zero time.
     su = _read_su(file)
     su[0].stats.starttime = UTCDateTime(0)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_su(su, outfile)
         # Check the new date.
         with open(outfile, 'rb') as f:
             f.seek(156, 0)
             date_time = f.read(10)
     year, julday, hour, minute, second = unpack(b'<5h', date_time)
     self.assertEqual([year == 0, julday == 0, hour == 0, minute == 0,
                       second == 0], 5 * [True])
Пример #9
0
 def test_writingNewSamplingRate(self):
     """
     Setting a new sample rate works.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     segy[0].stats.sampling_rate = 20
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_segy(segy, outfile)
         new_segy = _read_segy(outfile)
     self.assertEqual(new_segy[0].stats.sampling_rate, 20)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     _read_su(file)
Пример #10
0
 def test_writingNewSamplingRate(self):
     """
     Setting a new sample rate works.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     segy[0].stats.sampling_rate = 20
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         _write_segy(segy, outfile)
         new_segy = _read_segy(outfile)
     self.assertEqual(new_segy[0].stats.sampling_rate, 20)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     _read_su(file)
Пример #11
0
 def test_writing_too_long_trace(self):
     """
     Test nice exception message when trying to write a too long trace
     (#1393)
     """
     x = np.arange(32768, dtype=np.int32)
     tr = Trace(x)
     tr.stats.sampling_rate = 100
     st = Stream([tr])
     bio = io.BytesIO()
     with self.assertRaises(ValueError) as e:
         _write_segy(st, bio, data_encoding=2)
     self.assertEqual(
         str(e.exception),
         "Can not write traces with more than 32767 samples (trace at "
         "index 0):\n... | 1970-01-01T00:00:00.000000Z - "
         "1970-01-01T00:05:27.670000Z | 100.0 Hz, 32768 samples")
Пример #12
0
 def test_settingDataEncodingWorks(self):
     """
     Test whether or not the enforcing the data encoding works.
     """
     # File ld0042_file_00018.sgy_first_trace uses IBM floating point
     # representation.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st = _read_segy(file)
     # First test if it even works.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st, out_file)
         with open(out_file, 'rb') as f:
             data1 = f.read()
         # Write again and enforce encoding one which should yield the same
         # result.
         _write_segy(st, out_file, data_encoding=1)
         with open(out_file, 'rb') as f:
             data2 = f.read()
         self.assertTrue(data1 == data2)
         # Writing IEEE floats which should not require any dtype changes.
         _write_segy(st, out_file, data_encoding=5)
         with open(out_file, 'rb') as f:
             data3 = f.read()
         self.assertFalse(data1 == data3)
Пример #13
0
 def test_setting_data_encoding_works(self):
     """
     Test whether or not the enforcing the data encoding works.
     """
     # File ld0042_file_00018.sgy_first_trace uses IBM floating point
     # representation.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st = _read_segy(file)
     # First test if it even works.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st, out_file)
         with open(out_file, 'rb') as f:
             data1 = f.read()
         # Write again and enforce encoding one which should yield the same
         # result.
         _write_segy(st, out_file, data_encoding=1)
         with open(out_file, 'rb') as f:
             data2 = f.read()
         self.assertEqual(data1, data2)
         # Writing IEEE floats which should not require any dtype changes.
         _write_segy(st, out_file, data_encoding=5)
         with open(out_file, 'rb') as f:
             data3 = f.read()
         self.assertFalse(data1 == data3)
Пример #14
0
 def test_writing_modified_date(self):
     """
     Tests if the date in Trace.stats.starttime is correctly written in SU
     and SEGY files.
     """
     # Define new date!
     new_date = UTCDateTime(2010, 7, 7, 2, 2, 2)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # Test for SEGY.
         file = os.path.join(self.path, 'example.y_first_trace')
         segy = _read_segy(file)
         segy[0].stats.starttime = new_date
         _write_segy(segy, outfile)
         segy_new = _read_segy(outfile)
         self.assertEqual(new_date, segy_new[0].stats.starttime)
         # Test for SU.
         file = os.path.join(self.path, '1.su_first_trace')
         su = _read_su(file)
         su[0].stats.starttime = new_date
         _write_su(su, outfile)
         su_new = _read_su(outfile)
     self.assertEqual(new_date, su_new[0].stats.starttime)
Пример #15
0
 def test_writingModifiedDate(self):
     """
     Tests if the date in Trace.stats.starttime is correctly written in SU
     and SEGY files.
     """
     # Define new date!
     new_date = UTCDateTime(2010, 7, 7, 2, 2, 2)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         # Test for SEGY.
         file = os.path.join(self.path, 'example.y_first_trace')
         segy = _read_segy(file)
         segy[0].stats.starttime = new_date
         _write_segy(segy, outfile)
         segy_new = _read_segy(outfile)
         self.assertEqual(new_date, segy_new[0].stats.starttime)
         # Test for SU.
         file = os.path.join(self.path, '1.su_first_trace')
         su = _read_su(file)
         su[0].stats.starttime = new_date
         _write_su(su, outfile)
         su_new = _read_su(outfile)
     self.assertEqual(new_date, su_new[0].stats.starttime)
Пример #16
0
    def test_enforcing_textual_header_encoding_while_writing(self):
        """
        Tests whether or not the enforcing of the endianness while writing
        works.
        """
        # File ld0042_file_00018.sgy_first_trace has an EBCDIC encoding.
        file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
        st1 = _read_segy(file)
        # Save the header to compare it later on.
        with open(file, 'rb') as f:
            header = f.read(3200)

        # All newly written header will have the file revision number and
        # the end header mark set - just also set them in the old header.
        header = _patch_header(header, ebcdic=True)

        # First write should remain EBCDIC.
        with NamedTemporaryFile() as tf:
            out_file = tf.name
            _write_segy(st1, out_file)
            st2 = _read_segy(out_file)
            # Compare header.
            with open(out_file, 'rb') as f:
                new_header = f.read(3200)
        # re-encode both to ASCII to easily compare them.
        self.assertEqual(
            header.decode("EBCDIC-CP-BE").encode("ASCII"),
            new_header.decode("EBCDIC-CP-BE").encode("ASCII"))
        self.assertEqual(st2.stats.textual_file_header_encoding,
                         'EBCDIC')
        # Do once again to enforce EBCDIC.
        _write_segy(st1, out_file, textual_header_encoding='EBCDIC')
        st3 = _read_segy(out_file)
        # Compare header.
        with open(out_file, 'rb') as f:
            new_header = f.read(3200)
        self.assertEqual(header, new_header)
        os.remove(out_file)
        self.assertEqual(st3.stats.textual_file_header_encoding,
                         'EBCDIC')
        # Enforce ASCII
        _write_segy(st1, out_file, textual_header_encoding='ASCII')
        st4 = _read_segy(out_file)
        # Compare header. Should not be equal this time.
        with open(out_file, 'rb') as f:
            new_header = f.read(3200)
        self.assertFalse(header == new_header)
        os.remove(out_file)
        self.assertEqual(st4.stats.textual_file_header_encoding,
                         'ASCII')
Пример #17
0
    def test_enforcing_textual_header_encoding_while_writing(self):
        """
        Tests whether or not the enforcing of the endianness while writing
        works.
        """
        # File ld0042_file_00018.sgy_first_trace has an EBCDIC encoding.
        file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
        st1 = _read_segy(file)
        # Save the header to compare it later on.
        with open(file, 'rb') as f:
            header = f.read(3200)

        # All newly written header will have the file revision number and
        # the end header mark set - just also set them in the old header.
        header = _patch_header(header, ebcdic=True)

        # First write should remain EBCDIC.
        with NamedTemporaryFile() as tf:
            out_file = tf.name
            _write_segy(st1, out_file)
            st2 = _read_segy(out_file)
            # Compare header.
            with open(out_file, 'rb') as f:
                new_header = f.read(3200)
        # re-encode both to ASCII to easily compare them.
        self.assertEqual(
            header.decode("EBCDIC-CP-BE").encode("ASCII"),
            new_header.decode("EBCDIC-CP-BE").encode("ASCII"))
        self.assertEqual(st2.stats.textual_file_header_encoding,
                         'EBCDIC')
        # Do once again to enforce EBCDIC.
        _write_segy(st1, out_file, textual_header_encoding='EBCDIC')
        st3 = _read_segy(out_file)
        # Compare header.
        with open(out_file, 'rb') as f:
            new_header = f.read(3200)
        self.assertEqual(header, new_header)
        os.remove(out_file)
        self.assertEqual(st3.stats.textual_file_header_encoding,
                         'EBCDIC')
        # Enforce ASCII
        _write_segy(st1, out_file, textual_header_encoding='ASCII')
        st4 = _read_segy(out_file)
        # Compare header. Should not be equal this time.
        with open(out_file, 'rb') as f:
            new_header = f.read(3200)
        self.assertFalse(header == new_header)
        os.remove(out_file)
        self.assertEqual(st4.stats.textual_file_header_encoding,
                         'ASCII')
Пример #18
0
 def test_enforcingTextualHeaderEncodingWhileWriting(self):
     """
     Tests whether or not the enforcing of the endianness while writing
     works.
     """
     # File ld0042_file_00018.sgy_first_trace has an EBCDIC encoding.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st1 = _read_segy(file)
     # Save the header to compare it later on.
     with open(file, 'rb') as f:
         header = f.read(3200)
     # First write should remain EBCDIC.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st1, out_file)
         st2 = _read_segy(out_file)
         # Compare header.
         with open(out_file, 'rb') as f:
             new_header = f.read(3200)
     self.assertTrue(header == new_header)
     self.assertEqual(st2.stats.textual_file_header_encoding,
                      'EBCDIC')
     # Do once again to enforce EBCDIC.
     _write_segy(st1, out_file, textual_header_encoding='EBCDIC')
     st3 = _read_segy(out_file)
     # Compare header.
     with open(out_file, 'rb') as f:
         new_header = f.read(3200)
     self.assertTrue(header == new_header)
     os.remove(out_file)
     self.assertEqual(st3.stats.textual_file_header_encoding,
                      'EBCDIC')
     # Enforce ASCII
     _write_segy(st1, out_file, textual_header_encoding='ASCII')
     st4 = _read_segy(out_file)
     # Compare header. Should not be equal this time.
     with open(out_file, 'rb') as f:
         new_header = f.read(3200)
     self.assertFalse(header == new_header)
     os.remove(out_file)
     self.assertEqual(st4.stats.textual_file_header_encoding,
                      'ASCII')
Пример #19
0
 def test_enforcing_textual_header_encoding_while_writing(self):
     """
     Tests whether or not the enforcing of the endianness while writing
     works.
     """
     # File ld0042_file_00018.sgy_first_trace has an EBCDIC encoding.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st1 = _read_segy(file)
     # Save the header to compare it later on.
     with open(file, 'rb') as f:
         header = f.read(3200)
     # First write should remain EBCDIC.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st1, out_file)
         st2 = _read_segy(out_file)
         # Compare header.
         with open(out_file, 'rb') as f:
             new_header = f.read(3200)
     self.assertEqual(header, new_header)
     self.assertEqual(st2.stats.textual_file_header_encoding,
                      'EBCDIC')
     # Do once again to enforce EBCDIC.
     _write_segy(st1, out_file, textual_header_encoding='EBCDIC')
     st3 = _read_segy(out_file)
     # Compare header.
     with open(out_file, 'rb') as f:
         new_header = f.read(3200)
     self.assertEqual(header, new_header)
     os.remove(out_file)
     self.assertEqual(st3.stats.textual_file_header_encoding,
                      'EBCDIC')
     # Enforce ASCII
     _write_segy(st1, out_file, textual_header_encoding='ASCII')
     st4 = _read_segy(out_file)
     # Compare header. Should not be equal this time.
     with open(out_file, 'rb') as f:
         new_header = f.read(3200)
     self.assertFalse(header == new_header)
     os.remove(out_file)
     self.assertEqual(st4.stats.textual_file_header_encoding,
                      'ASCII')
Пример #20
0
 def test_enforcingEndiannessWhileWriting(self):
     """
     Tests whether or not the enforcing of the endianness while writing
     works.
     """
     # File ld0042_file_00018.sgy_first_trace is in big endian.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st1 = _read_segy(file)
     # First write should be big endian.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st1, out_file)
         st2 = _read_segy(out_file)
         self.assertEqual(st2.stats.endian, '>')
         # Do once again to enforce big endian.
         _write_segy(st1, out_file, byteorder='>')
         st3 = _read_segy(out_file)
         self.assertEqual(st3.stats.endian, '>')
         # Enforce little endian.
         _write_segy(st1, out_file, byteorder='<')
         st4 = _read_segy(out_file)
         self.assertEqual(st4.stats.endian, '<')
Пример #21
0
 def test_enforcing_endianness_while_writing(self):
     """
     Tests whether or not the enforcing of the endianness while writing
     works.
     """
     # File ld0042_file_00018.sgy_first_trace is in big endian.
     file = os.path.join(self.path, 'ld0042_file_00018.sgy_first_trace')
     st1 = _read_segy(file)
     # First write should be big endian.
     with NamedTemporaryFile() as tf:
         out_file = tf.name
         _write_segy(st1, out_file)
         st2 = _read_segy(out_file)
         self.assertEqual(st2.stats.endian, '>')
         # Do once again to enforce big endian.
         _write_segy(st1, out_file, byteorder='>')
         st3 = _read_segy(out_file)
         self.assertEqual(st3.stats.endian, '>')
         # Enforce little endian.
         _write_segy(st1, out_file, byteorder='<')
         st4 = _read_segy(out_file)
         self.assertEqual(st4.stats.endian, '<')