def retrieveData(self, length): data, times = super(PlotSink,self).retrieveData(length) if self.sri.mode or self._forceComplex: data2, times2 = super(PlotSink,self).retrieveData(length) data = bulkio_helpers.bulkioComplexToPythonComplexList(data + data2) times.extend(times2) return data, times
def _test_FileSource(self, format): filename = self._tempfileName('source_%s' % format) complexData = format.startswith('C') typecode = format[1] dataFormat, dataType = self.TYPEMAP[typecode] indata = self._generateSourceData(format, 16) hdr = bluefile.header(1000, format) bluefile.write(filename, hdr, indata) source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat) sink = sb.DataSink() source.connect(sink) sb.start() outdata = sink.getData(eos_block=True) if complexData: self.assertEqual(sink.sri().mode, 1) if dataFormat in ('float', 'double'): outdata = bulkio_helpers.bulkioComplexToPythonComplexList( outdata) else: outdata = numpy.reshape(outdata, (len(outdata) / 2, 2)) else: self.assertEqual(sink.sri().mode, 0) self.assertTrue(numpy.array_equal(indata, outdata), msg='%s != %s' % (indata, outdata))
def _test_FileSource(self, format): filename = self._tempfileName('source_%s' % format) complexData = format.startswith('C') typecode = format[1] dataFormat, dataType = self.TYPEMAP[typecode] indata = [dataType(x) for x in xrange(16)] if complexData: if dataFormat in ('float', 'double'): indata = [complex(x) for x in indata] else: indata = numpy.reshape(indata, (8,2)) hdr = bluefile.header(1000, format) bluefile.write(filename, hdr, indata) source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat) sink = sb.DataSink() source.connect(sink) sb.start() outdata = sink.getData(eos_block=True) if complexData: self.assertEqual(sink.sri().mode, 1) if dataFormat in ('float', 'double'): outdata = bulkio_helpers.bulkioComplexToPythonComplexList(outdata) else: outdata = numpy.reshape(outdata, (len(outdata)/2,2)) else: self.assertEqual(sink.sri().mode, 0) self.assertTrue(numpy.array_equal(indata, outdata), msg='%s != %s' % (indata, outdata))
def pushPacket(self, data, ts, EOS, stream_id): """ Pushes data to the file. Input: <data> The actual data to write to the file <ts> The timestamp <EOS> Flag indicating if this is the End Of the Stream <stream_id> The name of the file """ self.port_lock.acquire() if EOS: self.gotEOS = True self.eos_cond.notifyAll() else: self.gotEOS = False try: if self.header and self.header['format'][1] == 'B': # convert back from string to array of 8-bit integers data = numpy.fromstring(data, numpy.int8) # If complex data, need to convert data back from array of scalar values # to some form of complex values if self.header and self.header['format'][0] == 'C': # float and double are handled by numpy # each array element is a single complex value if self.header['format'][1] in ('F', 'D'): data = bulkio_helpers.bulkioComplexToPythonComplexList( data) # other data types are not handled by numpy # each element is two value array representing real and imaginary values else: # Need to rehape the data into complex value pairs data = numpy.reshape(data, (-1, 2)) bluefile.write(self.outFile, hdr=None, data=data, append=1) finally: self.port_lock.release()
def pushPacket(self, data, ts, EOS, stream_id): """ Pushes data to the file. Input: <data> The actual data to write to the file <ts> The timestamp <EOS> Flag indicating if this is the End Of the Stream <stream_id> The name of the file """ self.port_lock.acquire() if EOS: self.gotEOS = True self.eos_cond.notifyAll() else: self.gotEOS = False try: if self.header and self.header["format"][1] == "B": # convert back from string to array of 8-bit integers data = numpy.fromstring(data, numpy.int8) # If complex data, need to convert data back from array of scalar values # to some form of complex values if self.header and self.header["format"][0] == "C": # float and double are handled by numpy # each array element is a single complex value if self.header["format"][1] in ("F", "D"): data = bulkio_helpers.bulkioComplexToPythonComplexList(data) # other data types are not handled by numpy # each element is two value array representing real and imaginary values else: # Need to rehape the data into complex value pairs data = numpy.reshape(data, (-1, 2)) bluefile.write(self.outFile, hdr=None, data=data, append=1) finally: self.port_lock.release()
def pushPacket(self, data, ts, EOS, stream_id): """ Pushes data to the file. Input: <data> The actual data to write to the file <ts> The timestamp <EOS> Flag indicating if this is the End Of the Stream <stream_id> The name of the file """ self.port_lock.acquire() if EOS: self.gotEOS = True self.eos_cond.notifyAll() else: self.gotEOS = False try: # If the header doesn't already have meaningful timecode, update it # with the packet time and write it out to disk if self._firstPacket and self.header and ts.tcstatus == BULKIO.TCS_VALID: self.header['timecode'] = unix_to_j1950(ts.twsec + ts.tfsec) bluefile.writeheader(self.outFile, self.header) self._firstPacket = False if self.header and self.header['format'][1] == 'B': # convert back from string to array of 8-bit integers try: data = numpy.fromstring(data, numpy.int8) except TypeError: data = numpy.array(data, numpy.int8) # If complex data, need to convert data back from array of scalar values # to some form of complex values if self.header and self.header['format'][0] == 'C': # float and double are handled by numpy # each array element is a single complex value if self.header['format'][1] in ('F', 'D'): data = bulkio_helpers.bulkioComplexToPythonComplexList( data) # other data types are not handled by numpy # each element is two value array representing real and imaginary values # if data is also framed, wait to reshape everything at once elif self.header['subsize'] == 0: # Need to rehape the data into complex value pairs data = numpy.reshape(data, (-1, 2)) # If framed data, need to frame the data according to subsize if self.header and self.header['subsize'] != 0: # If scalar or single complex values, just frame it if self.header['format'][0] != 'C' or self.header['format'][ 1] in ('F', 'D'): data = numpy.reshape(data, (-1, int(self.header['subsize']))) # otherwise, frame and pair as complex values else: data = numpy.reshape(data, (-1, int(self.header['subsize']), 2)) bluefile.write(self.outFile, hdr=None, data=data, append=1) finally: self.port_lock.release()