def __init__(self, iring, buffer_key, gulp_nframe, space=None, *args, **kwargs): super(PsrDadaSinkBlock, self).__init__(iring, gulp_nframe, *args, **kwargs) self.hdu = Hdu() self.hdu.connect_write(buffer_key) self.keywords_to_add = {} self.keywords_to_sub = [] self.keywords_to_change = {}
def __init__(self, iring, buffer_key, gulp_nframe, space=None, *args, **kwargs): super(PsrDadaSinkBlock, self).__init__(iring, gulp_nframe, *args, **kwargs) self.hdu = Hdu() self.hdu.connect_write(buffer_key)
def psrdada_read_sequence_iterator(buffer_key, single=False): hdu = Hdu() hdu.connect_read(buffer_key) for hdr in hdu.header_block: with hdr: hdr_string = hdr.data.tostring() yield hdu, hdr_string if single: hdu.disconnect() break hdu.disconnect()
class PsrDadaSinkBlock(SinkBlock): def __init__(self, iring, buffer_key, gulp_nframe, space=None, *args, **kwargs): super(PsrDadaSinkBlock, self).__init__(iring, gulp_nframe, *args, **kwargs) self.hdu = Hdu() self.hdu.connect_write(buffer_key) def on_sequence(self, iseq): dada_header_str = generate_dada_header(iseq.header) dada_header_buf = next(self.hdu.header_block) dada_header_buf.data[:] = np.fromstring( dada_header_str.encode('ascii'), dtype='uint8') dada_header_buf.close() def on_sequence_end(self, iseq): self.hdu.disconnect() def on_data(self, ispan): # TODO: Make this work in CUDA space dada_blk = next(self.hdu.data_block) nbyte = ispan.data.nbytes _check( _bf.bfMemcpy(dada_blk.ptr, _bf.BF_SPACE_SYSTEM, ispan.data.ctypes.data, _bf.BF_SPACE_SYSTEM, nbyte)) #dada_blk.data[:] = ispan.data.view('u8') dada_blk.close()
class PsrDadaSinkBlock(SinkBlock): def __init__(self, iring, buffer_key, gulp_nframe, space=None, *args, **kwargs): super(PsrDadaSinkBlock, self).__init__(iring, gulp_nframe, *args, **kwargs) self.hdu = Hdu() self.hdu.connect_write(buffer_key) self.keywords_to_add = {} self.keywords_to_sub = [] self.keywords_to_change = {} def add_header_keywords(self, hdr_dict): """Add specified keywords to outgoing header dict""" for key, value in hdr_dict.items(): self.keywords_to_add[key] = value def sub_header_keywords(self, hdr_dict): """Remove specified keywords from outgoing header dict""" for key in hdr_dict: self.keywords_to_sub.append(key) def remap_prefixed_keywords(self, prefix, suffixes): """Remap the keywords in suffixes, removing the prefix""" for suffix in suffixes: self.keywords_to_change[prefix + suffix] = suffix def on_sequence(self, iseq): print("PsrDadaSinkBlock::on_sequence") updated_header = iseq.header.copy() # rename some header keywords for key, value in self.keywords_to_change.items(): try: self.keywords_to_add[value] = updated_header[key] self.keywords_to_sub.append(key) except KeyError: pass # insert the additional keywords updated_header.update(self.keywords_to_add) # remove the keywords for key in self.keywords_to_sub: try: del updated_header[key] except KeyError: pass dada_header_str = generate_dada_header(updated_header) dada_header_buf = next(self.hdu.header_block) dada_header_buf.data[:] = np.fromstring(dada_header_str.encode('ascii'), dtype='uint8') dada_header_buf.close() def on_sequence_end(self, iseq): self.hdu.disconnect() def on_data(self, ispan): # TODO: Make this work in CUDA space dada_blk = next(self.hdu.data_block) nbyte = ispan.data.nbytes _check(_bf.bfMemcpy(dada_blk.ptr, _bf.BF_SPACE_SYSTEM, ispan.data.ctypes.data, _bf.BF_SPACE_SYSTEM, nbyte)) #dada_blk.data[:] = ispan.data.view('u8') dada_blk.close()