Exemple #1
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)
Exemple #2
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)
Exemple #3
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])
Exemple #4
0
 def test_issue_377(self):
     """
     Tests that _read_segy() and stream.write() should handle negative trace
     header values.
     """
     filename = os.path.join(self.path, 'one_trace_year_11.sgy')
     st = _read_segy(filename)
     st[0].stats.segy.trace_header['source_coordinate_x'] = -1
     st.stats.textual_file_header = \
         _patch_header(st.stats.textual_file_header)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         st.write(outfile, format='SEGY')
Exemple #5
0
 def test_issue_377(self):
     """
     Tests that _read_segy() and stream.write() should handle negative trace
     header values.
     """
     filename = os.path.join(self.path, 'one_trace_year_11.sgy')
     st = _read_segy(filename)
     st[0].stats.segy.trace_header['source_coordinate_x'] = -1
     st.stats.textual_file_header = \
         _patch_header(st.stats.textual_file_header)
     with NamedTemporaryFile() as tf:
         outfile = tf.name
         st.write(outfile, format='SEGY')
Exemple #6
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])
Exemple #7
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')
Exemple #8
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')
Exemple #9
0
 def test_writing_new_sampling_rate(self):
     """
     Setting a new sample rate works.
     """
     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)
     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)
Exemple #10
0
 def test_writing_new_sampling_rate(self):
     """
     Setting a new sample rate works.
     """
     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)
     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)