def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) self.vnchan = 5 self.lowcore = create_named_configuration('LOWBD2-CORE') 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 * [self.frequency[1] - self.frequency[0]]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox=2000.0) 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=256, cellsize=0.001, nchan=self.vnchan, frequency=self.startfrequency)
def setUp(self): self.dir = './test_results' self.lowcore = create_named_configuration('LOWBD2-CORE') os.makedirs(self.dir, exist_ok=True) 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=2000.0) 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')) 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.vis = predict_2d(self.vis, self.model) assert numpy.max(numpy.abs(self.vis.vis)) > 0.0 export_image_to_fits( self.model, '%s/test_solve_skycomponent_model.fits' % (self.dir)) self.bigmodel = create_image_from_visibility(self.vis, cellsize=0.0015, npixel=512)
def test_get_frequency_map_mfs(self): self.model = create_image_from_visibility( self.vis, npixel=256, cellsize=0.001, nchan=1, frequency=self.startfrequency) spectral_mode, vfrequency_map = get_frequency_map(self.vis, self.model) assert numpy.max(vfrequency_map) == 0 assert spectral_mode == 'mfs'
def test_get_frequency_map_different_channel(self): self.model = create_image_from_visibility( self.vis, npixel=256, 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 main(): vt = load(1) #TODO move cellsize and npixel to Drop parameters model = create_image_from_visibility(vt, cellsize=0.001, npixel=256) dirty, sumwt = invert_2d(vt, model) psf, sumwt = invert_2d(vt, model, dopsf=True) fig = show_image(dirty) png = '%s_dirty_img.png' % sys.argv[4] fig.savefig(png) dump(2, psf) dump(3, dirty)
def get_LSM(self, vt, npixel=512, cellsize=0.001, reffrequency=[1e8], flux=0.0): model = create_image_from_visibility( vt, npixel=self.npixel, cellsize=cellsize, npol=1, frequency=reffrequency, polarisation_frame=PolarisationFrame("stokesI")) model.data[..., 32, 32] = flux return model
def ingest_visibility(self, freq=1e8, chan_width=1e6, time=0.0, reffrequency=[1e8], add_errors=False): lowcore = create_named_configuration('LOWBD2-CORE') times = [time] 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=2000.0) # Observe at zenith to ensure that timeslicing works well. We test that elsewhere. phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox=2000.0) vt = create_blockvisibility( 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=reffrequency, polarisation_frame=PolarisationFrame("stokesI")) flux = numpy.array([[100.0]]) facets = 4 rpix = model.wcs.wcs.crpix - 1 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=0) comps.append( create_skycomponent( flux=flux, frequency=vt.frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI"))) predict_skycomponent_blockvisibility(vt, comps) insert_skycomponent(model, comps) export_image_to_fits( model, '%s/test_imaging_dask_model.fits' % (self.results_dir)) if add_errors: gt = create_gaintable_from_blockvisibility(vt) gt = simulate_gaintable(gt, phase_error=1.0, amplitude_error=0.0) vt = apply_gaintable(vt, gt) return vt
def test_peel_skycomponent_blockvisibility(self): df = 1e6 frequency = numpy.array([1e8 - df, 1e8, 1e8 + df]) channel_bandwidth = numpy.array([df, df, df]) # Define the component and give it some spectral behaviour f = numpy.array([100.0, 20.0, -10.0, 1.0]) flux = numpy.array([f, 0.8 * f, 0.6 * f]) phasecentre = SkyCoord(0 * u.deg, -60.0 * u.deg) config = create_named_configuration('LOWBD2-CORE') peeldirection = SkyCoord(+15 * u.deg, -60.0 * u.deg) times = numpy.linspace(-3.0, 3.0, 7) * numpy.pi / 12.0 # Make the visibility vis = create_blockvisibility( config, times, frequency, phasecentre=phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('linear'), channel_bandwidth=channel_bandwidth) vis.data['vis'][...] = 0.0 # First add in the source to be peeled. peel = Skycomponent(direction=peeldirection, frequency=frequency, flux=flux, polarisation_frame=PolarisationFrame("stokesIQUV")) vis = predict_skycomponent_blockvisibility(vis, peel) # Make a gaintable and apply it to the visibility of the peeling source gt = create_gaintable_from_blockvisibility(vis) gt = simulate_gaintable(gt, phase_error=0.01, amplitude_error=0.01) gt.data['gain'] *= 0.3 vis = apply_gaintable(vis, gt) # Now create a plausible field using the GLEAM sources model = create_image_from_visibility( vis, cellsize=0.001, frequency=frequency, polarisation_frame=PolarisationFrame('stokesIQUV')) bm = create_low_test_beam(model=model) sc = create_low_test_skycomponents_from_gleam( flux_limit=1.0, polarisation_frame=PolarisationFrame("stokesIQUV"), frequency=frequency, kind='cubic', phasecentre=phasecentre, radius=0.1) sc = apply_beam_to_skycomponent(sc, bm) # Add in the visibility due to these sources vis = predict_skycomponent_blockvisibility(vis, sc) # Now we can peel vis, peel_gts = peel_skycomponent_blockvisibility(vis, peel) assert len(peel_gts) == 1 residual = numpy.max(peel_gts[0].residual) assert residual < 0.6, "Peak residual %.6f too large" % (residual)