def test_insert_skycomponent_nearest(self): self.actualSetup() insert_skycomponent(self.model, self.sc, insert_method='Nearest') # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 1.0, 7) self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.0, 7)
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 test_insert_skycomponent_nearest_IQUV(self): self.actualSetup(dopol=True) insert_skycomponent(self.model, self.sc, insert_method='Nearest') # These test a regression but are not known a priori to be correct for pol in range(4): self.assertAlmostEqual(self.model.data[2, pol, 151, 122], self.pol_flux[pol], 7) self.assertAlmostEqual(self.model.data[2, pol, 152, 122], 0.0, 7)
def test_insert_skycomponent_sinc(self): self.actualSetup() insert_skycomponent(self.model, self.sc, insert_method='Sinc') # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 0.87684398703184396, 7) self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.2469311811046056, 7)
def test_insert_skycomponent_lanczos(self): self.actualSetup() insert_skycomponent(self.model, self.sc, insert_method='Lanczos') # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 0.87781267543090036, 7) self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.23817562762032077, 7)
def test_insert_skycomponent_lanczos_IQUV(self): self.actualSetup(dopol=True) insert_skycomponent(self.model, self.sc, insert_method='Lanczos') # These test a regression but are not known a priori to be correct for pol in range(4): self.assertAlmostEqual(self.model.data[2, pol, 151, 122], self.pol_flux[pol] * 0.87781267543090036, 7) self.assertAlmostEqual(self.model.data[2, pol, 152, 122], self.pol_flux[pol] * 0.23817562762032077, 7)
def test_insert_skycomponent_sinc_bandwidth(self): self.actualSetup() insert_skycomponent(self.model, self.sc, insert_method='Sinc', bandwidth=0.5) # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 0.25133066186805758, 7) self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.19685222464041874, 7)
def test_insert_skycomponent_lanczos_bandwidth(self): self.actualSetup() insert_skycomponent(self.model, self.sc, insert_method='Lanczos', bandwidth=0.5) # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[2, 0, 151, 122], 0.24031092091707615, 7) self.assertAlmostEqual(self.model.data[2, 0, 152, 122], 0.18648989466050975, 7)
def partition_skymodel_by_flux(sc, model, flux_threshold=-numpy.inf): """Partition skymodel according to flux Bright skycomponents are put into a SkyModel as a list, and weak skycomponents are inserted into SkyModel as an image. :param sc: List of skycomponents :param model: Model image :param flux_threshold: :return: SkyModel For example:: fluxes = numpy.linspace(0, 1.0, 11) sc = [create_skycomponent(direction=phasecentre, flux=numpy.array([[f]]), frequency=frequency, polarisation_frame=PolarisationFrame('stokesI')) for f in fluxes] sm = partition_skymodel_by_flux(sc, model, flux_threshold=0.31) assert len(sm.components) == 7, len(sm.components) """ brightsc = filter_skycomponents_by_flux(sc, flux_min=flux_threshold) weaksc = filter_skycomponents_by_flux(sc, flux_max=flux_threshold) log.info( 'Converted %d components into %d bright components and one image containing %d components' % (len(sc), len(brightsc), len(weaksc))) im = copy_image(model) im = insert_skycomponent(im, weaksc) return SkyModel(components=[copy_skycomponent(comp) for comp in brightsc], image=copy_image(im), mask=None, fixed=False)
def show_skymodel(sms, psf_width=1.75, cm='Greys', vmax=None, vmin=None): """ Show a list of SkyModels :param sms: List of SkyModels :param psf_width: Width of PSF in pixels :param cm: matplotlib colormap :param vmax: Maximum in image display :param vmin: Minimum in image display :return: """ sp = 1 for ism, sm in enumerate(sms): plt.clf() plt.subplot(121, projection=sms[ism].image.wcs.sub([1, 2])) sp += 1 smodel = copy_image(sms[ism].image) smodel = insert_skycomponent(smodel, sms[ism].components) smodel = smooth_image(smodel, psf_width) if vmax is None: vmax = numpy.max(smodel.data[0, 0, ...]) if vmin is None: vmin = numpy.min(smodel.data[0, 0, ...]) plt.imshow(smodel.data[0, 0, ...], origin='lower', cmap=cm, vmax=vmax, vmin=vmin) plt.xlabel(sms[ism].image.wcs.wcs.ctype[0]) plt.ylabel(sms[ism].image.wcs.wcs.ctype[1]) plt.title('SkyModel%d' % ism) components = sms[ism].components if components is not None: for sc in components: x, y = skycoord_to_pixel(sc.direction, sms[ism].image.wcs, 0, 'wcs') plt.plot(x, y, marker='+', color='red') gaintable = sms[ism].gaintable if gaintable is not None: plt.subplot(122) sp += 1 phase = numpy.angle(sm.gaintable.gain[:, :, 0, 0, 0]) phase -= phase[:, 0][:, numpy.newaxis] plt.imshow(phase, origin='lower') plt.xlabel('Dish/Station') plt.ylabel('Integration') plt.show()
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 actualSetUp(self, freqwin=1, block=True, dopol=False): self.npixel = 512 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.vis = list() self.ntimes = 5 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if freqwin > 1: self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) flux = numpy.array( [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: self.frequency = numpy.array([1e8]) self.channelwidth = numpy.array([1e6]) flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.bvis = ingest_unittest_visibility(self.low, self.frequency, self.channelwidth, self.times, self.vis_pol, self.phasecentre, block=block) self.vis = convert_blockvisibility_to_visibility(self.bvis) self.model = create_unittest_model(self.vis, self.image_pol, npixel=self.npixel, nchan=freqwin) self.components = create_unittest_components(self.model, flux) self.model = insert_skycomponent(self.model, self.components) self.bvis = predict_skycomponent_visibility(self.bvis, self.components)
def partition_skymodel_by_flux(sc, model, flux_threshold=-numpy.inf): """Partition skymodel according to flux :param sc: :param model: :param flux_threshold: :return: """ brightsc = filter_skycomponents_by_flux(sc, flux_min=flux_threshold) weaksc = filter_skycomponents_by_flux(sc, flux_max=flux_threshold) log.info( 'Converted %d components into %d bright components and one image containing %d components' % (len(sc), len(brightsc), len(weaksc))) im = copy_image(model) im = insert_skycomponent(im, weaksc) return SkyModel(components=[copy_skycomponent(comp) for comp in brightsc], image=copy_image(im), mask=None, fixed=False)
def actualSetUp(self, add_errors=False, freqwin=3, block=True, dospectral=True, dopol=False, zerow=False, makegcfcf=False): self.npixel = 256 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.bvis_list = list() self.ntimes = 5 self.cellsize = 0.0005 # Choose the interval so that the maximum change in w is smallish integration_time = numpy.pi * (24 / (12 * 60)) self.times = numpy.linspace(-integration_time * (self.ntimes // 2), integration_time * (self.ntimes // 2), self.ntimes) if freqwin > 1: self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.frequency = numpy.array([1.0e8]) self.channelwidth = numpy.array([4e7]) if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if dospectral: flux = numpy.array( [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.bvis_list = [ ingest_unittest_visibility( self.low, numpy.array([self.frequency[freqwin]]), numpy.array([self.channelwidth[freqwin]]), self.times, self.vis_pol, self.phasecentre, block=block, zerow=zerow) for freqwin, _ in enumerate(self.frequency) ] self.model_list = [ create_unittest_model(self.bvis_list[freqwin], self.image_pol, cellsize=self.cellsize, npixel=self.npixel) for freqwin, _ in enumerate(self.frequency) ] self.components_list = [ create_unittest_components(self.model_list[freqwin], flux[freqwin, :][numpy.newaxis, :], single=False) for freqwin, _ in enumerate(self.frequency) ] self.model_list = [ insert_skycomponent(self.model_list[freqwin], self.components_list[freqwin]) for freqwin, _ in enumerate(self.frequency) ] self.bvis_list = [ dft_skycomponent_visibility(self.bvis_list[freqwin], self.components_list[freqwin]) for freqwin, _ in enumerate(self.frequency) ] centre = self.freqwin // 2 # Calculate the model convolved with a Gaussian. self.model = self.model_list[centre] self.cmodel = smooth_image(self.model) if self.persist: export_image_to_fits(self.model, '%s/test_imaging_model.fits' % self.dir) if self.persist: export_image_to_fits(self.cmodel, '%s/test_imaging_cmodel.fits' % self.dir) if add_errors and block: self.bvis_list = [ insert_unittest_errors(self.bvis_list[i]) for i, _ in enumerate(self.frequency) ] self.components = self.components_list[centre] if makegcfcf: self.gcfcf = [ create_awterm_convolutionfunction(self.model, nw=61, wstep=16.0, oversampling=8, support=64, use_aaf=True) ] self.gcfcf_clipped = [ (self.gcfcf[0][0], apply_bounding_box_convolutionfunction(self.gcfcf[0][1], fractional_level=1e-3)) ] self.gcfcf_joint = [ create_awterm_convolutionfunction(self.model, nw=11, wstep=16.0, oversampling=8, support=64, use_aaf=True) ] else: self.gcfcf = None self.gcfcf_clipped = None self.gcfcf_joint = None
def actualSetUp(self, add_errors=False, freqwin=7, block=False, dospectral=True, dopol=False, zerow=True): self.npixel = 256 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.vis_list = list() self.ntimes = 5 cellsize = 0.001 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) if freqwin > 1: self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.channelwidth = numpy.array([1e6]) if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if dospectral: flux = numpy.array( [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis_list = [ ingest_unittest_visibility(self.low, [self.frequency[freqwin]], [self.channelwidth[freqwin]], self.times, self.vis_pol, self.phasecentre, block=block, zerow=zerow) for freqwin, _ in enumerate(self.frequency) ] self.model_imagelist = [ create_unittest_model(self.vis_list[freqwin], self.image_pol, cellsize=cellsize, npixel=self.npixel) for freqwin, _ in enumerate(self.frequency) ] self.componentlist = [ create_unittest_components(self.model_imagelist[freqwin], flux[freqwin, :][numpy.newaxis, :]) for freqwin, _ in enumerate(self.frequency) ] self.model_imagelist = [ insert_skycomponent(self.model_imagelist[freqwin], self.componentlist[freqwin]) for freqwin, _ in enumerate(self.frequency) ] self.vis_list = [ dft_skycomponent_visibility(self.vis_list[freqwin], self.componentlist[freqwin]) for freqwin, _ in enumerate(self.frequency) ] # Calculate the model convolved with a Gaussian. model = self.model_imagelist[0] self.cmodel = smooth_image(model) if self.persist: export_image_to_fits( model, '%s/test_imaging_serial_deconvolved_model.fits' % self.dir) if self.persist: export_image_to_fits( self.cmodel, '%s/test_imaging_serial_deconvolved_cmodel.fits' % self.dir) if add_errors and block: self.vis_list = [ insert_unittest_errors(self.vis_list[i]) for i, _ in enumerate(self.frequency) ]
def actualSetUp(self, zerow=True): self.doplot = False self.npixel = 256 self.cellsize = 0.0009 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = 1 self.vis_list = list() self.ntimes = 3 self.times = numpy.linspace(-2.0, +2.0, self.ntimes) * numpy.pi / 12.0 if self.freqwin == 1: self.frequency = numpy.array([1e8]) self.channelwidth = numpy.array([4e7]) else: self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) self.channelwidth = numpy.array( self.freqwin * [self.frequency[1] - self.frequency[0]]) self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, -10.0, 1.0]) flux = numpy.array( [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = ingest_unittest_visibility(self.low, self.frequency, self.channelwidth, self.times, self.vis_pol, self.phasecentre, block=False, zerow=zerow) self.model = create_unittest_model(self.vis, self.image_pol, cellsize=self.cellsize, npixel=self.npixel, nchan=self.freqwin) self.components = create_unittest_components(self.model, flux, applypb=False, scale=0.5, single=False, symmetric=True) self.model = insert_skycomponent(self.model, self.components) self.vis = predict_skycomponent_visibility(self.vis, self.components) # Calculate the model convolved with a Gaussian. self.cmodel = smooth_image(self.model) if self.persist: export_image_to_fits(self.model, '%s/test_gridding_model.fits' % self.dir) export_image_to_fits(self.cmodel, '%s/test_gridding_cmodel.fits' % self.dir) pb = create_pb_generic(self.model, diameter=35.0, blockage=0.0, use_local=False) self.cmodel.data *= pb.data if self.persist: export_image_to_fits(self.cmodel, '%s/test_gridding_cmodel_pb.fits' % self.dir) self.peak = numpy.unravel_index( numpy.argmax(numpy.abs(self.cmodel.data)), self.cmodel.shape)
equinox='J2000') blockvis = ingest_unittest_visibility(low, frequency, channelwidth, times, blockvis_pol, phasecentre, block=block, zerow=zerow) vis = convert_blockvisibility_to_visibility(blockvis) model = create_unittest_model(vis, image_pol, npixel=npixel, nchan=freqwin) components = create_unittest_components(model, flux) model = insert_skycomponent(model, components) blockvis = predict_skycomponent_visibility(blockvis, components) #blockvis = dft_skycomponent_visibility(blockvis, components) blockvis1 = copy_visibility(blockvis) vis1 = convert_blockvisibility_to_visibility(blockvis1) # Calculate the model convolved with a Gaussian. cmodel = smooth_image(model) if persist: export_image_to_fits(model, '%s/test_imaging_2d_model.fits' % rdir) if persist: export_image_to_fits(cmodel, '%s/test_imaging_2d_cmodel.fits' % rdir) # In[4]:
def ingest_visibility(self, freq=None, chan_width=None, times=None, add_errors=False, block=True, bandpass=False): if freq is None: freq = [1e8] if chan_width is None: chan_width = [1e6] if times is None: times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5) lowcore = create_named_configuration('LOWBD2', rmax=750.0) 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=frequency, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) nchan = len(self.frequency) flux = numpy.array(nchan * [[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( direction=sc, flux=flux, frequency=frequency, polarisation_frame=PolarisationFrame("stokesI")) comps.append(comp) if block: dft_skycomponent_visibility(vt, comps) else: dft_skycomponent_visibility(vt, comps) insert_skycomponent(model, comps) self.comps = comps self.model = copy_image(model) self.empty_model = create_empty_image_like(model) export_image_to_fits( model, '%s/test_pipeline_functions_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) if bandpass: bgt = create_gaintable_from_blockvisibility(vt, timeslice=1e5) bgt = simulate_gaintable(bgt, phase_error=0.01, amplitude_error=0.01, smooth_channels=4) vt = apply_gaintable(vt, bgt) return vt
def actualSetUp(self, add_errors=False, nfreqwin=7, dospectral=True, dopol=False, zerow=True): self.npixel = 512 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = nfreqwin self.vis_list = list() self.ntimes = 5 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) if self.freqwin > 1: self.channelwidth = numpy.array(self.freqwin * [self.frequency[1] - self.frequency[0]]) else: self.channelwidth = numpy.array([1e6]) if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, 0.0, 0.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if dospectral: flux = numpy.array([f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.blockvis_list = [ingest_unittest_visibility(self.low, [self.frequency[i]], [self.channelwidth[i]], self.times, self.vis_pol, self.phasecentre, block=True, zerow=zerow) for i in range(nfreqwin)] self.vis_list = [convert_blockvisibility_to_visibility(bv) for bv in self.blockvis_list] self.model_imagelist = [ create_unittest_model(self.vis_list[i], self.image_pol, npixel=self.npixel, cellsize=0.0005) for i in range(nfreqwin)] self.components_list = [create_unittest_components(self.model_imagelist[freqwin], flux[freqwin, :][numpy.newaxis, :]) for freqwin, m in enumerate(self.model_imagelist)] self.blockvis_list = [ dft_skycomponent_visibility(self.blockvis_list[freqwin], self.components_list[freqwin]) for freqwin, _ in enumerate(self.blockvis_list)] self.model_imagelist = [insert_skycomponent(self.model_imagelist[freqwin], self.components_list[freqwin]) for freqwin in range(nfreqwin)] model = self.model_imagelist[0] self.cmodel = smooth_image(model) if self.persist: export_image_to_fits(model, '%s/test_imaging_serial_model.fits' % self.dir) export_image_to_fits(self.cmodel, '%s/test_imaging_serial_cmodel.fits' % self.dir) if add_errors: gt = create_gaintable_from_blockvisibility(self.blockvis_list[0]) gt = simulate_gaintable(gt, phase_error=0.1, amplitude_error=0.0, smooth_channels=1, leakage=0.0) self.blockvis_list = [apply_gaintable(self.blockvis_list[i], gt) for i in range(self.freqwin)] self.vis_list = [convert_blockvisibility_to_visibility(bv) for bv in self.blockvis_list] self.model_imagelist = [ create_unittest_model(self.vis_list[i], self.image_pol, npixel=self.npixel, cellsize=0.0005) for i in range(nfreqwin)]
def create_low_test_image_from_gleam(npixel=512, polarisation_frame=PolarisationFrame( "stokesI"), cellsize=0.000015, frequency=numpy.array([1e8]), channel_bandwidth=numpy.array([1e6]), phasecentre=None, kind='cubic', applybeam=False, flux_limit=0.1, flux_max=numpy.inf, flux_min=-numpy.inf, radius=None, insert_method='Nearest') -> Image: """Create LOW test image from the GLEAM survey Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero. See http://www.mwatelescope.org/science/gleam-survey The catalog is available from Vizier. VIII/100 GaLactic and Extragalactic All-sky MWA survey (Hurley-Walker+, 2016) GaLactic and Extragalactic All-sky Murchison Wide Field Array (GLEAM) survey. I: A low-frequency extragalactic catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H :param npixel: Number of pixels :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI")) :param cellsize: cellsize in radians :param frequency: :param channel_bandwidth: Channel width (Hz) :param phasecentre: phasecentre (SkyCoord) :param kind: Kind of interpolation (see scipy.interpolate.interp1d) Default: linear :return: Image """ check_data_directory() if phasecentre is None: phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') if radius is None: radius = npixel * cellsize / numpy.sqrt(2.0) sc = create_low_test_skycomponents_from_gleam( flux_limit=flux_limit, polarisation_frame=polarisation_frame, frequency=frequency, phasecentre=phasecentre, kind=kind, radius=radius) sc = filter_skycomponents_by_flux(sc, flux_min=flux_min, flux_max=flux_max) if polarisation_frame is None: polarisation_frame = PolarisationFrame("stokesI") npol = polarisation_frame.npol nchan = len(frequency) shape = [nchan, npol, npixel, npixel] w = WCS(naxis=4) # The negation in the longitude is needed by definition of RA, DEC w.wcs.cdelt = [ -cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0, channel_bandwidth[0] ] w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0] w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ'] w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0]] w.naxis = 4 w.wcs.radesys = 'ICRS' w.wcs.equinox = 2000.0 model = create_image_from_array(numpy.zeros(shape), w, polarisation_frame=polarisation_frame) model = insert_skycomponent(model, sc, insert_method=insert_method) if applybeam: beam = create_pb(model, telescope='LOW', use_local=False) model.data[...] *= beam.data[...] return model
def create_low_test_skymodel_from_gleam(npixel=512, polarisation_frame=PolarisationFrame( "stokesI"), cellsize=0.000015, frequency=numpy.array([1e8]), channel_bandwidth=numpy.array([1e6]), phasecentre=None, kind='cubic', applybeam=True, flux_limit=0.1, flux_max=numpy.inf, flux_threshold=1.0, insert_method='Nearest', telescope='LOW') -> SkyModel: """Create LOW test skymodel from the GLEAM survey Stokes I is estimated from a cubic spline fit to the measured fluxes. The polarised flux is always zero. See http://www.mwatelescope.org/science/gleam-survey The catalog is available from Vizier. VIII/100 GaLactic and Extragalactic All-sky MWA survey (Hurley-Walker+, 2016) GaLactic and Extragalactic All-sky Murchison Wide Field Array (GLEAM) survey. I: A low-frequency extragalactic catalogue. Hurley-Walker N., et al., Mon. Not. R. Astron. Soc., 464, 1146-1167 (2017), 2017MNRAS.464.1146H :param telescope: :param npixel: Number of pixels :param polarisation_frame: Polarisation frame (default PolarisationFrame("stokesI")) :param cellsize: cellsize in radians :param frequency: :param channel_bandwidth: Channel width (Hz) :param phasecentre: phasecentre (SkyCoord) :param kind: Kind of interpolation (see scipy.interpolate.interp1d) Default: cubic :param applybeam: Apply the primary beam? :param flux_limit: Weakest component :param flux_max: Maximum strength component to be included in components :param flux_threshold: Split between components (brighter) and image (weaker) :param insert_method: Nearest | PSWF | Lanczos :return: :return: SkyModel """ check_data_directory() if phasecentre is None: phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') radius = npixel * cellsize sc = create_low_test_skycomponents_from_gleam( flux_limit=flux_limit, polarisation_frame=polarisation_frame, frequency=frequency, phasecentre=phasecentre, kind=kind, radius=radius) sc = filter_skycomponents_by_flux(sc, flux_max=flux_max) if polarisation_frame is None: polarisation_frame = PolarisationFrame("stokesI") npol = polarisation_frame.npol nchan = len(frequency) shape = [nchan, npol, npixel, npixel] w = WCS(naxis=4) # The negation in the longitude is needed by definition of RA, DEC w.wcs.cdelt = [ -cellsize * 180.0 / numpy.pi, cellsize * 180.0 / numpy.pi, 1.0, channel_bandwidth[0] ] w.wcs.crpix = [npixel // 2 + 1, npixel // 2 + 1, 1.0, 1.0] w.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ'] w.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0]] w.naxis = 4 w.wcs.radesys = 'ICRS' w.wcs.equinox = 2000.0 model = create_image_from_array(numpy.zeros(shape), w, polarisation_frame=polarisation_frame) if applybeam: beam = create_pb(model, telescope=telescope, use_local=False) sc = apply_beam_to_skycomponent(sc, beam) weaksc = filter_skycomponents_by_flux(sc, flux_max=flux_threshold) brightsc = filter_skycomponents_by_flux(sc, flux_min=flux_threshold) model = insert_skycomponent(model, weaksc, insert_method=insert_method) log.info( 'create_low_test_skymodel_from_gleam: %d bright sources above flux threshold %.3f, %d weak sources below ' % (len(brightsc), flux_threshold, len(weaksc))) return SkyModel(components=brightsc, image=model, mask=None, gaintable=None)
def actualSetUp(self, freqwin=1, block=False, dospectral=True, dopol=False, zerow=False): self.npixel = 512 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.vis = list() self.ntimes = 5 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 if freqwin > 1: self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.frequency = numpy.array([1e8]) self.channelwidth = numpy.array([1e6]) if dopol: self.vis_pol = PolarisationFrame('linear') self.image_pol = PolarisationFrame('stokesIQUV') f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if dospectral: flux = numpy.array( [f * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis = ingest_unittest_visibility(self.low, [self.frequency], [self.channelwidth], self.times, self.vis_pol, self.phasecentre, block=block, zerow=zerow) self.model = create_unittest_model(self.vis, self.image_pol, npixel=self.npixel) self.components = create_unittest_components(self.model, flux) self.model = insert_skycomponent(self.model, self.components) self.vis = predict_skycomponent_visibility(self.vis, self.components) # Calculate the model convolved with a Gaussian. self.cmodel = smooth_image(self.model) if self.persist: export_image_to_fits(self.model, '%s/test_imaging_model.fits' % self.dir) if self.persist: export_image_to_fits(self.cmodel, '%s/test_imaging_cmodel.fits' % self.dir)