def test_readwritegaintable(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) 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 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 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_readwriteflagtable(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) ft = create_flagtable_from_blockvisibility(self.vis, timeslice='auto') config = { "buffer": { "directory": self.dir }, "flagtable": { "name": "test_bufferflagtable.hdf", "data_model": "FlagTable" } } bdm = BufferFlagTable(config["buffer"], config["flagtable"], ft) bdm.sync() new_bdm = BufferFlagTable(config["buffer"], config["flagtable"]) new_bdm.sync() newft = bdm.memory_data_model assert ft.data.shape == newft.data.shape assert numpy.max(numpy.abs(ft.flags - newft.flags)) < 1e-15
def test_create_flagtable(self): bvis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, polarisation_frame=self.polarisation_frame, weight=1.0) ft = create_flagtable_from_blockvisibility(bvis) print(ft) assert len(ft.data) == len(bvis.data)
def test_create_flagtable_from_rows(self): bvis = create_blockvisibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, polarisation_frame=self.polarisation_frame, phasecentre=self.phasecentre, weight=1.0) ft = create_flagtable_from_blockvisibility(bvis) rows = ft.time > 150.0 ft = create_flagtable_from_blockvisibility(bvis) selected_ft = create_flagtable_from_rows(ft, rows) assert len(selected_ft.time) == numpy.sum(numpy.array(rows))
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={"RASCIL": 0.0}) self.vis = dft_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
equinox='J2000') low = create_named_configuration('LOWBD2', rmax=rmax) print('Configuration has %d stations' % len(low.data)) centre = numpy.mean(low.xyz, axis=0) distance = numpy.hypot(low.xyz[:, 0] - centre[0], low.xyz[:, 1] - centre[1], low.xyz[:, 2] - centre[2]) lowouter = low.data[distance > 1000.0][::6] lowcore = low.data[distance < 1000.0][::3] low.data = numpy.hstack((lowcore, lowouter)) block_vis = create_blockvisibility( low, times, frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI"), zerow=True) vis = convert_blockvisibility_to_visibility(block_vis) advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02) cellsize = advice['cellsize'] vis_slices = advice['vis_slices'] npixel = advice['npixels2'] small_model = create_image_from_visibility(block_vis, npixel=512, frequency=frequency,
def actualSetup(self, nsources=None, nvoronoi=None): # Set up the observation: 10 minutes at transit, with 10s integration. # Skip 5/6 points to avoid outstation redundancy nfreqwin = 1 ntimes = 3 self.rmax = 2500.0 dec = -40.0 * u.deg frequency = [1e8] channel_bandwidth = [0.1e8] times = numpy.linspace(-10.0, 10.0, ntimes) * numpy.pi / (3600.0 * 12.0) phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=dec, frame='icrs', equinox='J2000') low = create_named_configuration('LOWBD2', rmax=self.rmax) centre = numpy.mean(low.xyz, axis=0) distance = numpy.hypot(low.xyz[:, 0] - centre[0], low.xyz[:, 1] - centre[1], low.xyz[:, 2] - centre[2]) lowouter = low.data[distance > 1000.0][::6] lowcore = low.data[distance < 1000.0][::3] low.data = numpy.hstack((lowcore, lowouter)) blockvis = create_blockvisibility(low, times, frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI"), zerow=True) vis = convert_blockvisibility_to_visibility(blockvis) advice = advise_wide_field(vis, guard_band_image=2.0, delA=0.02) cellsize = advice['cellsize'] npixel = 512 small_model = create_image_from_visibility( blockvis, npixel=512, frequency=frequency, nchan=nfreqwin, cellsize=cellsize, phasecentre=phasecentre) vis.data['imaging_weight'][...] = vis.data['weight'][...] vis = weight_list_serial_workflow([vis], [small_model])[0] vis = taper_list_serial_workflow([vis], 3 * cellsize)[0] blockvis = convert_visibility_to_blockvisibility(vis) # ### Generate the model from the GLEAM catalog, including application of the primary beam. beam = create_image_from_visibility(blockvis, npixel=npixel, frequency=frequency, nchan=nfreqwin, cellsize=cellsize, phasecentre=phasecentre) beam = create_low_test_beam(beam, use_local=False) flux_limit = 0.5 original_gleam_components = create_low_test_skycomponents_from_gleam(flux_limit=flux_limit, phasecentre=phasecentre, frequency=frequency, polarisation_frame=PolarisationFrame( 'stokesI'), radius=0.15) all_components = apply_beam_to_skycomponent(original_gleam_components, beam) all_components = filter_skycomponents_by_flux(all_components, flux_min=flux_limit) voronoi_components = filter_skycomponents_by_flux(all_components, flux_min=1.5) def max_flux(elem): return numpy.max(elem.flux) voronoi_components = sorted(voronoi_components, key=max_flux, reverse=True) if nsources is not None: all_components = [all_components[0]] if nvoronoi is not None: voronoi_components = [voronoi_components[0]] self.screen = import_image_from_fits(rascil_data_path('models/test_mpc_screen.fits')) all_gaintables = create_gaintable_from_screen(blockvis, all_components, self.screen) gleam_skymodel_noniso = [SkyModel(components=[all_components[i]], gaintable=all_gaintables[i]) for i, sm in enumerate(all_components)] # ### Now predict the visibility for each skymodel and apply the gaintable for that skymodel, # returning a list of visibilities, one for each skymodel. We then sum these to obtain # the total predicted visibility. All images and skycomponents in the same skymodel # get the same gaintable applied which means that in this case each skycomponent has a separate gaintable. self.all_skymodel_noniso_vis = convert_blockvisibility_to_visibility(blockvis) ngroup = 8 future_vis = rsexecute.scatter(self.all_skymodel_noniso_vis) chunks = [gleam_skymodel_noniso[i:i + ngroup] for i in range(0, len(gleam_skymodel_noniso), ngroup)] for chunk in chunks: result = predict_skymodel_list_rsexecute_workflow(future_vis, chunk, context='2d', docal=True) work_vis = rsexecute.compute(result, sync=True) for w in work_vis: self.all_skymodel_noniso_vis.data['vis'] += w.data['vis'] assert numpy.max(numpy.abs(self.all_skymodel_noniso_vis.data['vis'])) > 0.0 self.all_skymodel_noniso_blockvis = convert_visibility_to_blockvisibility(self.all_skymodel_noniso_vis) # ### Remove weaker of components that are too close (0.02 rad) idx, voronoi_components = remove_neighbouring_components(voronoi_components, 0.02) model = create_image_from_visibility(blockvis, npixel=npixel, frequency=frequency, nchan=nfreqwin, cellsize=cellsize, phasecentre=phasecentre) # Use the gaintable for the brightest component as the starting gaintable all_gaintables[0].gain[...] = numpy.conjugate(all_gaintables[0].gain[...]) all_gaintables[0].gain[...] = 1.0 + 0.0j self.theta_list = initialize_skymodel_voronoi(model, voronoi_components, all_gaintables[0])