Example #1
0
 def test_write_slist_file_multiple_traces(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     testfile = os.path.join(self.path, 'data', 'slist_2_traces.ascii')
     stream_orig = _read_slist(testfile)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile)
         # look at the raw data
         with open(tmpfile, 'rt') as f:
             lines = f.readlines()
         self.assertTrue(lines[0].startswith('TIMESERIES'))
         self.assertIn('SLIST', lines[0])
         self.assertEqual(lines[1].strip(), '185\t181\t185\t189\t194\t205')
         # read again
         stream = _read_slist(tmpfile)
     stream.verify()
     # sort traces to ensure comparable results
     stream.sort()
     self.assertEqual(stream[0].stats.network, 'XX')
     self.assertEqual(stream[0].stats.station, 'TEST')
     self.assertEqual(stream[0].stats.location, '')
     self.assertEqual(stream[0].stats.channel, 'BHE')
     self.assertEqual(stream[0].stats.sampling_rate, 40.0)
     self.assertEqual(stream[0].stats.npts, 630)
     self.assertEqual(stream[0].stats.starttime,
                      UTCDateTime("2008-01-15T00:00:00.025000"))
     self.assertEqual(stream[0].stats.calib, 1.0e-00)
     self.assertEqual(stream[0].stats.mseed.dataquality, 'R')
     # check first 4 samples
     data = [185, 181, 185, 189]
     np.testing.assert_array_almost_equal(stream[0].data[0:4], data)
     # check last 4 samples
     data = [781, 785, 778, 772]
     np.testing.assert_array_almost_equal(stream[0].data[-4:], data)
     # second trace
     self.assertEqual(stream[1].stats.network, 'XX')
     self.assertEqual(stream[1].stats.station, 'TEST')
     self.assertEqual(stream[1].stats.location, '')
     self.assertEqual(stream[1].stats.channel, 'BHZ')
     self.assertEqual(stream[1].stats.sampling_rate, 40.0)
     self.assertEqual(stream[1].stats.npts, 635)
     self.assertEqual(stream[1].stats.starttime,
                      UTCDateTime("2008-01-15T00:00:00.025000"))
     self.assertEqual(stream[1].stats.calib, 1.0e-00)
     self.assertEqual(stream[0].stats.mseed.dataquality, 'R')
     # check first 4 samples
     data = [185, 181, 185, 189]
     np.testing.assert_array_almost_equal(stream[1].data[0:4], data)
     # check last 4 samples
     data = [761, 755, 748, 746]
     np.testing.assert_array_almost_equal(stream[1].data[-4:], data)
Example #2
0
 def test_write_slist_custom_fmt_float(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     # float
     testfile_orig = os.path.join(self.path, 'data', 'slist_float.ascii')
     testfile = os.path.join(self.path, 'data',
                             'slist_float_custom_fmt.ascii')
     stream_orig = _read_slist(testfile_orig)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile, custom_fmt='%3.14f')
         # look at the raw data
         with open(tmpfile, 'rt') as f:
             lines = f.readlines()
         self.assertEqual(
             lines[0].strip(),
             'TIMESERIES XX_TEST__BHZ_R, 12 samples, 40 sps, ' +
             '2008-01-15T00:00:00.025000, SLIST, FLOAT, Counts')
         self.assertEqual(
             lines[1].strip(), '185.00999450000000\t181.02000430000001\t' +
             '185.02999879999999\t189.03999329999999\t' +
             '194.05000310000000\t205.05999760000000')
         # read again
         stream = _read_slist(tmpfile)
         stream.verify()
         self.assertEqual(stream[0].stats.network, 'XX')
         self.assertEqual(stream[0].stats.station, 'TEST')
         self.assertEqual(stream[0].stats.location, '')
         self.assertEqual(stream[0].stats.channel, 'BHZ')
         self.assertEqual(stream[0].stats.sampling_rate, 40.0)
         self.assertEqual(stream[0].stats.npts, 12)
         self.assertEqual(stream[0].stats.starttime,
                          UTCDateTime("2008-01-15T00:00:00.025000"))
         self.assertEqual(stream[0].stats.calib, 1.0e-00)
         self.assertEqual(stream[0].stats.mseed.dataquality, 'R')
         data = [
             185.01, 181.02, 185.03, 189.04, 194.05, 205.06, 209.07, 214.08,
             222.09, 225.98, 226.99, 219.00
         ]
         np.testing.assert_array_almost_equal(stream[0].data,
                                              data,
                                              decimal=2)
         # compare raw header
         with open(testfile, 'rt') as f:
             lines_orig = f.readlines()
         with open(tmpfile, 'rt') as f:
             lines_new = f.readlines()
     self.assertEqual(lines_orig[0], lines_new[0])
Example #3
0
 def test_write_slist_custom_fmt_float(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     # float
     testfile_orig = os.path.join(self.path, 'data', 'slist_float.ascii')
     testfile = os.path.join(self.path, 'data',
                             'slist_float_custom_fmt.ascii')
     stream_orig = _read_slist(testfile_orig)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile, custom_fmt='%3.14f')
         # look at the raw data
         with open(tmpfile, 'rt') as f:
             lines = f.readlines()
         self.assertEqual(
             lines[0].strip(),
             'TIMESERIES XX_TEST__BHZ_R, 12 samples, 40 sps, ' +
             '2008-01-15T00:00:00.025000, SLIST, FLOAT, Counts')
         self.assertEqual(
             lines[1].strip(),
             '185.00999450000000\t181.02000430000001\t' +
             '185.02999879999999\t189.03999329999999\t' +
             '194.05000310000000\t205.05999760000000')
         # read again
         stream = _read_slist(tmpfile)
         stream.verify()
         self.assertEqual(stream[0].stats.network, 'XX')
         self.assertEqual(stream[0].stats.station, 'TEST')
         self.assertEqual(stream[0].stats.location, '')
         self.assertEqual(stream[0].stats.channel, 'BHZ')
         self.assertEqual(stream[0].stats.sampling_rate, 40.0)
         self.assertEqual(stream[0].stats.npts, 12)
         self.assertEqual(stream[0].stats.starttime,
                          UTCDateTime("2008-01-15T00:00:00.025000"))
         self.assertEqual(stream[0].stats.calib, 1.0e-00)
         self.assertEqual(stream[0].stats.mseed.dataquality, 'R')
         data = [185.01, 181.02, 185.03, 189.04, 194.05, 205.06,
                 209.07, 214.08, 222.09, 225.98, 226.99, 219.00]
         np.testing.assert_array_almost_equal(stream[0].data, data,
                                              decimal=2)
         # compare raw header
         with open(testfile, 'rt') as f:
             lines_orig = f.readlines()
         with open(tmpfile, 'rt') as f:
             lines_new = f.readlines()
     self.assertEqual(lines_orig[0], lines_new[0])
Example #4
0
 def test_write_slist(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     # float32
     testfile = os.path.join(self.path, "data", "slist_float.ascii")
     stream_orig = _read_slist(testfile)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile)
         # look at the raw data
         with open(tmpfile, "rt") as f:
             lines = f.readlines()
         self.assertEqual(
             lines[0].strip(),
             "TIMESERIES XX_TEST__BHZ_R, 12 samples, 40 sps, " + "2008-01-15T00:00:00.025000, SLIST, FLOAT, Counts",
         )
         self.assertEqual(
             lines[1].strip(), "185.009995\t181.020004\t185.029999\t189.039993\t" + "194.050003\t205.059998"
         )
         # read again
         stream = _read_slist(tmpfile)
         stream.verify()
         self.assertEqual(stream[0].stats.network, "XX")
         self.assertEqual(stream[0].stats.station, "TEST")
         self.assertEqual(stream[0].stats.location, "")
         self.assertEqual(stream[0].stats.channel, "BHZ")
         self.assertEqual(stream[0].stats.sampling_rate, 40.0)
         self.assertEqual(stream[0].stats.npts, 12)
         self.assertEqual(stream[0].stats.starttime, UTCDateTime("2008-01-15T00:00:00.025000"))
         self.assertEqual(stream[0].stats.calib, 1.0e-00)
         self.assertEqual(stream[0].stats.mseed.dataquality, "R")
         data = [185.01, 181.02, 185.03, 189.04, 194.05, 205.06, 209.07, 214.08, 222.09, 225.98, 226.99, 219.00]
         np.testing.assert_array_almost_equal(stream[0].data, data, decimal=2)
         # compare raw header
         with open(testfile, "rt") as f:
             lines_orig = f.readlines()
         with open(tmpfile, "rt") as f:
             lines_new = f.readlines()
     self.assertEqual(lines_orig[0], lines_new[0])
Example #5
0
 def test_write_slist_custom_fmt_custom(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     # float
     testfile_orig = os.path.join(self.path, 'data', 'slist_float.ascii')
     stream_orig = _read_slist(testfile_orig)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile, custom_fmt='%+r')
         self.assertRaises(NotImplementedError, _read_slist, tmpfile)
         # look at the raw data
         with open(tmpfile, 'rt') as f:
             lines = f.readlines()
         self.assertEqual(
             lines[0].strip(),
             'TIMESERIES XX_TEST__BHZ_R, 12 samples, 40 sps, ' +
             '2008-01-15T00:00:00.025000, SLIST, CUSTOM, Counts')
         self.assertEqual(
             lines[1].strip(), '185.0099945\t181.02000430000001\t' +
             '185.02999879999999\t189.03999329999999\t' +
             '194.0500031\t205.0599976')
Example #6
0
 def test_write_slist_custom_fmt_custom(self):
     """
     Write SLIST file test via obspy.core.ascii._write_tspair.
     """
     # float
     testfile_orig = os.path.join(self.path, 'data', 'slist_float.ascii')
     stream_orig = _read_slist(testfile_orig)
     with NamedTemporaryFile() as tf:
         tmpfile = tf.name
         # write
         _write_slist(stream_orig, tmpfile, custom_fmt='%+r')
         self.assertRaises(NotImplementedError, _read_slist, tmpfile)
         # look at the raw data
         with open(tmpfile, 'rt') as f:
             lines = f.readlines()
         self.assertEqual(
             lines[0].strip(),
             'TIMESERIES XX_TEST__BHZ_R, 12 samples, 40 sps, ' +
             '2008-01-15T00:00:00.025000, SLIST, CUSTOM, Counts')
         self.assertEqual(
             lines[1].strip(),
             '185.0099945\t181.02000430000001\t' +
             '185.02999879999999\t189.03999329999999\t' +
             '194.0500031\t205.0599976')