def test_coalesce_decoalesce_with_iter(self): for rows in vis_timeslice_iter(self.blockvis): visslice = create_visibility_from_rows(self.blockvis, rows) cvisslice = convert_blockvisibility_to_visibility(visslice) assert numpy.min(cvisslice.frequency) == numpy.min(self.frequency) assert numpy.min(cvisslice.frequency) > 0.0 dvisslice = decoalesce_visibility(cvisslice) assert dvisslice.nvis == visslice.nvis
def test_vis_timeslice_iterator_single(self): self.actualSetUp(times=numpy.zeros([1])) nchunks = len(list(vis_timeslice_iter(self.vis))) log.debug('Found %d chunks' % (nchunks)) for chunk, rows in enumerate(vis_timeslice_iter(self.vis)): visslice = create_visibility_from_rows(self.vis, rows) assert visslice.vis[0].real == visslice.time[0] assert len(rows)
def test_vis_wstack_iterator(self): self.actualSetUp() nchunks = len(list(vis_wstack_iter(self.vis, wstack=10.0))) log.debug('Found %d chunks' % (nchunks)) assert nchunks > 1 for chunk, rows in enumerate(vis_wstack_iter(self.vis, wstack=10.0)): assert len(rows) visslice = create_visibility_from_rows(self.vis, rows) assert numpy.sum(visslice.nvis) < self.vis.nvis
def test_vis_timeslice_iterator(self): self.actualSetUp() nchunks = len(list(vis_timeslice_iter(self.vis))) log.debug('Found %d chunks' % (nchunks)) assert nchunks > 1 for chunk, rows in enumerate(vis_timeslice_iter(self.vis)): visslice = create_visibility_from_rows(self.vis, rows) assert visslice.vis[0].real == visslice.time[0] assert len(rows) assert numpy.sum(rows) < self.vis.nvis
def visibility_scatter(vis, vis_iter, **kwargs): """Scatter an visibility into a list of subvisibilities :param vis: Visibility :param vis_iter: visibility iterator :returns: list of subvisibilitys """ visibility_list = list() for i, rows in enumerate(vis_iter(vis, **kwargs)): if rows is not None: subvis = create_visibility_from_rows(vis, rows) visibility_list.append(subvis) else: visibility_list.append(None) return visibility_list
def predict_with_vis_iterator(vis, model, vis_iter=vis_slice_iter, predict=predict_2d, **kwargs): """Iterate through prediction in chunks This knows about the structure of predict in different execution frameworks but not anything about the actual processing. """ log.debug("predict_with_vis_iterator: Processing chunks") # Do each chunk in turn for rows in vis_iter(vis, **kwargs): if rows is not None: visslice = create_visibility_from_rows(vis, rows) visslice = predict(visslice, model, **kwargs) vis.data['vis'][rows] += visslice.data['vis'] return vis
def invert_with_vis_iterator(vis, im, dopsf=False, normalize=True, vis_iter=vis_slice_iter, invert=invert_2d, **kwargs): """ Invert using a specified iterator and invert This knows about the structure of invert in different execution frameworks but not anything about the actual processing. :param vis: :param im: :param dopsf: Make the psf instead of the dirty image :param normalize: Normalize by the sum of weights (True) :param kwargs: :return: """ resultimage = create_empty_image_like(im) i = 0 for rows in vis_iter(vis, **kwargs): if rows is not None: visslice = create_visibility_from_rows(vis, rows) workimage, sumwt = invert(visslice, im, dopsf, normalize=False, **kwargs) resultimage.data += workimage.data if i == 0: totalwt = sumwt else: totalwt += sumwt i += 1 if normalize: resultimage = normalize_sumwt(resultimage, totalwt) return resultimage, totalwt
def test_vis_slice_iterator_vis_slices(self): self.actualSetUp() for chunk, rows in enumerate(vis_slice_iter(self.vis, vis_slices=11)): visslice = create_visibility_from_rows(self.vis, rows) assert len(rows) assert visslice.vis[0].real == visslice.time[0]