Exemplo n.º 1
0
 def test_TwoDigitYearsSU(self):
     """
     Same test as test_TwoDigitYearsSEGY just for Seismic Unix files.
     """
     # Read two artificial test files and check the years.
     filename = os.path.join(self.path, 'one_trace_year_11.su')
     st = _read_su(filename)
     self.assertEqual(2011, st[0].stats.starttime.year)
     filename = os.path.join(self.path, 'one_trace_year_99.su')
     st = _read_su(filename)
     self.assertEqual(1999, st[0].stats.starttime.year)
Exemplo n.º 2
0
 def test_two_digit_years_su(self):
     """
     Same test as test_TwoDigitYearsSEGY just for Seismic Unix files.
     """
     # Read two artificial test files and check the years.
     filename = os.path.join(self.path, 'one_trace_year_11.su')
     st = _read_su(filename)
     self.assertEqual(2011, st[0].stats.starttime.year)
     filename = os.path.join(self.path, 'one_trace_year_99.su')
     st = _read_su(filename)
     self.assertEqual(1999, st[0].stats.starttime.year)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 8
0
 def test_read_head_only(self):
     """
     Tests headonly flag on _read_segy and _read_su functions.
     """
     # _read_segy
     file = os.path.join(self.path, '1.sgy_first_trace')
     st = _read_segy(file, headonly=True)
     self.assertEqual(st[0].stats.npts, 8000)
     self.assertEqual(len(st[0].data), 0)
     # _read_su
     file = os.path.join(self.path, '1.su_first_trace')
     st = _read_su(file, headonly=True)
     self.assertEqual(st[0].stats.npts, 8000)
     self.assertEqual(len(st[0].data), 0)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def test_reading_date(self):
     """
     Reads one file with a set date. The date has been read with SeisView 2
     by the DMNG.
     """
     # Date as read by SeisView 2.
     date = UTCDateTime(year=2005, julday=353, hour=15, minute=7, second=54)
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     self.assertEqual(date, segy[0].stats.starttime)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     su = _read_su(file)
     self.assertEqual(date, su[0].stats.starttime)
Exemplo n.º 11
0
 def test_setting_delta_and_sampling_rate_in_stats(self):
     """
     Just checks if the delta and sampling rate attributes are correctly
     set.
     Testing the delta value is enough because the stats attribute takes
     care that delta/sampling rate always match.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     self.assertEqual(segy[0].stats.delta, 250E-6)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     su = _read_su(file)
     self.assertEqual(su[0].stats.delta, 250E-6)
Exemplo n.º 12
0
 def test_readHeadOnly(self):
     """
     Tests headonly flag on _read_segy and _read_su functions.
     """
     # _read_segy
     file = os.path.join(self.path, '1.sgy_first_trace')
     st = _read_segy(file, headonly=True)
     self.assertEqual(st[0].stats.npts, 8000)
     self.assertEqual(len(st[0].data), 0)
     # _read_su
     file = os.path.join(self.path, '1.su_first_trace')
     st = _read_su(file, headonly=True)
     self.assertEqual(st[0].stats.npts, 8000)
     self.assertEqual(len(st[0].data), 0)
Exemplo n.º 13
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)
Exemplo n.º 14
0
 def test_readingDate(self):
     """
     Reads one file with a set date. The date has been read with SeisView 2
     by the DMNG.
     """
     # Date as read by SeisView 2.
     date = UTCDateTime(year=2005, julday=353, hour=15, minute=7, second=54)
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     self.assertEqual(date, segy[0].stats.starttime)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     su = _read_su(file)
     self.assertEqual(date, su[0].stats.starttime)
Exemplo n.º 15
0
 def test_settingDeltaandSamplingRateinStats(self):
     """
     Just checks if the delta and sampling rate attributes are correctly
     set.
     Testing the delta value is enough because the stats attribute takes
     care that delta/sampling rate always match.
     """
     file = os.path.join(self.path, '1.sgy_first_trace')
     segy = _read_segy(file)
     self.assertEqual(segy[0].stats.delta, 250E-6)
     # The same with the Seismic Unix file.
     file = os.path.join(self.path, '1.su_first_trace')
     su = _read_su(file)
     self.assertEqual(su[0].stats.delta, 250E-6)
Exemplo n.º 16
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])