def test_create_image_from_visibility(self): self.actualSetUp() im = create_image_from_visibility(self.vis, nchan=1, npixel=128) assert im.data.shape == (1, 1, 128, 128) im = create_image_from_visibility(self.vis, frequency=self.frequency, npixel=128) assert im.data.shape == (len(self.frequency), 1, 128, 128) im = create_image_from_visibility(self.vis, frequency=self.frequency, npixel=128, nchan=1) assert im.data.shape == (1, 1, 128, 128)
def test_invert(self): uvfitsfile = rascil_path("data/vis/ASKAP_example.fits") nchan_ave = 32 nchan = 192 for schan in range(0, nchan, nchan_ave): max_chan = min(nchan, schan + nchan_ave) bv = create_blockvisibility_from_uvfits(uvfitsfile, range(schan, max_chan))[0] vis = convert_blockvisibility_to_visibility(bv) from rascil.processing_components.visibility.operations import convert_visibility_to_stokesI vis = convert_visibility_to_stokesI(vis) model = create_image_from_visibility( vis, npixel=256, polarisation_frame=PolarisationFrame('stokesI')) dirty, sumwt = invert_2d(vis, model, context='2d') assert (numpy.max(numpy.abs(dirty.data))) > 0.0 assert dirty.shape == (nchan_ave, 1, 256, 256) if self.doplot: import matplotlib.pyplot as plt from rascil.processing_components.image.operations import show_image show_image(dirty) plt.show(block=False) if self.persist: export_image_to_fits( dirty, '%s/test_visibility_uvfits_dirty.fits' % self.dir)
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 test_create_voltage_patterns_illumination(self): self.createVis(freq=1.4e9) cellsize = 8 * numpy.pi / 180.0 / 280 model = create_image_from_visibility(self.vis, npixel=512, cellsize=cellsize, override_cellsize=False) plt.clf() fig, axs = plt.subplots(5, 5, gridspec_kw={'hspace': 0, 'wspace': 0}) # (r ** 2 + rho * (dx * dy) + diff * (dx ** 2 - dy ** 2)) for irho, rho in enumerate([-0.1, -0.05, 0.0, 0.05, 0.1]): for idiff, diff in enumerate([-0.2, -0.15, -0.1, -0.05, 0.0]): vp = create_vp_generic_numeric(model, pointingcentre=None, diameter=15.0, blockage=0.0, taper='gaussian', edge=0.03162278, padding=2, use_local=True, rho=rho, diff=diff) vp_data = vp.data vp.data = numpy.real(vp_data) if self.persist: export_image_to_fits( vp, "%s/test_voltage_pattern_real_%s_rho%.3f_diff%.3f.fits" % (self.dir, "MID_TAPER", rho, diff)) ax = axs[irho, idiff] ax.imshow(vp.data[0, 0]) #, vmax=0.1, vmin=-0.01) ax.axis('off') plt.show()
def test_get_frequency_map_different_channel(self): self.model = create_image_from_visibility(self.vis, npixel=128, cellsize=0.001, frequency=self.startfrequency, nchan=3, channel_bandwidth=2e7) spectral_mode, vfrequency_map = get_frequency_map(self.vis, self.model) assert numpy.max(vfrequency_map) == self.model.nchan - 1 assert spectral_mode == 'channel'
def test_create_voltage_patterns_zernike(self): self.createVis(freq=1.4e9) cellsize = 8 * numpy.pi / 180.0 / 280 model = create_image_from_visibility(self.vis, npixel=512, cellsize=cellsize, override_cellsize=False) plt.clf() fig, axs = plt.subplots(7, 7, gridspec_kw={'hspace': 0, 'wspace': 0}) for noll in range(1, 50): zernikes = [{'coeff': 1.0, 'noll': noll}] vp = create_vp_generic_numeric(model, pointingcentre=None, diameter=15.0, blockage=0.0, taper='gaussian', edge=0.03162278, zernikes=zernikes, padding=2, use_local=True) vp_data = vp.data vp.data = numpy.real(vp_data) if self.persist: export_image_to_fits( vp, "%s/test_voltage_pattern_real_%s_NOLL%d.fits" % (self.dir, 'MID_ZERNIKES', noll))
def actualSetUp(self, time=None, frequency=None, dospectral=False, dopol=False): self.lowcore = create_named_configuration('LOWBD2', rmax=600) 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=self.npixel, cellsize=0.0005, nchan=len(self.frequency), polarisation_frame=self.image_pol)
def test_get_frequency_map_channel(self): self.model = create_image_from_visibility(self.vis, npixel=128, cellsize=0.001, nchan=self.vnchan, frequency=self.startfrequency) spectral_mode, vfrequency_map = get_frequency_map(self.vis, self.model) assert numpy.max(vfrequency_map) == self.model.nchan - 1 assert numpy.min(vfrequency_map) == 0 assert spectral_mode == 'channel'
def test_create_voltage_patterns(self): self.createVis() for telescope in ['VLA', 'ASKAP', 'LOW']: model = create_image_from_visibility(self.vis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False) beam = create_vp(model, telescope=telescope) assert numpy.max(numpy.abs(beam.data.real)) > 0.0 assert numpy.max(numpy.abs(beam.data.imag)) < 1e-15, numpy.max( numpy.abs(beam.data.imag))
def test_create_primary_beams_RADEC(self): self.createVis() for telescope in ['VLA', 'ASKAP', 'MID', 'LOW']: model = create_image_from_visibility(self.vis, cellsize=self.cellsize, npixel=self.npixel, override_cellsize=False) beam = create_pb(model, telescope=telescope, use_local=False) assert numpy.max(beam.data) > 0.0 if self.persist: export_image_to_fits( beam, "%s/test_primary_beam_RADEC_%s.fits" % (self.dir, telescope))
def test_convert_weight(self): cvis = convert_blockvisibility_to_visibility(self.blockvis) model = create_image_from_visibility( vis=cvis, npixel=256, cellsize=0.001, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame('stokesI')) cvis = weight_visibility(cvis, model) assert numpy.mean(cvis.data['imaging_weight']) < 1.0 assert numpy.std(cvis.data['imaging_weight']) > 0.0 dvis = decoalesce_visibility(cvis) assert numpy.mean(dvis.data['imaging_weight']) < 1.0 assert numpy.std(dvis.data['imaging_weight']) > 0.0 assert dvis.nvis == self.blockvis.nvis
def test_map_create_pb(self): self.createVis(config='LOWBD2', rmax=1000.0) model = create_image_from_visibility(self.vis, cellsize=0.001, override_cellsize=False) beam = image_rsexecute_map_workflow(model, create_pb, facets=4, pointingcentre=self.phasecentre, telescope='MID') beam = rsexecute.compute(beam, sync=True) assert numpy.max(beam.data) > 0.0 if self.persist: export_image_to_fits( beam, "%s/test_image_rsexecute_scatter_gather.fits" % (self.dir))
def test_create_voltage_patterns_MID(self): self.createVis(freq=1.4e9) model = create_image_from_visibility(self.vis, npixel=self.npixel, cellsize=self.cellsize, override_cellsize=False) for telescope in ['MID', 'MID_FEKO_B1', 'MID_FEKO_B2', 'MID_FEKO_Ku']: beam = create_vp(model, telescope=telescope, padding=4) beam_data = beam.data beam.data = numpy.real(beam_data) beam.wcs.wcs.crval[0] = 0.0 beam.wcs.wcs.crval[1] = 90.0 if self.persist: export_image_to_fits( beam, "%s/test_voltage_pattern_real_zenith_%s.fits" % (self.dir, telescope))
def create_unittest_model(vis, model_pol, npixel=None, cellsize=None, nchan=1): advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02, facets=1, wprojection_planes=1, oversampling_synthesised_beam=4.0) if cellsize is None: cellsize = advice['cellsize'] if npixel is None: npixel = advice['npixels2'] model = create_image_from_visibility(vis, npixel=npixel, cellsize=cellsize, nchan=nchan, polarisation_frame=model_pol) return model
def setUp(self): from rascil.data_models.parameters import rascil_path, rascil_data_path self.dir = rascil_path('test_results') self.vnchan = 7 self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) 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 * [(1.0 - 1.0e-7) * (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=128, cellsize=0.001, nchan=self.vnchan, frequency=self.startfrequency)
def test_create_voltage_patterns_MID_GAUSS(self): self.createVis() model = create_image_from_visibility(self.vis, npixel=self.npixel, cellsize=self.cellsize, override_cellsize=False) for telescope in ['MID_GAUSS']: beam = create_vp(model, telescope=telescope, padding=4) beam_data = beam.data beam.data = numpy.real(beam_data) if self.persist: export_image_to_fits( beam, "%s/test_voltage_pattern_real_%s.fits" % (self.dir, telescope)) beam.data = numpy.imag(beam_data) if self.persist: export_image_to_fits( beam, "%s/test_voltage_pattern_imag_%s.fits" % (self.dir, telescope))
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'))
def test_create_voltage_patterns_MID_rotate(self): self.createVis(freq=1.4e9) model = create_image_from_visibility( self.vis, npixel=self.npixel, cellsize=self.cellsize, polarisation_frame=PolarisationFrame("stokesIQUV"), override_cellsize=False) for telescope in ['MID_FEKO_B1', 'MID_FEKO_B2', 'MID_FEKO_Ku']: beam = create_vp(telescope=telescope) beam = scale_and_rotate_image(beam, scale=[1.2, 0.8]) self.persist = True if self.persist: export_image_to_fits( beam, "%s/test_voltage_pattern_real_prerotate_%s.fits" % (self.dir, telescope)) beam_radec = convert_azelvp_to_radec(beam, model, numpy.pi / 4.0) beam_data = beam_radec.data beam_radec.data = numpy.real(beam_data) if self.persist: export_image_to_fits( beam_radec, "%s/test_voltage_pattern_real_rotate_%s.fits" % (self.dir, telescope))
results_dir = rascil_path('test_results') # Test requires that casa be installed try: bvt = create_blockvisibility_from_ms(rascil_data_path('vis/sim-2.ms'), channum=[35, 36, 37, 38, 39])[0] bvt.configuration.diameter[...] = 35.0 vt = convert_blockvisibility_to_visibility(bvt) vt = convert_visibility_to_stokes(vt) cellsize = 20.0 * numpy.pi / (180.0 * 3600.0) npixel = 512 model = create_image_from_visibility( vt, cellsize=cellsize, npixel=npixel, polarisation_frame=PolarisationFrame('stokesIQUV')) dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0] psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0] export_image_to_fits( dirty, '%s/compare_imaging_sim2_dirty.fits' % (results_dir)) export_image_to_fits( psf, '%s/compare_imaging_sim2_psf.fits' % (results_dir)) # Deconvolve using clean comp, residual = deconvolve_cube(dirty, psf,
if show: show_image(psf, cm='gray_r', title='%s PSF' % basename, vmin=-0.01, vmax=0.1) plt.savefig('PSF_rascil.png') plt.show(block=False) del psf_list del future_psf_list # ### Calculate the voltage pattern without pointing errors vp = create_image_from_visibility(vis_list0, npixel=pb_npixel, frequency=frequency, nchan=nfreqwin, cellsize=pb_cellsize, phasecentre=phasecentre, override_cellsize=False) # Optionally show the primary beam, with components if the image is in RADEC coords if show: if pbtype == "MID_GRASP": pb = create_pb(vp, "MID_GAUSS", pointingcentre=phasecentre, use_local=False) else: pb = create_pb(vp, pbtype, pointingcentre=phasecentre, use_local=False)
phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') config = create_named_configuration('MIDR5', rmax=rmax) times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0 nants = config.xyz.shape[0] assert nants > 1 assert len(config.names) == nants assert len(config.mount) == nants phasecentre = SkyCoord(ra=+15 * u.deg, dec=dec * u.deg, frame='icrs', equinox='J2000') vis = create_visibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) cellsize = 8 * numpy.pi / 180.0 / 280 model = create_image_from_visibility(vis, npixel=512, cellsize=cellsize, override_cellsize=False) # These are the nolls that maintain left-right symmetry plt.clf() fig, axs = plt.subplots(4, 4, gridspec_kw={'hspace': 0, 'wspace': 0}) ntrials = 16 zernikes = list() default_vp = create_vp_generic_numeric(model, pointingcentre=None, diameter=15.0, blockage=0.0, taper='gaussian', edge=0.03162278, padding=2, use_local=True) key_nolls = [3, 5, 6, 7] for noll in key_nolls: zernike = {'coeff': 1.0, 'noll': noll} zernike['vp'] = create_vp_generic_numeric(model, pointingcentre=None, diameter=15.0, blockage=0.0, taper='gaussian',
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: predict_skycomponent_visibility(vt, comps) else: predict_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