def get_tag_data(self, episode, tag_channel):
#memorise some useful properties
block = self.episode_block(episode)
sample_size = self.sample_size(episode, tag_channel)
sample_symbol = self.sample_symbol(episode, tag_channel)
#create a bit mask to define which
#sample to keep from the file
channel_mask = self.create_channel_mask(episode)
bit_mask = self.create_bit_mask(channel_mask, 1)
#get bytes from the file
data_block = self.data_blocks[episode - 1]
n_bytes = data_block.size
self.file.seek(data_block.start)
databytes = np.frombuffer(self.file.read(n_bytes), '<i1')
#detect which bits keep to recompose the tag
ep_mask = np.ones(n_bytes, dtype=int)
np.putmask(ep_mask, ep_mask, bit_mask)
to_keep = np.where(ep_mask > 0)[0]
raw = databytes.take(to_keep)
raw = raw.reshape([len(raw) / sample_size, sample_size])
#create a recarray containing data
dt = np.dtype(numpy_map[sample_symbol])
dt.newbyteorder('<')
tag_mask = 0b01 if (tag_channel == 1) else 0b10
y_data = np.frombuffer(raw, dt) & tag_mask
x_data = np.arange(0, len(y_data)) * block.dX + block.X0
data = np.recarray(len(y_data), dtype=[('x', b_float), ('y', b_int)])
data['x'] = x_data
data['y'] = y_data
return data
评论列表
文章目录