def refresh(self): lines = [l for ax in self._fig.axes for l in ax.lines] axes = cycle(self._fig.get_axes(self.AXES_CLASS.name)) params = self.params['draw'] for i, channel in enumerate(self.channels): try: line = lines[i] except IndexError: # haven't plotted this channel before ax = next(axes) label = (hasattr(channel, 'label') and channel.label or channel.texname) pparams = {} for key in params: try: if params[key][i]: pparams[key] = params[key][i] except IndexError: pass ts = self.data[channel][0].copy() for t2 in self.data[channel][1:]: ts.append(t2, pad=self.buffer.pad, gap=self.buffer.gap) l = ax.plot(ts, label=label, **pparams) ax.legend() else: # TODO: remove .copy() as soon as copy=True is fixed in gwpy ts = TimeSeries(line.get_ydata(), times=line.get_xdata(), copy=True).copy() for t2 in self.buffer.get((ts.span[1], self.epoch), channel, fetch=False): ts.append(t2, pad=self.buffer.pad, gap=self.buffer.gap) line.set_xdata(ts.times.value) line.set_ydata(ts.value) # format figure if 'ylim' not in self.params['refresh']: for ax in self._fig.get_axes(self.AXES_CLASS.name): ax.relim() ax.autoscale_view(scalex=False) self.logger.info('Figure data updated') for ax in self._fig.get_axes(self.AXES_CLASS.name): if float(self.epoch) > (self.gpsstart + self.duration): ax.set_xlim(float(self.epoch - self.duration), float(self.epoch)) else: ax.set_xlim(float(self.gpsstart), float(self.gpsstart) + self.duration) ax.set_epoch(self.epoch) self.set_params('refresh') self._fig.refresh() self.logger.debug('Figure refreshed')
def refresh(self): lines = [l for ax in self._fig.axes for l in ax.lines] axes = cycle(self._fig.get_axes(self.AXES_CLASS.name)) params = self.params['draw'] for i, channel in enumerate(self.channels): try: line = lines[i] except IndexError: # haven't plotted this channel before ax = next(axes) label = (hasattr(channel, 'label') and channel.label or channel.texname) pparams = {} for key in params: try: if params[key][i]: pparams[key] = params[key][i] except IndexError: pass ts = self.data[channel][0].copy() for t2 in self.data[channel][1:]: ts.append(t2, pad=self.buffer.pad, gap=self.buffer.gap) l = ax.plot(ts, label=label, **pparams) ax.legend() else: # TODO: remove .copy() as soon as copy=True is fixed in gwpy ts = TimeSeries(line.get_ydata(), times=line.get_xdata(), copy=True).copy() for t2 in self.buffer.get((ts.span[1], self.epoch), channel, fetch=False): ts.append(t2, pad=self.buffer.pad, gap=self.buffer.gap) line.set_xdata(ts.times.value) line.set_ydata(ts.value) # format figure if 'ylim' not in self.params['refresh']: for ax in self._fig.get_axes(self.AXES_CLASS.name): ax.relim() ax.autoscale_view(scalex=False) self.logger.info('Figure data updated') for ax in self._fig.get_axes(self.AXES_CLASS.name): if float(self.epoch) > (self.gpsstart + self.duration): ax.set_xlim(float(self.epoch - self.duration), float(self.epoch)) else: ax.set_xlim(float(self.gpsstart), float(self.gpsstart) + self.duration) ax.set_epoch(self.epoch) self.set_params('refresh') self._fig.refresh() self.logger.debug('Figure refreshed')
def test_add_timeseries(self): a = TimeSeries([1, 2, 3, 4, 5], name='test name', epoch=0, sample_rate=1) # test simple add using 'name' data.add_timeseries(a) self.assertIn('test name', globalv.DATA) self.assertEqual(globalv.DATA['test name'], [a]) # test add using key kwarg data.add_timeseries(a, key='test key') self.assertIn('test key', globalv.DATA) self.assertEqual(globalv.DATA['test key'], [a]) # test add to existing key with coalesce b = TimeSeries([6, 7, 8, 9, 10], name='test name 2', epoch=5, sample_rate=1) data.add_timeseries(b, key='test key', coalesce=True) self.assertEqual(globalv.DATA['test key'], [a.append(b, inplace=False)])
def test_add_timeseries(self): a = TimeSeries([1, 2, 3, 4, 5], name='test name', epoch=0, sample_rate=1) # test simple add using 'name' data.add_timeseries(a) self.assertIn('test name', globalv.DATA) self.assertEqual(globalv.DATA['test name'], [a]) # test add using key kwarg data.add_timeseries(a, key='test key') self.assertIn('test key', globalv.DATA) self.assertEqual(globalv.DATA['test key'], [a]) # test add to existing key with coalesce b = TimeSeries([6, 7, 8, 9, 10], name='test name 2', epoch=5, sample_rate=1) data.add_timeseries(b, key='test key', coalesce=True) self.assertEqual(globalv.DATA['test key'], [a.append(b, inplace=False)])