def test_plot_gaintable_to_screen(self): screen = import_image_from_fits( rascil_path('data/models/test_mpc_screen.fits')) beam = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.frequency) beam = create_low_test_beam(beam, use_local=False) gleam_components = create_low_test_skycomponents_from_gleam( flux_limit=1.0, phasecentre=self.phasecentre, frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI'), radius=0.2) pb_gleam_components = apply_beam_to_skycomponent( gleam_components, beam) actual_components = filter_skycomponents_by_flux(pb_gleam_components, flux_min=1.0) gaintables = create_gaintable_from_screen(self.vis, actual_components, screen) assert len(gaintables) == len(actual_components), len(gaintables) assert gaintables[0].gain.shape == (3, 94, 3, 1, 1), gaintables[0].gain.shape plot_gaintable_on_screen( self.vis, gaintables, plotfile=rascil_path( 'test_results/test_plot_gaintable_to_screen.png'))
def test_copy_ms(self): if run_ms_tests == False: return msfile = rascil_path("data/vis/ASKAP_example.ms") msoutfile = rascil_path("test_results/test_export_ms_ASKAP_output.ms") v = create_blockvisibility_from_ms(msfile) export_blockvisibility_to_ms( msoutfile, v) # vis_by_channel.append(integrate_visibility_by_channel(v[0]))
def setUp(self): from rascil.data_models.parameters import rascil_path self.doplot = False self.midcore = create_named_configuration('MID', rmax=300.0) self.nants = len(self.midcore.names) self.dir = rascil_path('test_results') self.ntimes = 30 self.times = numpy.linspace(-5.0, 5.0, self.ntimes) * numpy.pi / (12.0) self.frequency = numpy.array([1e9]) 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.00015, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre)
def setUp(self): rsexecute.set_client(use_dask=True) from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", True) self.verbose = True
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 setUp(self): from rascil.data_models.parameters import rascil_path self.lowcore = create_named_configuration('LOWBD2-CORE') self.dir = rascil_path('test_results') self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.image_frequency = numpy.linspace(0.9e8, 1.1e8, 5) self.component_frequency = numpy.linspace(0.8e8, 1.2e8, 7) self.channel_bandwidth = numpy.array(5*[1e7]) 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.image_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.model = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.image_frequency) self.model.data[self.model.data > 1.0] = 1.0 self.vis = predict_2d(self.vis, self.model) assert numpy.max(numpy.abs(self.vis.vis)) > 0.0 dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000') flux = [[numpy.power(f/1e8, -0.7)] for f in self.component_frequency] self.sc = create_skycomponent(direction=dphasecentre, flux=flux, frequency=self.component_frequency, polarisation_frame=PolarisationFrame('stokesI'))
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.m31image = create_test_image(cellsize=0.0001) self.cellsize = 180.0 * 0.0001 / numpy.pi
def setUp(self): rsexecute.set_client(verbose=False, memory_limit=4 * 1024 * 1024 * 1024, n_workers=4, dashboard_address=None) from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", False)
def setUp(self): from rascil.data_models.parameters import rascil_path self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = rascil_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): rsexecute.set_client(use_dask=True, processes=True, threads_per_worker=1) from rascil.data_models.parameters import rascil_path, rascil_data_path self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", False)
def setUp(self): self.persist = os.getenv("RASCIL_PERSIST", False) from rascil.data_models.parameters import rascil_path dec = -40.0 * u.deg self.lowcore = create_named_configuration('LOWBD2', rmax=300.0) self.dir = rascil_path('test_results') self.times = numpy.linspace(-10.0, 10.0, 3) * numpy.pi / (3600.0 * 12.0) self.frequency = numpy.array([1e8, 1.5e8, 2.0e8]) self.channel_bandwidth = numpy.array([5e7, 5e7, 5e7]) 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 setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results/') self.midcore = create_named_configuration('MID', rmax=3000.0) self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 100.0) self.frequency = numpy.linspace(1.0e9, 1.1e9, 3) self.channel_bandwidth = numpy.array([1e7, 1e7, 1e7]) # 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]) # 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)
def setUp(self): self.persist = os.getenv("RASCIL_PERSIST", False) from rascil.data_models.parameters import rascil_path, rascil_data_path self.lowcore = create_named_configuration('LOWBD2-CORE') self.dir = rascil_path('test_results')
def create_test_image( canonical=True, cellsize=None, frequency=None, channel_bandwidth=None, phasecentre=None, polarisation_frame=PolarisationFrame("stokesI")) -> Image: """Create a useful test image This is the test image M31 widely used in ALMA and other simulations. It is actually part of an Halpha region in M31. :param canonical: Make the image into a 4 dimensional image :param cellsize: :param frequency: Frequency (array) in Hz :param channel_bandwidth: Channel bandwidth (array) in Hz :param phasecentre: Phase centre of image (SkyCoord) :param polarisation_frame: Polarisation frame :return: Image """ check_data_directory() if frequency is None: frequency = [1e8] im = import_image_from_fits(rascil_path("data/models/M31.MOD")) if canonical: if polarisation_frame is None: im.polarisation_frame = PolarisationFrame("stokesI") elif isinstance(polarisation_frame, PolarisationFrame): im.polarisation_frame = polarisation_frame else: raise ValueError("polarisation_frame is not valid") im = replicate_image(im, frequency=frequency, polarisation_frame=im.polarisation_frame) if cellsize is not None: im.wcs.wcs.cdelt[0] = -180.0 * cellsize / numpy.pi im.wcs.wcs.cdelt[1] = +180.0 * cellsize / numpy.pi if frequency is not None: im.wcs.wcs.crval[3] = frequency[0] if channel_bandwidth is not None: im.wcs.wcs.cdelt[3] = channel_bandwidth[0] else: if len(frequency) > 1: im.wcs.wcs.cdelt[3] = frequency[1] - frequency[0] else: im.wcs.wcs.cdelt[3] = 0.001 * frequency[0] im.wcs.wcs.radesys = 'ICRS' im.wcs.wcs.equinox = 2000.00 if phasecentre is not None: im.wcs.wcs.crval[0] = phasecentre.ra.deg im.wcs.wcs.crval[1] = phasecentre.dec.deg # WCS is 1 relative im.wcs.wcs.crpix[0] = im.data.shape[3] // 2 + 1 im.wcs.wcs.crpix[1] = im.data.shape[2] // 2 + 1 return im
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.m31image = create_test_image(cellsize=0.0001) self.cellsize = 180.0 * 0.0001 / numpy.pi self.persist = os.getenv("RASCIL_PERSIST", False)
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", True) self.verbosity = 0
def setUp(self): self.dir = rascil_path('test_results') self.persist = os.getenv("RASCIL_PERSIST", False) self.doplot = False return
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.frequency = numpy.linspace(1e8, 1.5e8, 3) self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
def create_low_test_beam(model: Image, use_local=True) -> Image: """Create a test power beam for LOW using an image from OSKAR This is not fit for anything except the most basic testing. It does not include any form of elevation/pa dependence. :param model: Template image :return: Image """ beam = import_image_from_fits( rascil_path('data/models/SKA1_LOW_beam.fits')) # Scale the image cellsize to account for the different in frequencies. Eventually we will want to # use a frequency cube log.debug( "create_low_test_beam: LOW voltage pattern is defined at %.3f MHz" % (beam.wcs.wcs.crval[2] * 1e-6)) nchan, npol, ny, nx = model.shape # We need to interpolate each frequency channel separately. The beam is assumed to just scale with # frequency. reprojected_beam = create_empty_image_like(model) for chan in range(nchan): model2dwcs = model.wcs.sub(2).deepcopy() model2dshape = [model.shape[2], model.shape[3]] beam2dwcs = beam.wcs.sub(2).deepcopy() # The frequency axis is the second to last in the beam frequency = model.wcs.sub(['spectral']).wcs_pix2world([chan], 0)[0] fscale = beam.wcs.wcs.crval[2] / frequency beam2dwcs.wcs.cdelt = fscale * beam.wcs.sub(2).wcs.cdelt beam2dwcs.wcs.crpix = beam.wcs.sub(2).wcs.crpix beam2dwcs.wcs.crval = model.wcs.sub(2).wcs.crval beam2dwcs.wcs.ctype = model.wcs.sub(2).wcs.ctype model2dwcs.wcs.crpix = [ model.shape[2] // 2 + 1, model.shape[3] // 2 + 1 ] beam2d = create_image_from_array(beam.data[0, 0, :, :], beam2dwcs, model.polarisation_frame) reprojected_beam2d, footprint = reproject_image(beam2d, model2dwcs, shape=model2dshape) assert numpy.max( footprint.data) > 0.0, "No overlap between beam and model" reprojected_beam2d.data[footprint.data <= 0.0] = 0.0 for pol in range(npol): reprojected_beam.data[chan, pol, :, :] = reprojected_beam2d.data[:, :] set_pb_header(reprojected_beam, use_local=use_local) return reprojected_beam
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e6]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-55.0 * u.deg, frame='icrs', equinox='J2000')
def test_grid_gaintable_to_screen(self): self.actualSetup() screen = import_image_from_fits( rascil_data_path('models/test_mpc_screen.fits')) beam = create_test_image(cellsize=0.0015, phasecentre=self.vis.phasecentre, frequency=self.frequency) beam = create_low_test_beam(beam, use_local=False) gleam_components = create_low_test_skycomponents_from_gleam( flux_limit=1.0, phasecentre=self.phasecentre, frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI'), radius=0.2) pb_gleam_components = apply_beam_to_skycomponent( gleam_components, beam) actual_components = filter_skycomponents_by_flux(pb_gleam_components, flux_min=1.0) gaintables = create_gaintable_from_screen(self.vis, actual_components, screen) assert len(gaintables) == len(actual_components), len(gaintables) assert gaintables[0].gain.shape == (3, 94, 1, 1, 1), gaintables[0].gain.shape newscreen = create_empty_image_like(screen) newscreen, weights = grid_gaintable_to_screen(self.vis, gaintables, newscreen) assert numpy.max(numpy.abs(screen.data)) > 0.0 if self.persist: export_image_to_fits( newscreen, rascil_path('test_results/test_mpc_screen_gridded.fits')) if self.persist: export_image_to_fits( weights, rascil_path( 'test_results/test_mpc_screen_gridded_weights.fits'))
def test_create_list(self): if not self.casacore_available: return msfile = rascil_path("data/vis/xcasa.ms") self.vis = create_blockvisibility_from_ms(msfile) for v in self.vis: assert v.vis.data.shape[-1] == 4 assert v.polarisation_frame.type == "circular"
def test_visibility_from_oskar(self): for oskar_file in [ "data/vis/vla_1src_6h/test_vla.vis", "data/vis/vla_grid_6h/test_vla.vis" ]: vis = import_visibility_from_oskar(rascil_path(oskar_file)) self.assertEqual( len(numpy.unique(vis.antenna1)) + 1, len(vis.configuration.xyz)) self.assertEqual( len(numpy.unique(vis.antenna2)) + 1, len(vis.configuration.xyz))
def test_create_gradient(self): real_vp = import_image_from_fits( rascil_path('data/models/MID_GRASP_VP_real.fits')) gradx, grady = image_gradients(real_vp) gradxx, gradxy = image_gradients(gradx) gradyx, gradyy = image_gradients(grady) gradx.data *= real_vp.data grady.data *= real_vp.data gradxx.data *= real_vp.data gradxy.data *= real_vp.data gradyx.data *= real_vp.data gradyy.data *= real_vp.data if self.show: import matplotlib.pyplot as plt plt.clf() show_image(gradx, title='gradx') plt.show() plt.clf() show_image(grady, title='grady') plt.show() if self.persist: export_image_to_fits( gradx, "%s/test_image_gradients_gradx.fits" % (self.dir)) export_image_to_fits( grady, "%s/test_image_gradients_grady.fits" % (self.dir)) if self.show: import matplotlib.pyplot as plt plt.clf() show_image(gradxx, title='gradxx') plt.show() plt.clf() show_image(gradxy, title='gradxy') plt.show() plt.clf() show_image(gradyx, title='gradyx') plt.show() plt.clf() show_image(gradyy, title='gradyy') plt.show() if self.persist: export_image_to_fits( gradxx, "%s/test_image_gradients_gradxx.fits" % (self.dir)) export_image_to_fits( gradxy, "%s/test_image_gradients_gradxy.fits" % (self.dir)) export_image_to_fits( gradyx, "%s/test_image_gradients_gradyx.fits" % (self.dir)) export_image_to_fits( gradyy, "%s/test_image_gradients_gradyy.fits" % (self.dir))
def setUp(self): from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.image = create_image( npixel=512, cellsize=0.0005, phasecentre=self.phasecentre, polarisation_frame=PolarisationFrame("stokesI")) self.persist = os.getenv("RASCIL_PERSIST", False)
def test_gravity(self): if os.path.isdir(rascil_path('models/interpolated')): error_dirty, sumwt = self.simulation(self.get_args(), 'gravity') qa = qa_image(error_dirty) numpy.testing.assert_almost_equal(qa.data['max'], 2.2055849698035616e-06, 12) numpy.testing.assert_almost_equal(qa.data['min'], -6.838117387793031e-07, 12) numpy.testing.assert_almost_equal(qa.data['rms'], 3.7224203394509413e-07, 12)
def setUp(self): rsexecute.set_client(use_dask=True, processes=True, threads_per_worker=1) from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.frequency = numpy.linspace(1e8, 1.5e8, 3) self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
def setUp(self): rsexecute.set_client(memory_limit=4 * 1024 * 1024 * 1024, n_workers=4, dashboard_address=None) from rascil.data_models.parameters import rascil_path self.dir = rascil_path('test_results') self.frequency = numpy.linspace(1e8, 1.5e8, 3) self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0
def test_create_list_spectral(self): uvfitsfile = rascil_path("data/vis/ASKAP_example.fits") vis_by_channel = list() nchan_ave = 16 nchan = 192 for schan in range(0, nchan, nchan_ave): max_chan = min(nchan, schan + nchan_ave) v = create_visibility_from_uvfits(uvfitsfile, range(schan, max_chan)) vis_by_channel.append(v[0]) assert len(vis_by_channel) == 12 for v in vis_by_channel: assert v.vis.data.shape[-1] == 4 assert v.polarisation_frame.type == "linear"