def predict_wstack_single(vis, model, remove=True, gcfcf=None, **kwargs) -> Visibility: """ Predict using a single w slices. This processes a single w plane, rotating out the w beam for the average w The w-stacking or w-slicing approach is to partition the visibility data by slices in w. The measurement equation is approximated as: .. math:: V(u,v,w) =\\sum_i \\int \\frac{ I(l,m) e^{-2 \\pi j (w_i(\\sqrt{1-l^2-m^2}-1))})}{\\sqrt{1-l^2-m^2}} e^{-2 \\pi j (ul+vm)} dl dm If images constructed from slices in w are added after applying a w-dependent image plane correction, the w term will be corrected. :param vis: Visibility to be predicted :param model: model image :return: resulting visibility (in place works) """ assert isinstance(vis, Visibility), vis assert image_is_canonical(model) vis.data['vis'][...] = 0.0 log.debug("predict_wstack_single: predicting using single w slice") # We might want to do wprojection so we remove the average w w_average = numpy.average(vis.w) if remove: vis.data['uvw'][..., 2] -= w_average tempvis = copy_visibility(vis) # Calculate w beam and apply to the model. The imaginary part is not needed workimage = copy_image(model) w_beam = create_w_term_like(model, w_average, vis.phasecentre) # Do the real part workimage.data = w_beam.data.real * model.data vis = predict_2d(vis, workimage, gcfcf=gcfcf, **kwargs) # and now the imaginary part workimage.data = w_beam.data.imag * model.data tempvis = predict_2d(tempvis, workimage, gcfcf=gcfcf, **kwargs) vis.data['vis'] -= 1j * tempvis.data['vis'] if remove: vis.data['uvw'][..., 2] += w_average return vis
def test_insert_skycomponent_FFT_IQUV(self): self.actualSetup(dopol=True) self.sc = create_skycomponent(direction=self.phasecentre, flux=self.sc.flux, frequency=self.component_frequency, polarisation_frame=self.image_pol) insert_skycomponent(self.model, self.sc) npixel = self.model.shape[3] # WCS is 1-relative rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int') - 1 assert rpix[0] == npixel // 2 assert rpix[1] == npixel // 2 # The phase centre is at rpix[0], rpix[1] in 0-relative pixels assert_array_almost_equal(self.model.data[2, :, rpix[1], rpix[0]], self.flux[3, :], 8) # If we predict the visibility, then the imaginary part must be zero. This is determined entirely # by shift_vis_to_image in processing_components.imaging.base self.vis.data['vis'][...] = 0.0 self.vis = predict_2d(self.vis, self.model) # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel). assert numpy.max(numpy.abs(self.vis.vis[..., 0].imag)) == 0.0 assert numpy.max(numpy.abs(self.vis.vis[..., 3].imag)) == 0.0
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7) self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e6]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), zerow=True) self.vis.data['vis'] *= 0.0 # Create model self.test_model = create_test_image(cellsize=0.001, phasecentre=self.vis.phasecentre, frequency=self.frequency) self.vis = predict_2d(self.vis, self.test_model) assert numpy.max(numpy.abs(self.vis.vis)) > 0.0 self.model = create_image_from_visibility( self.vis, npixel=512, cellsize=0.001, polarisation_frame=PolarisationFrame('stokesI')) self.dirty, sumwt = invert_2d(self.vis, self.model) self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True)
def _predict_base(self, fluxthreshold=1.0, gcf=None, cf=None, name='predict_2d', gcfcf=None, **kwargs): vis = predict_2d(self.vis, self.model, gcfcf=gcfcf, **kwargs) vis.data['vis'] = self.vis.data['vis'] - vis.data['vis'] dirty = invert_2d(vis, self.model, dopsf=False, normalize=True, gcfcf=gcfcf) if self.persist: export_image_to_fits( dirty[0], '%s/test_imaging_%s_residual.fits' % (self.dir, name)) assert numpy.max(numpy.abs(dirty[0].data)), "Residual image is empty" maxabs = numpy.max(numpy.abs(dirty[0].data)) assert maxabs < fluxthreshold, "Error %.3f greater than fluxthreshold %.3f " % ( maxabs, fluxthreshold)
def test_predict_2d_point_block(self): self.actualSetUp(zerow=True, block=True) self.model.data[...] = 0.0 nchan, npol, ny, nx = self.model.shape self.model.data[0, 0, ny // 2, nx // 2] = 1.0 vis = predict_2d(self.vis, self.model) assert numpy.max(numpy.abs(vis.vis-1.0)) < 1e-12
def setUp(self): from rascil.data_models.parameters import rascil_path self.lowcore = create_named_configuration('LOWBD2-CORE') self.dir = rascil_path('test_results') self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.image_frequency = numpy.linspace(0.9e8, 1.1e8, 5) self.component_frequency = numpy.linspace(0.8e8, 1.2e8, 7) self.channel_bandwidth = numpy.array(5*[1e7]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility(self.lowcore, self.times, self.image_frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), zerow=True) self.vis.data['vis'] *= 0.0 # Create model self.model = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.image_frequency) self.model.data[self.model.data > 1.0] = 1.0 self.vis = predict_2d(self.vis, self.model) assert numpy.max(numpy.abs(self.vis.vis)) > 0.0 dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000') flux = [[numpy.power(f/1e8, -0.7)] for f in self.component_frequency] self.sc = create_skycomponent(direction=dphasecentre, flux=flux, frequency=self.component_frequency, polarisation_frame=PolarisationFrame('stokesI'))
def test_predict_2d_point_block_IQUV(self): self.actualSetUp(zerow=True, block=True, image_pol=PolarisationFrame("stokesIQUV")) self.model.data[...] = 0.0 nchan, npol, ny, nx = self.model.shape self.model.data[0, 0, ny // 2, nx // 2] = 1.0 vis = predict_2d(self.vis, self.model) assert numpy.max(numpy.abs(vis.vis[...,0]-1.0)) < 1e-12 assert numpy.max(numpy.abs(vis.vis[...,1])) < 1e-12 assert numpy.max(numpy.abs(vis.vis[...,2])) < 1e-12 assert numpy.max(numpy.abs(vis.vis[...,3]-1.0)) < 1e-12
def test_predict_2d_offset_point(self): self.actualSetUp(zerow=True, block=True) nchan, npol, ny, nx = self.model.shape for oversampling in [15]: self.model.data[...] = 0.0 self.model.data[0, 0, ny // 2 - ny // 8, nx // 2] = 1.0 vis = predict_2d(self.vis, self.model, oversampling=oversampling) print(oversampling, numpy.max(numpy.abs(vis.vis))) plot_visibility([vis], x="uvdist") plot_visibility([vis], x="uvdist", y="phase")
def test_insert_skycomponent_FFT(self): self.model.data *= 0.0 self.sc = create_skycomponent(direction=self.phasecentre, flux=self.sc.flux, frequency=self.component_frequency, polarisation_frame=PolarisationFrame('stokesI')) insert_skycomponent(self.model, self.sc) npixel = self.model.shape[3] # WCS is 1-relative rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int') - 1 assert rpix[0] == npixel // 2 assert rpix[1] == npixel // 2 # The phase centre is at rpix[0], rpix[1] in 0-relative pixels assert self.model.data[2, 0, rpix[1], rpix[0]] == 1.0 # If we predict the visibility, then the imaginary part must be zero. This is determined entirely # by shift_vis_to_image in processing_components.imaging.base self.vis.data['vis'][...] = 0.0 self.vis = predict_2d(self.vis, self.model) # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel). assert numpy.max(numpy.abs(self.vis.vis.imag)) <1e-3
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", False) self.niter = 1000 self.lowcore = create_named_configuration('LOWBD2-CORE') self.nchan = 5 self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.frequency = numpy.linspace(0.9e8, 1.1e8, self.nchan) self.channel_bandwidth = numpy.array(self.nchan * [self.frequency[1] - self.frequency[0]]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility(self.lowcore, self.times, self.frequency, self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), zerow=True) self.vis.data['vis'] *= 0.0 # Create model self.test_model = create_low_test_image_from_gleam(npixel=512, cellsize=0.001, phasecentre=self.vis.phasecentre, frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, flux_limit=1.0) beam = create_low_test_beam(self.test_model) if self.persist: export_image_to_fits(beam, "%s/test_deconvolve_mmclean_beam.fits" % self.dir) self.test_model.data *= beam.data if self.persist: export_image_to_fits(self.test_model, "%s/test_deconvolve_mmclean_model.fits" % self.dir) self.vis = predict_2d(self.vis, self.test_model) assert numpy.max(numpy.abs(self.vis.vis)) > 0.0 self.model = create_image_from_visibility(self.vis, npixel=512, cellsize=0.001, polarisation_frame=PolarisationFrame('stokesI')) self.dirty, sumwt = invert_2d(self.vis, self.model) self.psf, sumwt = invert_2d(self.vis, self.model, dopsf=True) if self.persist: export_image_to_fits(self.dirty, "%s/test_deconvolve_mmclean-dirty.fits" % self.dir) if self.persist: export_image_to_fits(self.psf, "%s/test_deconvolve_mmclean-psf.fits" % self.dir) window = numpy.ones(shape=self.model.shape, dtype=numpy.bool) window[..., 129:384, 129:384] = True self.innerquarter = create_image_from_array(window, self.model.wcs, polarisation_frame=PolarisationFrame('stokesI'))