示例#1
0
    def _bin_data(self, packet):
        key = "%s.%s.%s.%s" % (packet["net"], packet.get("location", ""), packet.get("sta", ""), packet["chan"])
        start, end = self._get_bin(packet)

        with self._lock:
            self._pktid = packet["pktid"]

            if key not in self._logs:
                self._logs[key] = PacketLog.from_packet(packet, end, self._param_dict.get(Parameter.REFDES))

            try:
                while True:
                    packet = self._logs[key].add_packet(packet)
                    if packet is None:
                        break
                    # residual, we need a new bin
                    # log is complete, move to holding list until next flush
                    self._filled_logs.append(self._logs[key])
                    del self._logs[key]
                    # create the new log...
                    start, end = self._get_bin(packet)
                    self._logs[key] = PacketLog.from_packet(packet, end, self._param_dict.get(Parameter.REFDES))

            except GapException:
                # non-contiguous data detected, close this log and open a new one
                self._filled_logs.append(self._logs[key])
                del self._logs[key]
                # create the new log
                self._logs[key] = PacketLog.from_packet(packet, end, self._param_dict.get(Parameter.REFDES))
                self._logs[key].add_packet(packet)
示例#2
0
    def _bin_data(self, packet):
        key = '%s.%s.%s.%s' % (packet['net'], packet.get('location', ''),
                               packet.get('sta', ''), packet['chan'])
        start, end = self._get_bin(packet)

        with self._lock:
            self._pktid = packet['pktid']

            if key not in self._logs:
                self._logs[key] = PacketLog.from_packet(packet, end)

            try:
                while True:
                    packet = self._logs[key].add_packet(packet)
                    if packet is None:
                        break
                    # residual, we need a new bin
                    # log is complete, move to holding list until next flush
                    self._filled_logs.append(self._logs[key])
                    del self._logs[key]
                    # create the new log...
                    start, end = self._get_bin(packet)
                    self._logs[key] = PacketLog.from_packet(packet, end)

            except GapException:
                # non-contiguous data detected, close this log and open a new one
                self._filled_logs.append(self._logs[key])
                del self._logs[key]
                # create the new log
                self._logs[key] = PacketLog.from_packet(packet, end)
                self._logs[key].add_packet(packet)
    def test_log_properties(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        PacketLog.base_dir = './antelope_data/refdes'
        log.create(*header_values)

        self.assertEqual(log.filename, './antelope_data/refdes/1970/01/01/OO.AXAS1.XX.EHE.1970-01-01T00:00:01.000000.mseed')
示例#4
0
    def test_log_properties(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        PacketLog.base_dir = './antelope_data'
        log.create(*header_values)

        self.assertEqual(log.absname, './antelope_data/antelope/refdes/1970/01/01/'
                                      'OO.AXAS1.XX.EHE.1970-01-01T00:00:01.000000.mseed')
示例#5
0
    def test_packet_range_exceptions(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        log.create(*header_values)

        log.add_packet(packet_values._asdict())

        with self.assertRaises(GapException):
            log.add_packet(early_packet_values._asdict())

        with self.assertRaises(GapException):
            log.add_packet(late_packet_values._asdict())
示例#6
0
    def test_packet_gap_exception(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        log.create(*header_values)

        log.add_packet(packet_values._asdict())

        with self.assertRaises(GapException):
            log.add_packet(gap_packet_values._asdict())
示例#7
0
    def test_log_add_packet(self):
        packet_log = PacketLog()
        packet_log.filehandle = BytesIO()
        packet_log.create(*header_values)

        packet_log.add_packet(packet_values._asdict())

        self.assertEqual(list(packet_log.data.get()), packet_values.data)
示例#8
0
    def test_log_flush(self):
        # here we'll mock the methods that actually write to disk
        # so we can test the flush interface without creating any files
        trace_write = 'obspy.core.trace.Trace.write'

        with mock.patch(trace_write, new_callable=mock.Mock) as mocked_write:
            packet_log = PacketLog()
            packet_log.filehandle = BytesIO()
            packet_log.create(*header_values)

            packet_log.add_packet(packet_values._asdict())
            # assert the record was updated
            self.assertEqual(packet_log.header.num_samples, 5)

            packet_log.flush()

            # assert Trace.write was called
            mocked_write.assert_called_once_with(packet_log.absname, format='MSEED')
示例#9
0
    def test_packet_overlap(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        log.create(*header_values)

        log.add_packet(packet_values._asdict())

        self.assertEqual(log.header.num_samples, 5)

        # fudge our num_samples value to avoid gap exception
        log.header.num_samples += 19775

        # add our overlapping data
        packet = log.add_packet(overlapping_packet_values._asdict())

        # assert that a packet containing 180 samples with a starttime of 100.0 is returned
        self.assertEqual(packet['nsamp'], 180)
        self.assertEqual(packet['time'], 100.0)

        # assert our container is full
        self.assertEqual(log.header.num_samples, 200 * 99)
        self.assertEqual(log.header.endtime, 100.0)
示例#10
0
 def test_log_create(self):
     log = PacketLog()
     log.filehandle = BytesIO()
     log.create(*header_values)
    def test_log_properties(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        log.create(*header_values)

        self.assertEqual(log.filename, 'OO.AXAS1.XX.EHE.1970-01-01T00:00:01.000000.mseed')
示例#12
0
    def test_packet_range_exceptions(self):
        log = PacketLog()
        log.filehandle = BytesIO()
        log.create(*header_values)

        log.add_packet(packet_values._asdict())

        with self.assertRaises(TimeRangeException):
            log.add_packet(early_packet_values._asdict())

        with self.assertRaises(TimeRangeException):
            log.add_packet(late_packet_values._asdict())