def test_divide_visibility(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.vis.data['vis'][..., :] = [2.0 + 0.0j, 0.0j, 0.0j, 2.0 + 0.0j] self.othervis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) self.othervis.data['vis'][..., :] = [ 1.0 + 0.0j, 0.0j, 0.0j, 1.0 + 0.0j ] self.ratiovis = divide_visibility(self.vis, self.othervis) assert self.ratiovis.nvis == self.vis.nvis assert numpy.max(numpy.abs(self.ratiovis.vis)) == 2.0, numpy.max( numpy.abs(self.ratiovis.vis))
def test_elevation_block(self): self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=+15.0 * u.deg, frame='icrs', equinox='J2000') self.times = (numpy.pi / 43200.0) * numpy.arange(-43200, +43200, 3600.0) self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV"), elevation_limit=numpy.pi * 15.0/180.0) n_elevation_limit = len(numpy.unique(self.vis.time)) self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV"), elevation_limit=None) assert len(numpy.unique(self.vis.time)) >= n_elevation_limit
def test_readwriteblockvisibility(self): self.vis = create_blockvisibility( 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) export_blockvisibility_to_hdf5( self.vis, '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir) newvis = import_blockvisibility_from_hdf5( '%s/test_data_model_helpers_blockvisibility.hdf' % self.dir) for key in self.vis.data.dtype.fields: assert numpy.max( numpy.abs(newvis.data[key] - self.vis.data[key])) < 1e-15 assert numpy.array_equal(newvis.frequency, self.vis.frequency) assert newvis.data.shape == self.vis.data.shape assert numpy.max(numpy.abs(self.vis.vis - newvis.vis)) < 1e-15 assert numpy.max(numpy.abs(self.vis.uvw - newvis.uvw)) < 1e-15 assert numpy.abs(newvis.configuration.location.x.value - self.vis.configuration.location.x.value) < 1e-15 assert numpy.abs(newvis.configuration.location.y.value - self.vis.configuration.location.y.value) < 1e-15 assert numpy.abs(newvis.configuration.location.z.value - self.vis.configuration.location.z.value) < 1e-15 assert numpy.max( numpy.abs(newvis.configuration.xyz - self.vis.configuration.xyz)) < 1e-15
def setUp(self): from data_models.parameters import arl_path self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = arl_path('test_results') 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_blockvisibility( 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.mask = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.frequency) self.mask.data[self.mask.data > 0.1] = 1.0 self.mask.data[self.mask.data <= 0.1] = 0.0
def setUp(self): from data_models.parameters import arl_path dec = -40.0 * u.deg self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = arl_path('test_results') self.times = numpy.linspace(-10.0, 10.0, 3) * numpy.pi / (3600.0 * 12.0) self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e6]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=dec, frame='icrs', equinox='J2000') self.vis = create_blockvisibility( 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_image( npixel=512, cellsize=0.000015, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def test_readwritepointingtable(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) pt = create_pointingtable_from_blockvisibility(self.vis, timeslice='auto') pt = simulate_pointingtable(pt, pointing_error=0.1) config = { "buffer": { "directory": self.dir }, "pointingtable": { "name": "test_bufferpointingtable.hdf", "data_model": "PointingTable" } } bdm = BufferPointingTable(config["buffer"], config["pointingtable"], pt) bdm.sync() new_bdm = BufferPointingTable(config["buffer"], config["pointingtable"]) new_bdm.sync() newpt = bdm.memory_data_model assert pt.data.shape == newpt.data.shape assert numpy.max(numpy.abs(pt.pointing - newpt.pointing)) < 1e-15
def test_readwriteskymodel_no_image(self): vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_gaintable_from_blockvisibility(vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1) sm = SkyModel(components=[self.comp], gaintable=gt) config = { "buffer": { "directory": self.dir }, "skymodel": { "name": "test_bufferskymodel.hdf", "data_model": "SkyModel" } } bdm = BufferSkyModel(config["buffer"], config["skymodel"], sm) bdm.sync() new_bdm = BufferSkyModel(config["buffer"], config["skymodel"]) new_bdm.sync() newsm = bdm.memory_data_model assert newsm.components[0].flux.shape == self.comp.flux.shape assert newsm.gaintable.data.shape == gt.data.shape
def setUp(self): from data_models.parameters import arl_path self.doplot = True self.midcore = create_named_configuration('MID', rmax=100.0) self.nants = len(self.midcore.names) self.dir = arl_path('test_results') self.ntimes = 100 interval = 10.0 self.times = numpy.arange(0.0, float(self.ntimes)) * interval self.times *= numpy.pi / 43200.0 self.frequency = numpy.array([1.4e9]) self.channel_bandwidth = numpy.array([1e7]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_blockvisibility(self.midcore, 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_image(npixel=512, cellsize=0.001, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def ingest_unittest_visibility(config, frequency, channel_bandwidth, times, vis_pol, phasecentre, block=False, zerow=False): if block: vt = create_blockvisibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol, zerow=zerow) else: vt = create_visibility(config, times, frequency, channel_bandwidth=channel_bandwidth, phasecentre=phasecentre, weight=1.0, polarisation_frame=vis_pol, zerow=zerow) vt.data['vis'][...] = 0.0 return vt
def test_readwritegaintable(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1) config = { "buffer": { "directory": self.dir }, "gaintable": { "name": "test_buffergaintable.hdf", "data_model": "GainTable" } } bdm = BufferGainTable(config["buffer"], config["gaintable"], gt) bdm.sync() new_bdm = BufferGainTable(config["buffer"], config["gaintable"]) new_bdm.sync() newgt = bdm.memory_data_model assert gt.data.shape == newgt.data.shape assert numpy.max(numpy.abs(gt.gain - newgt.gain)) < 1e-15
def actualSetUp(self, times=None): if times is not None: self.times = times self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.gaintable = create_gaintable_from_blockvisibility(self.vis)
def test_phase_rotation_block(self): self.vis = create_blockvisibility(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_blockvisibility(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=3e-6) assert_allclose(rotatedvis.uvw, vismodel2.uvw, rtol=3e-6)
def create_blockvisibility_iterator(config: Configuration, times: numpy.array, frequency: numpy.array, channel_bandwidth, phasecentre: SkyCoord, weight: float = 1, polarisation_frame=PolarisationFrame('stokesI'), integration_time=1.0, number_integrations=1, predict=predict_2d, model=None, components=None, phase_error=0.0, amplitude_error=0.0, sleep=0.0, **kwargs): """ Create a sequence of Visibilities and optionally predicting and coalescing This is useful mainly for performing large simulations. Do something like:: vis_iter = create_blockvisibility_iterator(config, times, frequency, channel_bandwidth, phasecentre=phasecentre, weight=1.0, integration_time=30.0, number_integrations=3) for i, vis in enumerate(vis_iter): if i == 0: fullvis = vis else: fullvis = append_visibility(fullvis, vis) :param config: Configuration of antennas :param times: hour angles in radians :param frequency: frequencies (Hz] Shape [nchan] :param weight: weight of a single sample :param phasecentre: phasecentre of observation :param npol: Number of polarizations :param integration_time: Integration time ('auto' or value in s) :param number_integrations: Number of integrations to be created at each time. :param model: Model image to be inserted :param components: Components to be inserted :param sleep_time: Time to sleep between yields :return: Visibility """ for time in times: actualtimes = time + numpy.arange(0, number_integrations) * integration_time * numpy.pi / 43200.0 bvis = create_blockvisibility(config, actualtimes, frequency=frequency, phasecentre=phasecentre, weight=weight, polarisation_frame=polarisation_frame, integration_time=integration_time, channel_bandwidth=channel_bandwidth) if model is not None: vis = predict(bvis, model, **kwargs) bvis = convert_visibility_to_blockvisibility(vis) if components is not None: bvis = predict_skycomponent_visibility(bvis, components) # Add phase errors if phase_error > 0.0 or amplitude_error > 0.0: gt = create_gaintable_from_blockvisibility(bvis) gt = simulate_gaintable(gt=gt, phase_error=phase_error, amplitude_error=amplitude_error) bvis = apply_gaintable(bvis, gt) import time time.sleep(sleep) yield bvis
def test_convert_blockvisibility(self): self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, channel_bandwidth=self.channel_bandwidth) vis = convert_blockvisibility_to_visibility(self.vis) assert vis.nvis == len(vis.time) assert numpy.unique(vis.time).size == self.vis.time.size # pylint: disable=no-member
def setUp(self): self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 30 * 3.76, 3.76) df = 27343.75000 self.frequency = numpy.array([1e8 - df, 1e8, 1e8 + df]) self.channel_bandwidth = numpy.array([27343.75, 27343.75, 27343.75]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.blockvis = create_blockvisibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth, meta={"ARL":0.9})
def test_coalesce_decoalesce_singletime(self): self.times = numpy.array([0.0]) self.blockvis = create_blockvisibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) # Fill in the vis values so each can be uniquely identified self.blockvis.data['vis'] = range(self.blockvis.nvis) cvis = coalesce_visibility(self.blockvis, time_coal=1.0) assert numpy.min(cvis.frequency) == numpy.min(self.frequency) assert numpy.min(cvis.frequency) > 0.0 dvis = decoalesce_visibility(cvis) assert dvis.nvis == self.blockvis.nvis
def test_readwritegaintable(self): self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.1) export_gaintable_to_hdf5(gt, '%s/test_data_model_helpers_gaintable.hdf' % self.dir) newgt = import_gaintable_from_hdf5('%s/test_data_model_helpers_gaintable.hdf' % self.dir) assert gt.data.shape == newgt.data.shape assert numpy.max(numpy.abs(gt.gain - newgt.gain)) < 1e-15
def test_addnoise_blockvisibility(self): self.vis = create_blockvisibility( self.config, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesIQUV'), channel_bandwidth=self.channel_bandwidth) original = copy_visibility(self.vis) self.vis = addnoise_visibility(self.vis) actual = numpy.std(numpy.abs(self.vis.vis - original.vis)) assert abs(actual - 0.01077958403015586) < 1e-4, actual
def test_create_generic_blockvisibility_workflow(self): self.blockvis = [create_blockvisibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, channel_bandwidth=self.channel_bandwidth, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'))] self.blockvis = generic_blockvisibility_workflow(predict_skycomponent_visibility, vis_list=self.blockvis, sc=self.comp)[0] self.blockvis = arlexecute.compute(self.blockvis, sync=True) arlexecute.close() assert numpy.max(numpy.abs(self.blockvis[0].vis)) > 0.0
def test_phase_rotation_inverse_block(self): self.vis = create_blockvisibility(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_readwriteskymodel(self): self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) im = create_test_image() gt = create_gaintable_from_blockvisibility(self.vis, timeslice='auto') sm = SkyModel(components=[self.comp], image=im, gaintable=gt) export_skymodel_to_hdf5(sm, '%s/test_data_model_helpers_skymodel.hdf' % self.dir) newsm = import_skymodel_from_hdf5('%s/test_data_model_helpers_skymodel.hdf' % self.dir) assert newsm.components[0].flux.shape == self.comp.flux.shape assert newsm.image.data.shape == im.data.shape assert numpy.max(numpy.abs(newsm.image.data - im.data)) < 1e-15
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear', f=None, vnchan=1): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.linspace(0.0, 30.0, 3) self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) if vnchan > 1: self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) else: self.channel_bandwidth = numpy.array([2e7]) if f is None: f = [100.0, 50.0, -10.0, 40.0] if sky_pol_frame == 'stokesI': f = [100.0] self.flux = numpy.outer( numpy.array( [numpy.power(freq / 1e8, -0.7) for freq in self.frequency]), f) # The phase centre is absolute and the component is specified relative (for now). # This means that the component should end up at the position phasecentre+compredirection self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.comp = Skycomponent( direction=self.compabsdirection, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame(sky_pol_frame)) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, channel_bandwidth=self.channel_bandwidth, weight=1.0, polarisation_frame=PolarisationFrame(data_pol_frame)) self.vis = predict_skycomponent_visibility(self.vis, self.comp)
def test_readwritepointingtable(self): self.vis = create_blockvisibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0) gt = create_pointingtable_from_blockvisibility(self.vis, timeslice='auto') gt = simulate_pointingtable(gt, pointing_error=0.001) export_pointingtable_to_hdf5(gt, '%s/test_data_model_helpers_pointingtable.hdf' % self.dir) newgt = import_pointingtable_from_hdf5('%s/test_data_model_helpers_pointingtable.hdf' % self.dir) for key in gt.data.dtype.fields: assert numpy.max(numpy.abs(newgt.data[key] - gt.data[key])) < 1e-15 assert gt.data.shape == newgt.data.shape assert numpy.max(numpy.abs(gt.pointing - newgt.pointing)) < 1e-15
def test_predict_sky_components_coalesce(self): sc = create_low_test_skycomponents_from_gleam(flux_limit=10.0, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, kind='cubic', phasecentre=SkyCoord("17h20m31s", "-00d58m45s"), radius=0.1) self.config = create_named_configuration('LOWBD2-CORE') self.phasecentre = SkyCoord("17h20m31s", "-00d58m45s") sampling_time = 3.76 self.times = numpy.arange(0.0, + 300 * sampling_time, sampling_time) self.vis = create_blockvisibility(self.config, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) self.vis = predict_skycomponent_visibility(self.vis, sc) cvt = convert_blockvisibility_to_visibility(self.vis) assert cvt.cindex is not None
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 self.blockvis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0) self.blockvis.data['vis'][...] = 1.0
def test_readwriteblockvisibility(self): self.vis = create_blockvisibility( self.midcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("linear"), weight=1.0, meta={"ARL": 0.0}) self.vis = predict_skycomponent_visibility(self.vis, self.comp) config = { "buffer": { "directory": self.dir }, "vislist": { "name": "test_bufferblockvisibility.hdf", "data_model": "BlockVisibility" } } bdm = BufferBlockVisibility(config["buffer"], config["vislist"], self.vis) bdm.sync() new_bdm = BufferBlockVisibility(config["buffer"], config["vislist"]) new_bdm.sync() newvis = bdm.memory_data_model assert isinstance(newvis, BlockVisibility) assert numpy.array_equal(newvis.frequency, self.vis.frequency) assert newvis.data.shape == self.vis.data.shape assert numpy.max(numpy.abs(self.vis.vis - newvis.vis)) < 1e-15 assert numpy.max(numpy.abs(self.vis.uvw - newvis.uvw)) < 1e-15 assert numpy.abs(newvis.configuration.location.x.value - self.vis.configuration.location.x.value) < 1e-15 assert numpy.abs(newvis.configuration.location.y.value - self.vis.configuration.location.y.value) < 1e-15 assert numpy.abs(newvis.configuration.location.z.value - self.vis.configuration.location.z.value) < 1e-15 assert numpy.max( numpy.abs(newvis.configuration.xyz - self.vis.configuration.xyz)) < 1e-15 assert newvis.meta == self.vis.meta
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear'): self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0) vnchan = 3 self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) # Define the component and give it some spectral behaviour f = numpy.array([100.0, 20.0, -10.0, 1.0]) self.flux = numpy.array([f, 0.8 * f, 0.6 * f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') if sky_pol_frame == 'stokesI': self.flux = self.flux[:, 0][:, numpy.newaxis] self.comp = Skycomponent( direction=self.compabsdirection, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame(sky_pol_frame)) self.vis = create_blockvisibility( self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, channel_bandwidth=self.channel_bandwidth, weight=1.0, polarisation_frame=PolarisationFrame(data_pol_frame)) self.vis = predict_skycomponent_visibility(self.vis, self.comp)
def actualSetup(self, vnchan=1, doiso=True, ntimes=5, flux_limit=2.0, zerow=True, fixed=False): nfreqwin = vnchan rmax = 300.0 npixel = 512 cellsize = 0.001 frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin) if nfreqwin > 1: channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]]) else: channel_bandwidth = [0.4e8] times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes) phasecentre = SkyCoord(ra=-60.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') lowcore = create_named_configuration('LOWBD2', rmax=rmax) block_vis = create_blockvisibility( lowcore, times, frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI"), zerow=zerow) block_vis.data['uvw'][..., 2] = 0.0 self.beam = create_image_from_visibility( block_vis, npixel=npixel, frequency=[numpy.average(frequency)], nchan=nfreqwin, channel_bandwidth=[numpy.sum(channel_bandwidth)], cellsize=cellsize, phasecentre=phasecentre) self.components = create_low_test_skycomponents_from_gleam( flux_limit=flux_limit, phasecentre=phasecentre, frequency=frequency, polarisation_frame=PolarisationFrame('stokesI'), radius=npixel * cellsize) self.beam = create_low_test_beam(self.beam) self.components = apply_beam_to_skycomponent(self.components, self.beam, flux_limit=flux_limit) self.vis = copy_visibility(block_vis, zero=True) gt = create_gaintable_from_blockvisibility(block_vis, timeslice='auto') for i, sc in enumerate(self.components): if sc.flux[0, 0] > 10: sc.flux[...] /= 10.0 component_vis = copy_visibility(block_vis, zero=True) gt = simulate_gaintable(gt, amplitude_error=0.0, phase_error=0.1, seed=None) component_vis = predict_skycomponent_visibility(component_vis, sc) component_vis = apply_gaintable(component_vis, gt) self.vis.data['vis'][...] += component_vis.data['vis'][...] # Do an isoplanatic selfcal self.model_vis = copy_visibility(self.vis, zero=True) self.model_vis = predict_skycomponent_visibility( self.model_vis, self.components) if doiso: gt = solve_gaintable(self.vis, self.model_vis, phase_only=True, timeslice='auto') self.vis = apply_gaintable(self.vis, gt, inverse=True) self.model_vis = convert_blockvisibility_to_visibility(self.model_vis) self.model_vis, _, _ = weight_visibility(self.model_vis, self.beam) self.dirty_model, sumwt = invert_function(self.model_vis, self.beam, context='2d') export_image_to_fits(self.dirty_model, "%s/test_skymodel-model_dirty.fits" % self.dir) lvis = convert_blockvisibility_to_visibility(self.vis) lvis, _, _ = weight_visibility(lvis, self.beam) dirty, sumwt = invert_function(lvis, self.beam, context='2d') if doiso: export_image_to_fits( dirty, "%s/test_skymodel-initial-iso-residual.fits" % self.dir) else: export_image_to_fits( dirty, "%s/test_skymodel-initial-noiso-residual.fits" % self.dir) self.skymodels = [ SkyModel(components=[cm], fixed=fixed) for cm in self.components ]
def test_export_ms(self): if run_ms_tests == False: return msoutfile = arl_path("data/vis/Test_output.ms") from astropy.coordinates import SkyCoord from astropy import units as u from wrappers.serial.image.operations import show_image, export_image_to_fits from wrappers.serial.simulation.configurations import create_named_configuration from wrappers.serial.simulation.testing_support import create_test_image from wrappers.serial.imaging.base import create_image_from_visibility from wrappers.serial.imaging.base import advise_wide_field from workflows.serial.imaging.imaging_serial import invert_list_serial_workflow, predict_list_serial_workflow from data_models.polarisation import PolarisationFrame lowr3 = create_named_configuration('LOWBD2', rmax=750.0) times = numpy.zeros([1]) frequency = numpy.array([1e8]) channelbandwidth = numpy.array([1e6]) phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000') bvis = create_blockvisibility(lowr3, times, frequency, phasecentre=phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=channelbandwidth) vt = convert_blockvisibility_to_visibility(bvis) advice = advise_wide_field(vt, guard_band_image=3.0, delA=0.1, facets=1, wprojection_planes=1, oversampling_synthesised_beam=4.0) cellsize = advice['cellsize'] m31image = create_test_image(frequency=frequency, cellsize=cellsize) nchan, npol, ny, nx = m31image.data.shape m31image.wcs.wcs.crval[0] = vt.phasecentre.ra.deg m31image.wcs.wcs.crval[1] = vt.phasecentre.dec.deg m31image.wcs.wcs.crpix[0] = float(nx // 2) m31image.wcs.wcs.crpix[1] = float(ny // 2) vt = predict_list_serial_workflow([vt], [m31image], context='2d')[0] # uvdist = numpy.sqrt(vt.data['uvw'][:, 0] ** 2 + vt.data['uvw'][:, 1] ** 2) # # model = create_image_from_visibility(vt, cellsize=cellsize, npixel=512) # dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0] # psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0] # # show_image(dirty) # print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" % (dirty.data.max(), dirty.data.min(), sumwt)) # # print("Max, min in PSF = %.6f, %.6f, sumwt = %f" % (psf.data.max(), psf.data.min(), sumwt)) # results_dir="/Users/f.wang" # export_image_to_fits(dirty, '%s/imaging_dirty.fits' % (results_dir)) # export_image_to_fits(psf, '%s/imaging_psf.fits' % (results_dir)) v = convert_visibility_to_blockvisibility(vt) vis_list=[] vis_list.append(v) export_blockvisility_to_ms(msoutfile, vis_list,source_name='M31')
ntimes = 11 rmax = 300.0 frequency = numpy.linspace(0.8e8, 1.2e8, nfreqwin) channel_bandwidth = numpy.array(nfreqwin * [frequency[1] - frequency[0]]) times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes) phasecentre = SkyCoord(ra=+30.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') lowcore = create_named_configuration('LOWBD2-CORE', rmax=rmax) block_vis = create_blockvisibility( lowcore, times, frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) wprojection_planes = 1 advice = advise_wide_field(block_vis, guard_band_image=4.0, delA=0.02, wprojection_planes=wprojection_planes) vis_slices = advice['vis_slices'] npixel = advice['npixels2'] cellsize = advice['cellsize'] gleam_model = create_low_test_image_from_gleam(