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 complex data, need to convert data back from array of scalar values # to some form of complex values if self.header != None 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] == 'F' or self.header['format'][ 1] == 'D': real = data[0:len(data):2] imag = data[1:len(data):2] tmp = multiply(imag, 1.0j).tolist() data = add(real, tmp).tolist() # other data types are not handled by numpy # each element is two value array representing real and imaginary values elif self.header['format'][1] == 'I' or self.header['format'][ 1] == 'L': if arch == "x86_64": # Need to rehape the data into complex value pairs # numpy reshape is used to avoid 64-bit error data = reshape(data, (-1, 2)) # Need to convert numpy array to Numeric array which bluefile.write() is expecting data = Numeric.array(data) else: data = Numeric.reshape(data, (-1, 2)) elif self.header['format'][1] == 'B': # convert back from string to array of 8-bit integers data = Numeric.fromstring(data, Numeric.Int8) if arch == "x86_64": # Need to rehape the data into complex value pairs # numpy reshape is used to avoid 64-bit error data = reshape(data, (-1, 2)) # Need to convert numpy array to Numeric array which bluefile.write() is expecting data = Numeric.array(data) else: data = Numeric.reshape(data, (-1, 2)) elif self.header != None and self.header['format'] == "SB": data = Numeric.fromstring(data, Numeric.Int8) 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 complex data, need to convert data back from array of scalar values # to some form of complex values if self.header != None 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] == 'F' or self.header['format'][1] == 'D': real = data[0:len(data):2] imag = data[1:len(data):2] tmp = multiply(imag,1.0j).tolist() data = add(real,tmp).tolist() # other data types are not handled by numpy # each element is two value array representing real and imaginary values elif self.header['format'][1] == 'I' or self.header['format'][1] == 'L': if arch == "x86_64": # Need to rehape the data into complex value pairs # numpy reshape is used to avoid 64-bit error data= reshape(data,(-1,2)) # Need to convert numpy array to Numeric array which bluefile.write() is expecting data = Numeric.array(data) else: data= Numeric.reshape(data,(-1,2)) elif self.header['format'][1] == 'B': # convert back from string to array of 8-bit integers data = Numeric.fromstring(data,Numeric.Int8) if arch == "x86_64": # Need to rehape the data into complex value pairs # numpy reshape is used to avoid 64-bit error data= reshape(data,(-1,2)) # Need to convert numpy array to Numeric array which bluefile.write() is expecting data = Numeric.array(data) else: data= Numeric.reshape(data,(-1,2)) elif self.header != None and self.header['format'] == "SB": data = Numeric.fromstring(data,Numeric.Int8) 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 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()
first_samp += step last_samp = first_samp + fftsize print len(frames), len(frames[0]), len(frames[-1]) return hdr, frames if __name__ == '__main__': from optparse import OptionParser parser = OptionParser() parser.add_option('-l', '--log', action='store_true', dest='log_scale', default=False, help='Convert to log scale') parser.add_option('-f', '--fftsize', action='store', dest='fftsize', default=2048, type='int', help='fft size to use') parser.add_option('-o', '--overlap', action='store', dest='overlap', default=0.0, type='float', help='overlap') options, args = parser.parse_args() if len(args) < 2: print 'Must pass input and output filenames on command line' sys.exit(-1) fname = args[0] outname = args[1] success, samprate, data = read_simple_wave(fname) if not success: sys.exit(-1) print 'samprate: %s' % samprate hdr, frames = spectrogram(samprate, data, log_scale=options.log_scale, fftsize=options.fftsize, overlap=options.overlap) bluefile.write(outname, hdr=hdr, data=frames)
# hdr['head_rep']="EEEI" # hdr['data_rep']="EEEI" return hdr if __name__ == "__main__": xfile = 480 yfile = 480 file_format = "SP" filename = "mydata_%s_%s_%s" % (file_format, xfile, yfile) blue = True if blue: bluefile.set_type2000_format(np.ndarray) filename = filename + ".tmp" hdr = make_midas_header(xfile, yfile, file_format) data = make_2d_data_np(xfile, yfile, file_format) print("len data", len(data), len(data[0]), type(data), type(data[0])) bluefile.write(filename, hdr, data) else: data = make_2d_data(xfile, yfile, file_format) f = open(filename, "a+") for datalist in data: # time.sleep(0.1) binarydata = pack_list(datalist, file_format) f.write(binarydata) f.close()