def test_phase_rotation(self): self.vis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) # Predict visibilities with new phase centre independently ha_diff = -(self.compabsdirection.ra - self.phasecentre.ra).to( u.rad).value vispred = create_visibility( self.lowcore, self.times + ha_diff, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.compabsdirection, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vismodel2 = predict_skycomponent_visibility(vispred, self.comp) # Should yield the same results as rotation rotatedvis = phaserotate_visibility( self.vismodel, newphasecentre=self.compabsdirection, tangent=False) assert_allclose(rotatedvis.vis, vismodel2.vis, rtol=1e-7) assert_allclose(rotatedvis.uvw, vismodel2.uvw, rtol=1e-7)
def _predict_base(self, predict, fluxthreshold=1.0): self.modelvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.modelvis.data['vis'] *= 0.0 predict(self.modelvis, self.model, **self.params) self.residualvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.residualvis.data['uvw'][:, 2] = 0.0 self.residualvis.data[ 'vis'] = self.modelvis.data['vis'] - self.componentvis.data['vis'] self._checkdirty(self.residualvis, 'test_%s' % predict.__name__, fluxthreshold=fluxthreshold)
def _predict_base(self, context='2d', extra='', fluxthreshold=1.0): self.modelvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.modelvis.data['vis'] *= 0.0 self.modelvis = predict_context(self.modelvis, self.model, context=context, **self.params) self.residualvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.residualvis.data['uvw'][:, 2] = 0.0 self.residualvis.data[ 'vis'] = self.modelvis.data['vis'] - self.componentvis.data['vis'] self._checkdirty(self.residualvis, 'predict_%s%s' % (context, extra), fluxthreshold=fluxthreshold)
def test_append_visibility(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) othertimes = (numpy.pi / 43200.0) * numpy.arange(300.0, 600.0, 30.0) self.othervis = create_visibility(self.lowcore, othertimes, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.vis = append_visibility(self.vis, self.othervis) assert self.vis.nvis == len(self.vis.time) assert self.vis.nvis == len(self.vis.frequency)
def test_subtract(self): vis1 = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vis1.data['vis'][...] = 1.0 vis2 = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vis2.data['vis'][...] = 1.0 zerovis = subtract_visibility(vis1, vis2) qa = qa_visibility(zerovis, context='test_qa') self.assertAlmostEqual(qa.data['maxabs'], 0.0, 7)
def test_create_visibility_polarisation(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("linear")) assert self.vis.nvis == len(self.vis.time) assert self.vis.nvis == len(self.vis.frequency)
def test_create_visibility1(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) assert self.vis.nvis == len(self.vis.time) assert self.vis.nvis == len(self.vis.frequency)
def test_create_visibility_from_rows_makecopy(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, channel_bandwidth=self.channel_bandwidth) rows = self.vis.time > 150.0 for makecopy in [True, False]: selected_vis = create_visibility_from_rows(self.vis, rows, makecopy=makecopy) assert selected_vis.nvis == numpy.sum(numpy.array(rows))
def test_phase_rotation_identity(self): self.vis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) newphasecenters = [ SkyCoord(182, -35, unit=u.deg), SkyCoord(182, -30, unit=u.deg), SkyCoord(177, -30, unit=u.deg), SkyCoord(176, -35, unit=u.deg), SkyCoord(216, -35, unit=u.deg), SkyCoord(180, -70, unit=u.deg) ] for newphasecentre in newphasecenters: # Phase rotating back should not make a difference original_vis = self.vismodel.vis original_uvw = self.vismodel.uvw rotatedvis = phaserotate_visibility(phaserotate_visibility( self.vismodel, newphasecentre, tangent=False), self.phasecentre, tangent=False) assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7) assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) self.vnchan = 5 self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.frequency = numpy.linspace(8e7, 1.2e8, self.vnchan) self.startfrequency = numpy.array([8e7]) self.channel_bandwidth = numpy.array( self.vnchan * [self.frequency[1] - self.frequency[0]]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility( self.lowcore, times=self.times, frequency=self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) self.model = create_image_from_visibility( self.vis, npixel=512, cellsize=0.001, nchan=self.vnchan, frequency=self.startfrequency)
def ingest_visibility(self, freq=None, chan_width=None, times=None, reffrequency=None, add_errors=False, block=True): if freq is None: freq = [1e8] if times is None: ntimes = 5 times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes) if chan_width is None: chan_width = [1e6] if reffrequency is None: reffrequency = [1e8] lowcore = create_named_configuration('LOWBD2-CORE') frequency = numpy.array([freq]) channel_bandwidth = numpy.array([chan_width]) phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') if block: vt = create_blockvisibility(lowcore, times, frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) else: vt = create_visibility(lowcore, times, frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) cellsize = 0.001 model = create_image_from_visibility(vt, npixel=self.npixel, cellsize=cellsize, npol=1, frequency=reffrequency, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) flux = numpy.array([[100.0]]) facets = 4 rpix = model.wcs.wcs.crpix - 1.0 spacing_pixels = self.npixel // facets centers = [-1.5, -0.5, 0.5, 1.5] comps = list() for iy in centers: for ix in centers: p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[0]))), \ int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1]))) sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=1) comp = create_skycomponent(flux=flux, frequency=frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI")) comps.append(comp) if block: predict_skycomponent_blockvisibility(vt, comps) else: predict_skycomponent_visibility(vt, comps) insert_skycomponent(model, comps) self.model = copy_image(model) self.empty_model = create_empty_image_like(model) export_image_to_fits(model, '%s/test_pipeline_bags_model.fits' % self.dir) if add_errors: # These will be the same for all calls numpy.random.seed(180555) gt = create_gaintable_from_blockvisibility(vt) gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.0) vt = apply_gaintable(vt, gt) return vt
def test_invert_2d(self): # Test if the 2D invert works with w set to zero # Set w=0 so that the two-dimensional transform should agree exactly with the model. # Good check on the grid correction in the vis->image direction self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.componentvis.data['uvw'][:, 2] = 0.0 self.componentvis.data['vis'] *= 0.0 # Predict the visibility using direct evaluation for comp in self.components: predict_skycomponent_visibility(self.componentvis, comp) dirty2d = create_empty_image_like(self.model) dirty2d, sumwt = invert_2d(self.componentvis, dirty2d, **self.params) export_image_to_fits( dirty2d, '%s/test_imaging_functions_invert_2d_dirty.fits' % self.dir) self._checkcomponents(dirty2d)
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) 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')) 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) beam = create_low_test_beam(self.test_model) export_image_to_fits(beam, "%s/test_deconvolve_msmfsclean_beam.fits" % self.dir) self.test_model.data *= beam.data export_image_to_fits(self.test_model, "%s/test_deconvolve_msmfsclean_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) export_image_to_fits(self.dirty, "%s/test_deconvolve_msmfsclean_dirty.fits" % self.dir) export_image_to_fits(self.psf, "%s/test_deconvolve_msmfsclean_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)
def test_psf_location_2d(self): self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.componentvis.data['uvw'][:, 2] = 0.0 self.componentvis.data['vis'] *= 0.0 psf2d = create_empty_image_like(self.model) psf2d, sumwt = invert_2d(self.componentvis, psf2d, dopsf=True, **self.params) export_image_to_fits( psf2d, '%s/test_imaging_functions_invert_psf_location.fits' % self.dir) nchan, npol, ny, nx = psf2d.shape assert numpy.abs(psf2d.data[0, 0, ny // 2, nx // 2] - 1.0) < 2e-3 imagecentre = pixel_to_skycoord(nx // 2 + 1.0, ny // 2 + 1.0, wcs=psf2d.wcs, origin=1) assert imagecentre.separation(self.phasecentre).value < 1e-15, \ "Image phase centre %s not as expected %s" % (imagecentre, self.phasecentre)
def ingest_unittest_visibility(config, frequency, channel_bandwidth, times, vis_pol, phasecentre, block=False): if block: vt = create_blockvisibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol) else: vt = create_visibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol) vt.data['vis'][...] = 0.0 return vt
def createVis(self, config, dec=-35.0, rmax=None): self.config = create_named_configuration(config, rmax=rmax) self.phasecentre = SkyCoord(ra=+15 * u.deg, dec=dec * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility(self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'))
def setUp(self): self.dir = './test_results' self.lowcore = create_named_configuration('LOWBD2-CORE') os.makedirs(self.dir, exist_ok=True) 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')) self.vis.data['vis'] *= 0.0 # Create model self.model = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.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 export_image_to_fits( self.model, '%s/test_solve_skycomponent_model.fits' % (self.dir)) self.bigmodel = create_image_from_visibility(self.vis, cellsize=0.0015, npixel=512)
def ingest_visibility(self, freq=1e8, chan_width=1e6, times=None, reffrequency=None, add_errors=False): if times is None: times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5) if reffrequency is None: reffrequency = [1e8] lowcore = create_named_configuration('LOWBD2-CORE') frequency = numpy.array([freq]) channel_bandwidth = numpy.array([chan_width]) phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') vt = create_visibility(lowcore, times, frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) cellsize = 0.001 model = create_image_from_visibility( vt, npixel=self.npixel, cellsize=cellsize, npol=1, frequency=reffrequency, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) flux = numpy.array([[100.0]]) facets = 4 rpix = model.wcs.wcs.crpix spacing_pixels = self.npixel // facets centers = [-1.5, -0.5, 0.5, 1.5] comps = list() for iy in centers: for ix in centers: p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[0]))), \ int(round(rpix[1] + iy * spacing_pixels * numpy.sign(model.wcs.wcs.cdelt[1]))) sc = pixel_to_skycoord(p[0], p[1], model.wcs, origin=0) comp = create_skycomponent( flux=flux, frequency=frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI")) comps.append(comp) predict_skycomponent_visibility(vt, comps) insert_skycomponent(model, comps) self.model = copy_image(model) export_image_to_fits(model, '%s/test_bags_model.fits' % (self.results_dir)) return vt
def actualSetUp(self, time=None, frequency=None, dospectral=False, dopol=False): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5) if time is not None: self.times = time log.info("Times are %s" % (self.times)) if dospectral: self.nchan = 3 self.frequency = numpy.array([0.9e8, 1e8, 1.1e8]) self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7]) else: self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e7]) if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') if dopol: f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: f = numpy.array([100.0]) if dospectral: numpy.array([f, 0.8 * f, 0.6 * f]) else: numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.uvw = self.componentvis.data['uvw'] self.componentvis.data['vis'] *= 0.0 # Create model self.model = create_image_from_visibility( self.componentvis, npixel=512, cellsize=0.001, nchan=len(self.frequency), polarisation_frame=self.image_pol)
def test_visibilitysum(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) # Sum the visibilities in the correct_visibility direction. This is limited by numerical precision summedflux, weight = sum_visibility(self.vismodel, self.compreldirection) assert_allclose(self.flux, summedflux, rtol=1e-7)
def test_copy_visibility(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vis = copy_visibility(self.vis) self.vis.data['vis'] = 0.0 vis.data['vis'] = 1.0 assert (vis.data['vis'][0, 0].real == 1.0) assert (self.vis.data['vis'][0, 0].real == 0.0)
def test_sum_visibility(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) self.vis = predict_skycomponent_visibility(self.vis, self.comp) flux, weight = sum_visibility(self.vis, self.comp.direction) assert numpy.max(numpy.abs(flux - self.flux)) < 1e-7
def test_predict_2d(self): # Test if the 2D prediction works # # Set w=0 so that the two-dimensional transform should agree exactly with the component transform. # Good check on the grid correction in the image->vis direction # Set all w to zero self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.componentvis.data['uvw'][:, 2] = 0.0 # Predict the visibility using direct evaluation predict_skycomponent_visibility(self.componentvis, self.components) self.modelvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.modelvis.data['uvw'][:, 2] = 0.0 predict_2d(self.modelvis, self.model, **self.params) self.residualvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol) self.residualvis.data['uvw'][:, 2] = 0.0 self.residualvis.data[ 'vis'] = self.modelvis.data['vis'] - self.componentvis.data['vis'] self._checkdirty(self.residualvis, 'test_predict_2d', fluxthreshold=4.0)
def test_qa(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) qa = qa_visibility(self.vis, context='test_qa') self.assertAlmostEqual(qa.data['maxabs'], 100.0, 7) self.assertAlmostEqual(qa.data['medianabs'], 11.0, 7) assert qa.context == 'test_qa'
def actualSetUp(self, times=None): if times is not None: self.times = times self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.vis.data['vis'][:, 0] = self.vis.time
def test_phase_rotation_inverse(self): self.vis = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) there = SkyCoord(ra=+250.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') # Phase rotating back should not make a difference original_vis = self.vismodel.vis original_uvw = self.vismodel.uvw rotatedvis = phaserotate_visibility(phaserotate_visibility(self.vismodel, there, tangent=False, inverse=True), self.phasecentre, tangent=False, inverse=True) assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7) assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
def test_fit_visibility(self): # Sum the visibilities in the correct_visibility direction. This is limited by numerical precision methods = ['CG', 'BFGS', 'Powell', 'trust-ncg', 'trust-exact', 'trust-krylov'] for method in methods: self.actualSetup() 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")) self.vismodel = predict_skycomponent_visibility(self.vis, self.comp) initial_comp = Skycomponent(direction=self.comp_start_direction, frequency=self.frequency, flux=2.0 * self.flux, polarisation_frame=PolarisationFrame("stokesI")) sc, res = fit_visibility(self.vismodel, initial_comp, niter=200, tol=1e-5, method=method, verbose=False) # print(method, res) assert sc.direction.separation(self.comp_actual_direction).to('rad').value < 1e-6, \ sc.direction.separation(self.comp_actual_direction).to('rad')
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) 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')) 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) window = numpy.zeros(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'))
def create_visibility_para(config: Configuration, times: np.array, frequency: np.array, channel_bandwidth, phasecentre: SkyCoord, weight: float, polarisation_frame=PolarisationFrame('stokesI'), integration_time=1.0, mode="nto1", keys=None): visibility = create_visibility(config=config, times=times, frequency=frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=weight, polarisation_frame=polarisation_frame, integration_time=integration_time) viss, vis_share = visibility_to_visibility_para(visibility, mode=mode, keys=keys) return viss, vis_share
def test_create_image_from_visibility(self): self.actualSetUp() self.componentvis = create_visibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=self.vis_pol, channel_bandwidth=self.channel_bandwidth) im = create_image_from_visibility(self.componentvis, nchan=1, npixel=128) assert im.data.shape == (1, 1, 128, 128) im = create_image_from_visibility(self.componentvis, frequency=self.frequency, npixel=128) assert im.data.shape == (len(self.frequency), 1, 128, 128) im = create_image_from_visibility(self.componentvis, frequency=self.frequency, npixel=128, nchan=1) assert im.data.shape == (1, 1, 128, 128)