Пример #1
0
    def __init__(
        self,
        server_url: str = None,
        buffer: Union[Stream, Buffer] = None,
        buffer_capacity: float = 600.,
    ) -> None:
        self.server_url = server_url
        if buffer is None:
            buffer = Buffer(traces=[], maxlen=buffer_capacity)
        elif isinstance(buffer, Stream):
            buffer = Buffer(buffer.traces, maxlen=buffer_capacity)
        self._buffer = buffer
        self.buffer_capacity = buffer_capacity

        # Queues for communication

        # Outgoing data
        self._stream_queue = Queue(maxsize=1)
        # Incoming data - no limit on size, just empty it!
        self._incoming_queue = Queue()

        # Quereyable attributes to get a view of the size of the buffer
        self._last_data_queue = Queue(maxsize=1)
        self._buffer_full_queue = Queue(maxsize=1)

        # Poison!
        self._killer_queue = Queue(maxsize=1)
        self._dead_queue = Queue(maxsize=1)

        # Private attributes for properties
        self.__stream = Stream()
        self.__last_data = None
        self.__buffer_full = False

        self.processes = []
Пример #2
0
 def test_reset_maxlen(self) -> None:
     buffer = Buffer(traces=self.st.traces)
     self.assertEqual(buffer.maxlen, 30.)
     buffer.maxlen = 20.
     self.assertEqual(buffer.maxlen, 20.)
     for tr in buffer:
         self.assertEqual(len(tr), 20. * tr.stats.sampling_rate)
Пример #3
0
 def test_addition(self) -> None:
     buffer = Buffer(traces=self.st1, maxlen=30.)
     self.assertEqual(buffer.stream.split(), self.st1)
     buffer.add_stream(self.st2)
     buffer_stream = buffer.stream
     for tr in buffer_stream:
         tr.stats.pop("processing")
     self.assertEqual(buffer_stream, self.st)
Пример #4
0
 def test_add_buffer(self):
     buffer1 = Buffer(traces=self.st1, maxlen=30.)
     buffer2 = Buffer(traces=self.st2, maxlen=25.)
     buffer3 = buffer1 + buffer2
     self.assertEqual(buffer1.stream.split(), self.st1)
     self.assertEqual(buffer2.stream.split(), self.st2)
     buffer_stream = buffer3.stream
     for tr in buffer_stream:
         tr.stats.pop("processing")
     self.assertEqual(buffer_stream, self.st)
Пример #5
0
 def test_add_new_trace(self):
     buffer = Buffer(self.st)
     new_trace = self.st[0].copy()
     new_trace.stats.station = "NOOB"
     buffer.add_stream(new_trace)
     self.assertEqual(len(buffer), 4)
     buffer_stream = buffer.stream
     self.assertEqual(buffer_stream.select(station="NOOB")[0], new_trace)
     for tr in buffer_stream:
         if tr.stats.station == "NOOB":
             continue
         else:
             self.assertEqual(tr, self.st.select(id=tr.id)[0])
Пример #6
0
 def test_init_with_trace_buffer(self):
     buffer = Buffer(traces=[
         TraceBuffer(data=tr.data, header=tr.stats, maxlen=tr.stats.npts)
         for tr in self.st
     ],
                     maxlen=30.)
     self.assertEqual(buffer.stream, self.st)
Пример #7
0
 def __init__(
     self,
     client_name: str = None,
     buffer: Union[Stream, Buffer] = None,
     buffer_capacity: float = 600.,
     wavebank: WaveBank = None,
 ) -> None:
     self.client_name = client_name
     if buffer is None:
         buffer = Buffer(traces=[], maxlen=buffer_capacity)
     elif isinstance(buffer, Stream):
         buffer = Buffer(buffer.traces, maxlen=buffer_capacity)
     self._buffer = buffer
     self.buffer_capacity = buffer_capacity
     self.wavebank = wavebank
     self.threads = []
Пример #8
0
 def test_full(self):
     buffer = Buffer(traces=self.st1, maxlen=30.)
     self.assertFalse(buffer.is_full())
     buffer += self.st2
     self.assertTrue(buffer.is_full())
Пример #9
0
 def test_failed_init(self):
     with self.assertRaises(AssertionError):
         Buffer(["a"])
Пример #10
0
 def test_buffer_init_with_traces_maxlen(self) -> None:
     buffer = Buffer(traces=self.st.traces, maxlen=20.)
     self.assertEqual(buffer.maxlen, 20.)
     for tr in buffer:
         self.assertEqual(len(tr), 20. * tr.stats.sampling_rate)
Пример #11
0
 def test_buffer_init_with_stream(self) -> None:
     buffer = Buffer(traces=self.st)
     self.assertEqual(buffer.maxlen, 30.)
Пример #12
0
 def clear_buffer(self):
     """ Clear the current buffer. """
     self._buffer = Buffer(traces=[], maxlen=self.buffer_capacity)
Пример #13
0
 def clear_buffer(self):
     """Clear the current buffer. Cannot be accessed outside the process."""
     with self.lock:
         self._buffer = Buffer(traces=[], maxlen=self.buffer_capacity)