def setUp(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange( -21600, +21600, 3600.0) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-65.0 * u.deg, frame='icrs', equinox='J2000') self.frequency = numpy.linspace(1.0e8, 1.1e8, 3) self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7]) self.bvis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0)
def test_apply_primary_beam_imageplane(self): self.createVis() telescope = 'MID' lflux = numpy.array([[100.0, 1.0, -10.0, +60.0]]) cflux = numpy.array([[100.0, 60.0, -10.0, +1.0]]) apply_pb = True for flux, vpol in ((lflux, PolarisationFrame("linear")), (cflux, PolarisationFrame("circular"))): # print("Testing {0}".format(vpol.type)) # print("Original flux = {}".format(flux)) bvis = create_blockvisibility( self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=vpol, zerow=True) component_centre = SkyCoord(ra=+15.5 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') component = create_skycomponent( direction=component_centre, flux=flux, frequency=self.frequency, polarisation_frame=PolarisationFrame("stokesIQUV")) model = create_image_from_visibility( bvis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) pb = create_pb(model, telescope=telescope, use_local=False) if apply_pb: pbcomp = apply_beam_to_skycomponent(component, pb) # print("After application of primary beam {}".format(str(pbcomp.flux))) else: pbcomp = copy_skycomponent(component) bvis = dft_skycomponent_visibility(bvis, pbcomp) iquv_image = idft_visibility_skycomponent(bvis, component)[0]
def test_apply_voltage_pattern_image_pointsource(self): self.createVis(rmax=1e3) telescope = 'MID_FEKO_B2' vpol = PolarisationFrame("linear") self.times = numpy.linspace(-4, +4, 8) * numpy.pi / 12.0 bvis = create_blockvisibility(self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=vpol, zerow=True) cellsize = advise_wide_field(bvis)['cellsize'] pbmodel = create_image_from_visibility( bvis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) vpbeam = create_vp(pbmodel, telescope=telescope, use_local=False) vpbeam.wcs.wcs.ctype[0] = 'RA---SIN' vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN' vpbeam.wcs.wcs.crval[0] = pbmodel.wcs.wcs.crval[0] vpbeam.wcs.wcs.crval[1] = pbmodel.wcs.wcs.crval[1] s3_components = create_test_skycomponents_from_s3( flux_limit=0.1, phasecentre=self.phasecentre, frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI'), radius=1.5 * numpy.pi / 180.0) for comp in s3_components: comp.polarisation_frame = PolarisationFrame('stokesIQUV') comp.flux = numpy.array([[comp.flux[0, 0], 0.0, 0.0, 0.0]]) s3_components = filter_skycomponents_by_flux(s3_components, 0.0, 10.0) from rascil.processing_components.image import show_image import matplotlib.pyplot as plt plt.clf() show_image(vpbeam, components=s3_components) plt.show(block=False) vpcomp = apply_voltage_pattern_to_skycomponent(s3_components, vpbeam) bvis.data['vis'][...] = 0.0 + 0.0j bvis = dft_skycomponent_visibility(bvis, vpcomp) rec_comp = idft_visibility_skycomponent(bvis, vpcomp)[0] stokes_comp = list() for comp in rec_comp: stokes_comp.append( convert_pol_frame(comp.flux[0], PolarisationFrame("linear"), PolarisationFrame("stokesIQUV"))) stokesI = numpy.abs( numpy.array([comp_flux[0] for comp_flux in stokes_comp]).real) stokesQ = numpy.abs( numpy.array([comp_flux[1] for comp_flux in stokes_comp]).real) stokesU = numpy.abs( numpy.array([comp_flux[2] for comp_flux in stokes_comp]).real) stokesV = numpy.abs( numpy.array([comp_flux[3] for comp_flux in stokes_comp]).real) plt.clf() plt.loglog(stokesI, stokesQ, '.', label='Q') plt.loglog(stokesI, stokesU, '.', label='U') plt.loglog(stokesI, stokesV, '.', label='V') plt.xlabel("Stokes Flux I (Jy)") plt.ylabel("Flux (Jy)") plt.legend() plt.savefig('%s/test_primary_beams_pol_rsexecute_stokes_errors.png' % self.dir) plt.show(block=False) split_times = False if split_times: bvis_list = list() for rows in vis_timeslice_iter(bvis, vis_slices=8): bvis_list.append(create_visibility_from_rows(bvis, rows)) else: bvis_list = [bvis] bvis_list = rsexecute.scatter(bvis_list) model_list = \ [rsexecute.execute(create_image_from_visibility, nout=1)(bv, cellsize=cellsize, npixel=4096, phasecentre=self.phasecentre, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) for bv in bvis_list] model_list = rsexecute.persist(model_list) bvis_list = weight_list_rsexecute_workflow(bvis_list, model_list) continuum_imaging_list = \ continuum_imaging_list_rsexecute_workflow(bvis_list, model_list, context='2d', algorithm='hogbom', facets=1, niter=1000, fractional_threshold=0.1, threshold=1e-4, nmajor=5, gain=0.1, deconvolve_facets=4, deconvolve_overlap=32, deconvolve_taper='tukey', psf_support=64, restore_facets=4, psfwidth=1.0) clean, residual, restored = rsexecute.compute(continuum_imaging_list, sync=True) centre = 0 if self.persist: export_image_to_fits( clean[centre], '%s/test_primary_beams_pol_rsexecute_clean.fits' % self.dir) export_image_to_fits( residual[centre][0], '%s/test_primary_beams_pol_rsexecute_residual.fits' % self.dir) export_image_to_fits( restored[centre], '%s/test_primary_beams_pol_rsexecute_restored.fits' % self.dir) plt.clf() show_image(restored[centre]) plt.show(block=False) qa = qa_image(restored[centre]) assert numpy.abs(qa.data['max'] - 0.9953017707113947) < 1.0e-7, str(qa) assert numpy.abs(qa.data['min'] + 0.0036396480874570846) < 1.0e-7, str(qa)
def test_apply_voltage_pattern_skycomponent(self): self.createVis() telescope = 'MID_FEKO_B2' vpbeam = create_vp(telescope=telescope, use_local=False) vpol = PolarisationFrame("linear") bvis = create_blockvisibility(self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=vpol) cellsize = advise_wide_field(bvis)['cellsize'] component_centre = SkyCoord(ra=+15.25 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') model = create_image_from_visibility( bvis, cellsize=cellsize, npixel=1024, phasecentre=component_centre, override_cellsize=False, polarisation_frame=PolarisationFrame("linear")) bvis = weight_blockvisibility(bvis, model) pbmodel = create_image_from_visibility( bvis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) vpbeam = create_vp(pbmodel, telescope=telescope, use_local=False) vpbeam.wcs.wcs.ctype[0] = 'RA---SIN' vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN' vpbeam.wcs.wcs.crval[0] = pbmodel.wcs.wcs.crval[0] vpbeam.wcs.wcs.crval[1] = pbmodel.wcs.wcs.crval[1] for case, flux in enumerate( (numpy.array([[100.0, 0.0, 0.0, 0.0]]), numpy.array([[100.0, 100.0, 0.0, 0.0]]), numpy.array([[100.0, 0.0, 100.0, 0.0]]), numpy.array([[100.0, 0.0, 0.0, 100.0]]), numpy.array([[100.0, 1.0, -10.0, +60.0]]))): component = create_skycomponent( direction=component_centre, flux=flux, frequency=self.frequency, polarisation_frame=PolarisationFrame("stokesIQUV")) vpcomp = apply_voltage_pattern_to_skycomponent(component, vpbeam) bvis.data['vis'][...] = 0.0 + 0.0j bvis = dft_skycomponent_visibility(bvis, vpcomp) polimage, sumwt = invert_2d(bvis, model, dopsf=False) export_image_to_fits( polimage, "{0}/test_primary_beams_pol_case{1}.fits".format( self.dir, case)) # Check out the path via components found_components = find_skycomponents(polimage, threshold=20.0, npixels=5) assert len(found_components) == 1 inv_vpcomp = apply_voltage_pattern_to_skycomponent( found_components[0], vpbeam, inverse=True) assert_array_almost_equal(flux, numpy.real(inv_vpcomp.flux), 1) # Now check out the path via images vpbeam.wcs.wcs.ctype[0] = polimage.wcs.wcs.ctype[0] vpbeam.wcs.wcs.ctype[1] = polimage.wcs.wcs.ctype[1] vpbeam.wcs.wcs.crval[0] = polimage.wcs.wcs.crval[0] vpbeam.wcs.wcs.crval[1] = polimage.wcs.wcs.crval[1] vpbeam_regrid, footprint = reproject_image(vpbeam, polimage.wcs, polimage.shape) polimage_corrected = apply_voltage_pattern_to_image(polimage, vpbeam_regrid, inverse=True, min_det=0.3) export_image_to_fits( polimage_corrected, "{0}/test_primary_beams_pol_corrected_case{1}.fits".format( self.dir, case)) found_components = find_skycomponents(polimage_corrected, threshold=20.0, npixels=5) assert len(found_components) == 1
def test_apply_voltage_pattern_dft(self): self.createVis() nfailures = 0 telescope = 'MID_FEKO_B2' for flux in (numpy.array([[100.0, 0.0, 0.0, 0.0]]), numpy.array([[100.0, 100.0, 0.0, 0.0]]), numpy.array([[100.0, 0.0, 100.0, 0.0]]), numpy.array([[100.0, 0.0, 0.0, 100.0]]), numpy.array([[100.0, 1.0, -10.0, +60.0]])): vpol = PolarisationFrame("linear") try: bvis = create_blockvisibility( self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=vpol) component_centre = SkyCoord(ra=+16.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') component = create_skycomponent( direction=component_centre, flux=flux, frequency=self.frequency, polarisation_frame=PolarisationFrame("stokesIQUV")) model = create_image_from_visibility( bvis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False, polarisation_frame=PolarisationFrame("stokesIQUV")) vpbeam = create_vp(model, telescope=telescope, use_local=False) vpbeam.wcs.wcs.ctype[0] = 'RA---SIN' vpbeam.wcs.wcs.ctype[1] = 'DEC--SIN' vpbeam.wcs.wcs.crval[0] = model.wcs.wcs.crval[0] vpbeam.wcs.wcs.crval[1] = model.wcs.wcs.crval[1] assert component.polarisation_frame == PolarisationFrame( "stokesIQUV") vpcomp = apply_voltage_pattern_to_skycomponent( component, vpbeam) assert vpcomp.polarisation_frame == vpbeam.polarisation_frame bvis = dft_skycomponent_visibility(bvis, vpcomp) vpcomp = idft_visibility_skycomponent(bvis, vpcomp)[0][0] assert vpcomp.polarisation_frame == bvis.polarisation_frame inv_vpcomp = apply_voltage_pattern_to_skycomponent( vpcomp, vpbeam, inverse=True) assert vpcomp.polarisation_frame == PolarisationFrame( "stokesIQUV") # print("After application of primary beam {}".format(str(vpcomp.flux))) # print("After correction of primary beam {}".format(str(inv_vpcomp.flux))) # print("{0} {1} succeeded".format(vpol, str(flux))) assert_array_almost_equal(flux, numpy.real(inv_vpcomp.flux), 9) except AssertionError as e: print(e) print("{0} {1} failed".format(vpol, str(flux))) nfailures += 1 assert nfailures == 0, "{} tests failed".format(nfailures)