def test_writeAndReadDifferentEncodings(self):
     """
     Writes and read a file with different encoding via the obspy.core
     methods.
     """
     npts = 1000
     np.random.seed(815)  # make test reproducable
     data = np.random.randn(npts).astype('float64') * 1e3 + .5
     st = Stream([Trace(data=data)])
     # Loop over some record lengths.
     for encoding, value in ENCODINGS.iteritems():
         seed_dtype = value[2]
         # Special handling for the ASCII dtype. NumPy 1.7 changes the
         # default dtype of numpy.string_ from "|S1" to "|S32". Enforce
         # "|S1|" here to be consistent across NumPy versions.
         if encoding == 0:
             seed_dtype = "|S1"
         with NamedTemporaryFile() as tf:
             tempfile = tf.name
             # Write it once with the encoding key and once with the value.
             st[0].data = data.astype(seed_dtype)
             st.verify()
             st.write(tempfile, format="MSEED", encoding=encoding)
             st2 = read(tempfile)
             del st2[0].stats.mseed
             np.testing.assert_array_equal(st[0].data, st2[0].data,
                 "Arrays are not equal for encoding '%s'" %
                 ENCODINGS[encoding][0])
             del st2
             ms = _MSStruct(tempfile)
             ms.read(-1, 1, 1, 0)
             self.assertEqual(ms.msr.contents.encoding, encoding)
             del ms  # for valgrind
 def test_writeAndReadDifferentEncodings(self):
     """
     Writes and read a file with different encoding via the obspy.core
     methods.
     """
     npts = 1000
     np.random.seed(815)  # make test reproducable
     data = np.random.randn(npts).astype('float64') * 1e3 + .5
     st = Stream([Trace(data=data)])
     # Loop over some record lengths.
     for encoding, value in ENCODINGS.iteritems():
         seed_dtype = value[2]
         tempfile = NamedTemporaryFile().name
         # Write it once with the encoding key and once with the value.
         st[0].data = data.astype(seed_dtype)
         st.verify()
         st.write(tempfile, format="MSEED", encoding=encoding)
         st2 = read(tempfile)
         del st2[0].stats.mseed
         np.testing.assert_array_equal(st[0].data, st2[0].data)
         del st2
         ms = _MSStruct(tempfile)
         ms.read(-1, 1, 1, 0)
         self.assertEqual(ms.msr.contents.encoding, encoding)
         del ms  # for valgrind
         os.remove(tempfile)
 def test_writeAndReadDifferentEncodings(self):
     """
     Writes and read a file with different encoding via the obspy.core
     methods.
     """
     npts = 1000
     np.random.seed(815)  # make test reproducable
     data = np.random.randn(npts).astype('float64') * 1e3 + .5
     st = Stream([Trace(data=data)])
     # Loop over some record lengths.
     for encoding, value in ENCODINGS.iteritems():
         seed_dtype = value[2]
         tempfile = NamedTemporaryFile().name
         # Write it once with the encoding key and once with the value.
         st[0].data = data.astype(seed_dtype)
         st.verify()
         st.write(tempfile, format="MSEED", encoding=encoding)
         st2 = read(tempfile)
         del st2[0].stats.mseed
         np.testing.assert_array_equal(st[0].data, st2[0].data)
         del st2
         ms = _MSStruct(tempfile)
         ms.read(-1, 1, 1, 0)
         self.assertEqual(ms.msr.contents.encoding, encoding)
         del ms  # for valgrind
         os.remove(tempfile)
 def test_getRecordInformation(self):
     """
     Tests the reading of Mini-SEED record information.
     """
     # Build encoding strings.
     encoding_strings = {}
     for key, value in ENCODINGS.iteritems():
         encoding_strings[value[0]] = key
     # Test the encodings and byteorders.
     path = os.path.join(self.path, "data", "encoding")
     files = ['float32_Float32_bigEndian.mseed',
              'float32_Float32_littleEndian.mseed',
              'float64_Float64_bigEndian.mseed',
              'float64_Float64_littleEndian.mseed',
              'fullASCII_bigEndian.mseed', 'fullASCII_littleEndian.mseed',
              'int16_INT16_bigEndian.mseed',
              'int16_INT16_littleEndian.mseed',
              'int32_INT32_bigEndian.mseed',
              'int32_INT32_littleEndian.mseed',
              'int32_Steim1_bigEndian.mseed',
              'int32_Steim1_littleEndian.mseed',
              'int32_Steim2_bigEndian.mseed',
              'int32_Steim2_littleEndian.mseed']
     for file in files:
         info = util.getRecordInformation(os.path.join(path, file))
         if not 'ASCII' in file:
             encoding = file.split('_')[1].upper()
             byteorder = file.split('_')[2].split('.')[0]
         else:
             encoding = 'ASCII'
             byteorder = file.split('_')[1].split('.')[0]
         if 'big' in byteorder:
             byteorder = '>'
         else:
             byteorder = '<'
         self.assertEqual(encoding_strings[encoding], info['encoding'])
         self.assertEqual(byteorder, info['byteorder'])
         # Also test the record length although it is equal for all files.
         self.assertEqual(256, info['record_length'])
     # No really good test files for the record length so just two files
     # with known record lengths are tested.
     info = util.getRecordInformation(os.path.join(self.path, 'data',
                                     'timingquality.mseed'))
     self.assertEqual(info['record_length'], 512)
     info = util.getRecordInformation(os.path.join(self.path, 'data',
                                      'steim2.mseed'))
     self.assertEqual(info['record_length'], 4096)