def main(self, input_rings, output_rings):
"""Generate a histogram from the input ring data
@param[in] input_rings List with first ring containing
data of interest. Must terminate before histogram
is generated.
@param[out] output_rings First ring in this list
will contain the output histogram"""
histogram = np.reshape(
np.zeros(self.bins).astype(np.float32),
(1, self.bins))
tstart = None
for span in self.iterate_ring_read(input_rings[0]):
nchans = self.data_settings['frame_shape'][0]
if tstart is None:
tstart = self.data_settings['tstart']
frequency = self.data_settings['fch1']
for chan in range(nchans):
modified_tstart = tstart - self.calculate_delay(
frequency,
self.data_settings['fch1'])
frequency -= self.data_settings['foff']
sort_indices = np.argsort(
self.calculate_bin_indices(
modified_tstart, self.data_settings['tsamp'],
span.data.shape[1] / nchans))
sorted_data = span.data[0][chan::nchans][sort_indices]
extra_elements = np.round(self.bins * (1 - np.modf(
float(span.data.shape[1] / nchans) / self.bins)[0])).astype(int)
sorted_data = insert_zeros_evenly(sorted_data, extra_elements)
histogram += np.sum(
sorted_data.reshape(self.bins, -1), 1).astype(np.float32)
tstart += (self.data_settings['tsamp'] *
self.gulp_size * 8 / self.data_settings['nbit'] / nchans)
self.out_gulp_size = self.bins * 4
out_span_generator = self.iterate_ring_write(output_rings[0])
out_span = out_span_generator.next()
bifrost.memory.memcpy(
out_span.data_view(dtype=np.float32),
histogram)
评论列表
文章目录