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 = readSEGY(file) # Set the largest possible delta value which should just work. segy[0].stats.delta = 0.065535 writeSEGY(segy, outfile) # Slightly larger should raise. segy[0].stats.delta = 0.065536 self.assertRaises(SEGYSampleIntervalError, writeSEGY, segy, outfile) # Same for SU. file = os.path.join(self.path, '1.su_first_trace') su = readSU(file) # Set the largest possible delta value which should just work. su[0].stats.delta = 0.065535 writeSU(su, outfile) # Slightly larger should raise. su[0].stats.delta = 0.065536 self.assertRaises(SEGYSampleIntervalError, writeSU, su, outfile)
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. """ outfile = NamedTemporaryFile().name # Test for SEG Y. file = os.path.join(self.path, '1.sgy_first_trace') segy = readSEGY(file) # Set the largest possible delta value which should just work. segy[0].stats.delta = 0.065535 writeSEGY(segy, outfile) os.remove(outfile) # Slightly larger should raise. segy[0].stats.delta = 0.065536 self.assertRaises(SEGYSampleIntervalError, writeSEGY, segy, outfile) # Same for SU. file = os.path.join(self.path, '1.su_first_trace') su = readSU(file) # Set the largest possible delta value which should just work. su[0].stats.delta = 0.065535 writeSU(su, outfile) os.remove(outfile) # Slightly larger should raise. su[0].stats.delta = 0.065536 self.assertRaises(SEGYSampleIntervalError, writeSU, su, outfile)
def test_writingStarttimeTimestamp0(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('>5h', date_time) self.assertEqual([ year == 2005, julday == 353, hour == 15, minute == 7, second == 54 ], 5 * [True]) # Read and set zero time. segy = readSEGY(file) segy[0].stats.starttime = UTCDateTime(0) outfile = NamedTemporaryFile().name writeSEGY(segy, outfile) # Check the new date. with open(outfile, 'rb') as f: f.seek(3600 + 156, 0) date_time = f.read(10) os.remove(outfile) year, julday, hour, minute, second = unpack('>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('<5h', date_time) self.assertEqual([ year == 2005, julday == 353, hour == 15, minute == 7, second == 54 ], 5 * [True]) # Read and set zero time. su = readSU(file) su[0].stats.starttime = UTCDateTime(0) outfile = NamedTemporaryFile().name writeSU(su, outfile) # Check the new date. with open(outfile, 'rb') as f: f.seek(156, 0) date_time = f.read(10) os.remove(outfile) year, julday, hour, minute, second = unpack('<5h', date_time) self.assertEqual( [year == 0, julday == 0, hour == 0, minute == 0, second == 0], 5 * [True])
def test_writingStarttimeTimestamp0(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('>5h', date_time) self.assertEqual([year == 2005, julday == 353, hour == 15, minute == 7, second == 54], 5 * [True]) # Read and set zero time. segy = readSEGY(file) segy[0].stats.starttime = UTCDateTime(0) with NamedTemporaryFile() as tf: outfile = tf.name writeSEGY(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('>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('<5h', date_time) self.assertEqual([year == 2005, julday == 353, hour == 15, minute == 7, second == 54], 5 * [True]) # Read and set zero time. su = readSU(file) su[0].stats.starttime = UTCDateTime(0) with NamedTemporaryFile() as tf: outfile = tf.name writeSU(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('<5h', date_time) self.assertEqual([year == 0, julday == 0, hour == 0, minute == 0, second == 0], 5 * [True])
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 = readSEGY(file) segy[0].stats.starttime = new_date writeSEGY(segy, outfile) segy_new = readSEGY(outfile) self.assertEqual(new_date, segy_new[0].stats.starttime) # Test for SU. file = os.path.join(self.path, '1.su_first_trace') su = readSU(file) su[0].stats.starttime = new_date writeSU(su, outfile) su_new = readSU(outfile) self.assertEqual(new_date, su_new[0].stats.starttime)
def su_specfem2d_obspy(d, prefix='SEM', channel=None, suffix='.su.adj'): """ Writes Seismic Unix file """ if channel in ['x']: file = '%s/Ux_file_single%s' % (prefix, suffix) elif channel in ['y']: file = '%s/Uy_file_single%s' % (prefix, suffix) elif channel in ['z']: file = '%s/Uz_file_single%s' % (prefix, suffix) elif channel in ['p']: file = '%s/Up_file_single%s' % (prefix, suffix) else: raise ValueError('CHANNEL must be one of the following: x y z p') max_delta = 0.065535 dummy_delta = max_delta if d[0].stats.delta > max_delta: for t in d: t.stats.delta = dummy_delta # write data to file from obspy.segy.core import writeSU writeSU(d, file)