def set(self, hdata): assert(hdata.shape == self.shape) hdata = hdata.astype(self.dtype) if self.flags['C_CONTIGUOUS'] and hdata.flags['C_CONTIGUOUS']: memcpy(self, hdata) elif self.ndim == 2: memcpy2D(self, hdata) else: raise RuntimeError("Copying with this data layout is unsupported") return self
def get(self, dst=None): hdata = dst if dst is not None else np.empty(self.shape, self.dtype) # hdata = dst if dst is not None else np.zeros(self.shape, self.dtype) assert(hdata.shape == self.shape) assert(hdata.dtype == self.dtype) if self.flags['C_CONTIGUOUS'] and hdata.flags['C_CONTIGUOUS']: memcpy(hdata, self) elif self.ndim == 2: memcpy2D(hdata, self) else: raise RuntimeError("Copying with this data layout is unsupported") return hdata
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 = next(out_span_generator) memory.memcpy( out_span.data_view(dtype=np.float32), histogram)