示例#1
0
 def test_convert_date_time(self):
     """
     Tests all time conversion methods.
     """
     # These values are created using the Linux "date -u -d @TIMESTRING"
     # command. These values are assumed to be correct.
     timesdict = {
         1234567890: UTCDateTime(2009, 2, 13, 23, 31, 30),
         1111111111: UTCDateTime(2005, 3, 18, 1, 58, 31),
         1212121212: UTCDateTime(2008, 5, 30, 4, 20, 12),
         1313131313: UTCDateTime(2011, 8, 12, 6, 41, 53),
         100000: UTCDateTime(1970, 1, 2, 3, 46, 40),
         100000.111112: UTCDateTime(1970, 1, 2, 3, 46, 40, 111112),
         200000000: UTCDateTime(1976, 5, 3, 19, 33, 20),
         # test rounding of 7th digit of microseconds
         1388479508.871572: UTCDateTime(1388479508.8715718),
     }
     # Loop over timesdict.
     for ts, dt in timesdict.items():
         self.assertEqual(
             dt, util._convert_mstime_to_datetime(ts * 1000000))
         self.assertEqual(
             ts * 1000000, util._convert_datetime_to_mstime(dt))
     # Additional sanity tests.
     # Today.
     now = UTCDateTime()
     self.assertEqual(now, util._convert_mstime_to_datetime(
         util._convert_datetime_to_mstime(now)))
     # Some random date.
     random.seed(815)  # make test reproducible
     timestring = random.randint(0, 2000000) * 1e6
     self.assertEqual(timestring, util._convert_datetime_to_mstime(
         util._convert_mstime_to_datetime(timestring)))
示例#2
0
 def test_convert_date_time(self):
     """
     Tests all time conversion methods.
     """
     # These values are created using the Linux "date -u -d @TIMESTRING"
     # command. These values are assumed to be correct.
     timesdict = {
         1234567890: UTCDateTime(2009, 2, 13, 23, 31, 30),
         1111111111: UTCDateTime(2005, 3, 18, 1, 58, 31),
         1212121212: UTCDateTime(2008, 5, 30, 4, 20, 12),
         1313131313: UTCDateTime(2011, 8, 12, 6, 41, 53),
         100000: UTCDateTime(1970, 1, 2, 3, 46, 40),
         100000.111112: UTCDateTime(1970, 1, 2, 3, 46, 40, 111112),
         200000000: UTCDateTime(1976, 5, 3, 19, 33, 20),
         # test rounding of 7th digit of microseconds
         1388479508.871572: UTCDateTime(1388479508.8715718),
     }
     # Loop over timesdict.
     for ts, dt in timesdict.items():
         self.assertEqual(dt,
                          util._convert_mstime_to_datetime(ts * 1000000))
         self.assertEqual(ts * 1000000,
                          util._convert_datetime_to_mstime(dt))
     # Additional sanity tests.
     # Today.
     now = UTCDateTime()
     self.assertEqual(
         now,
         util._convert_mstime_to_datetime(
             util._convert_datetime_to_mstime(now)))
     # Some random date.
     random.seed(815)  # make test reproducible
     timestring = random.randint(0, 2000000) * 1e6
     self.assertEqual(
         timestring,
         util._convert_datetime_to_mstime(
             util._convert_mstime_to_datetime(timestring)))
示例#3
0
    def get_trace(self):

        if self.trace is not None:
            return self.trace

        msr, msrecord_py = self.get_ms_record()
        try:
            header = _convert_msr_to_dict(msrecord_py)

            # XXX Workaround: in Python 3 msrecord_py.sampletype is a byte
            # (e.g. b'i'), while keys of mseed.headers.SAMPLESIZES are
            # unicode ('i') (see above)
            sampletype = msrecord_py.sampletype
            if not isinstance(sampletype, str):
                sampletype = sampletype.decode()

            data = _ctypes_array_2_numpy_array(msrecord_py.datasamples,
                                               msrecord_py.numsamples,
                                               sampletype)
        finally:
            self.free_ms_record(msr, msrecord_py)

        # XXX Workaround: the fields in the returned struct of type
        # obspy.io.mseed.header.MsrecordS have byte values in Python 3, while
        # the rest of the code still expects them to be string (see #770)
        # -> convert
        convert = ('network', 'station', 'location', 'channel', 'dataquality',
                   'sampletype')
        for key, value in header.items():
            if key in convert and not isinstance(value, str):
                header[key] = value.decode()

        # 20111201 AJL - bug fix?
        header['starttime'] = _convert_mstime_to_datetime(header['starttime'])
        # 20111205 AJL - bug fix?
        if 'samprate' in header:
            header['sampling_rate'] = header['samprate']
            del header['samprate']
        # Access data directly as NumPy array.

        self.trace = Trace(data, header)
        return self.trace
示例#4
0
文件: slpacket.py 项目: Brtle/obspy
    def get_trace(self):

        if self.trace is not None:
            return self.trace

        msr, msrecord_py = self.get_ms_record()
        try:
            header = _convert_msr_to_dict(msrecord_py)

            # XXX Workaround: in Python 3 msrecord_py.sampletype is a byte
            # (e.g. b'i'), while keys of mseed.headers.SAMPLESIZES are
            # unicode ('i') (see above)
            sampletype = msrecord_py.sampletype
            if not isinstance(sampletype, str):
                sampletype = sampletype.decode()

            data = _ctypes_array_2_numpy_array(msrecord_py.datasamples,
                                               msrecord_py.numsamples,
                                               sampletype)
        finally:
            self.free_ms_record(msr, msrecord_py)

        # XXX Workaround: the fields in the returned struct of type
        # obspy.io.mseed.header.MsrecordS have byte values in Python 3, while
        # the rest of the code still expects them to be string (see #770)
        # -> convert
        convert = ('network', 'station', 'location', 'channel',
                   'dataquality', 'sampletype')
        for key, value in header.items():
            if key in convert and not isinstance(value, str):
                header[key] = value.decode()

        # 20111201 AJL - bug fix?
        header['starttime'] = _convert_mstime_to_datetime(header['starttime'])
        # 20111205 AJL - bug fix?
        if 'samprate' in header:
            header['sampling_rate'] = header['samprate']
            del header['samprate']
        # Access data directly as NumPy array.

        self.trace = Trace(data, header)
        return self.trace