def test_insert_skycomponent_lanczos(self): dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000') sc = create_skycomponent( direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) self.model.data *= 0.0 insert_skycomponent(self.model, sc, insert_method='Lanczos') # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 0.87781267543090036, 7) self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.23817562762032077, 7)
def ingest_visibility(self, freq=1e8, chan_width=1e6, times=None, reffrequency=None, add_errors=False): if times is None: times = [0.0] if reffrequency is None: reffrequency = [1e8] lowcore = create_named_configuration('LOWBD2-CORE') 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') # 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='J2000') 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.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) comps.append(create_skycomponent(flux=flux, frequency=vt.frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI"))) predict_skycomponent_blockvisibility(vt, comps) insert_skycomponent(model, comps) self.actualmodel = copy_image(model) export_image_to_fits(model, '%s/test_imaging_model.fits' % (self.results_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) return vt
def test_insert_skycomponent(self): sc = create_skycomponent( direction=self.phasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) log.debug(self.model.wcs) log.debug(str(sc)) # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel). self.model.data *= 0.0 insert_skycomponent(self.model, sc) npixel = self.model.shape[3] rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int') assert rpix[0] == npixel // 2 assert rpix[1] == npixel // 2 assert self.model.data[0, 0, rpix[1], rpix[0]] == 1.0 self.vis = predict_2d(self.vis, self.model) assert self.vis.vis.imag.all() == 0.0
def test_insert_skycomponent_lanczos_bandwidth(self): dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000') sc = create_skycomponent( direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) self.model.data *= 0.0 insert_skycomponent(self.model, sc, insert_method='Lanczos', bandwidth=0.5) # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 0.24031092091707615, 7) self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.18648989466050975, 7)
def test_insert_skycomponent_sinc_bandwidth(self): dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox='J2000') sc = create_skycomponent( direction=dphasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) self.model.data *= 0.0 insert_skycomponent(self.model, sc, insert_method='Sinc', bandwidth=0.5) # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[0, 0, 151, 122], 0.25133066186805758, 7) self.assertAlmostEqual(self.model.data[0, 0, 152, 122], 0.19685222464041874, 7)
def test_insert_skycomponent(self): sc = create_skycomponent( direction=self.phasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) self.model.data *= 0.0 insert_skycomponent(self.model, sc) npixel = self.model.shape[3] # WCS is 1-relative rpix = numpy.round(self.model.wcs.wcs.crpix).astype('int') - 1 assert rpix[0] == npixel // 2 assert rpix[1] == npixel // 2 # The phase centre is at rpix[0], rpix[1] in 0-relative pixels assert self.model.data[0, 0, rpix[1], rpix[0]] == 1.0 # If we predict the visibility, then the imaginary part must be zero. This is determined entirely # by shift_vis_to_image in arl.imaging.base self.vis = predict_2d(self.vis, self.model) # The actual phase centre of a numpy FFT is at nx //2, nx //2 (0 rel). assert self.vis.vis.imag.all() == 0.0
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = numpy.linspace(-3, +3, 13) * (numpy.pi / 12.0) self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e7]) # Define the component and give it some polarisation and spectral behaviour f = numpy.array([100.0]) self.flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox=2000.0) self.compabsdirection = SkyCoord(ra=17.0 * u.deg, dec=-36.5 * u.deg, frame='icrs', equinox=2000.0) self.comp = create_skycomponent( flux=self.flux, frequency=self.frequency, direction=self.compabsdirection, polarisation_frame=PolarisationFrame('stokesI')) self.image = create_test_image( frequency=self.frequency, phasecentre=self.phasecentre, cellsize=0.001, polarisation_frame=PolarisationFrame('stokesI')) self.image.data[self.image.data < 0.0] = 0.0 self.image_graph = delayed(create_test_image)( frequency=self.frequency, phasecentre=self.phasecentre, cellsize=0.001, polarisation_frame=PolarisationFrame('stokesI'))
def create_unittest_components(model, flux): # Fill the visibility with exactly computed point sources. spacing_pixels = 512 // 8 log.info('Spacing in pixels = %s' % spacing_pixels) centers = [(x, x) for x in numpy.linspace(-1.2, +1.2, 9)] for x in numpy.linspace(-1.2, +1.2, 9): centers.append((-x, x)) centers.append((0.5, 1.1)) centers.append((1e-7, 1e-7)) model_pol = model.polarisation_frame # Make the list of components rpix = model.wcs.wcs.crpix components = [] for center in centers: ix, iy = center # The phase center in 0-relative coordinates is n // 2 so we centre the grid of # components on ny // 2, nx // 2. The wcs must be defined consistently. 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) log.info("Component at (%f, %f) [0-rel] %s" % (p[0], p[1], str(sc))) if ix != 0 and iy != 0: # Channel images comp = create_skycomponent(flux=flux, frequency=model.frequency, direction=sc, polarisation_frame=model_pol) components.append(comp) beam = create_low_test_beam(model) components = apply_beam_to_skycomponent(components, beam) return components
def ingest_visibility(self, freq=[1e8], chan_width=[1e6], times=None, reffrequency=None, add_errors=False, block=True): if times is None: times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 5) if reffrequency is None: reffrequency = [1e8] lowcore = create_named_configuration('LOWBD2-CORE') 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=reffrequency, phasecentre=phasecentre, polarisation_frame=PolarisationFrame("stokesI")) flux = numpy.array([[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( flux=flux, frequency=frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI")) comps.append(comp) if block: predict_skycomponent_blockvisibility(vt, comps) else: predict_skycomponent_visibility(vt, comps) insert_skycomponent(model, comps) self.model = copy_image(model) self.empty_model = create_empty_image_like(model) export_image_to_fits(model, '%s/test_bags_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) return vt
def actualSetUp(self, time=None, dospectral=False, dopol=False): self.lowcore = create_named_configuration('LOWBD2-CORE') 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') f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') f = numpy.array([100.0]) if dospectral: flux = numpy.array([f, 0.8 * f, 0.6 * f]) else: flux = 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.params['npixel'], cellsize=0.0005, nchan=len(self.frequency), polarisation_frame=self.image_pol) # Fill the visibility with exactly computed point sources. spacing_pixels = 512 // 8 log.info('Spacing in pixels = %s' % spacing_pixels) centers = [(x, x) for x in numpy.linspace(-1.4, +1.4, 9)] for x in numpy.linspace(-1.4, +1.4, 9): centers.append((-x, x)) centers.append((0.5, 1.1)) centers.append((1e-7, 1e-7)) # Make the list of components rpix = self.model.wcs.wcs.crpix self.components = [] for center in centers: ix, iy = center # The phase center in 0-relative coordinates is n // 2 so we centre the grid of # components on ny // 2, nx // 2. The wcs must be defined consistently. p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[0]))), \ int(round(rpix[1] + iy * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[1]))) sc = pixel_to_skycoord(p[0], p[1], self.model.wcs, origin=1) log.info("Component at (%f, %f) [0-rel] %s" % (p[0], p[1], str(sc))) if ix != 0 and iy != 0: # Channel images comp = create_skycomponent(flux=flux, frequency=self.frequency, direction=sc, polarisation_frame=self.image_pol) self.components.append(comp) # Predict the visibility from the components exactly self.componentvis.data['vis'] *= 0.0 self.beam = create_low_test_beam(self.model) self.components = apply_beam_to_skycomponent(self.components, self.beam) self.componentvis = predict_skycomponent_visibility( self.componentvis, self.components) self.model = insert_skycomponent(self.model, self.components) # Calculate the model convolved with a Gaussian. self.cmodel = smooth_image(self.model) export_image_to_fits(self.model, '%s/test_imaging_functions_model.fits' % self.dir) export_image_to_fits( self.cmodel, '%s/test_imaging_functions_cmodel.fits' % self.dir)
def actualSetUp(self, time=None, frequency=None): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / (12.0)) * numpy.linspace(-3.0, 3.0, 7) if time is not None: self.times = time log.info("Times are %s" % (self.times)) if frequency is None: self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e7]) else: self.frequency = frequency if len(self.frequency) < 1: self.channel_bandwidth = numpy.full_like( self.frequency, self.frequency[1] - self.frequency[0]) else: 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.componentvis = create_visibility( self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.uvw = self.componentvis.data['uvw'] self.componentvis.data['vis'] *= 0.0 # Create model self.model = create_image_from_visibility( self.componentvis, npixel=256, cellsize=0.001, nchan=1, polarisation_frame=PolarisationFrame('stokesI')) # Fill the visibility with exactly computed point sources. These are chosen to lie # on grid points. spacing_pixels = 32 log.info('Spacing in pixels = %s' % spacing_pixels) centers = [-2.5, -0.5, 0.5, 2.5] # Make the list of components rpix = self.model.wcs.wcs.crpix - 1 self.components = [] for iy in centers: for ix in centers: if ix >= iy: # The phase center in 0-relative coordinates is n // 2 so we centre the grid of # components on ny // 2, nx // 2. The wcs must be defined consistently. p = int(round(rpix[0] + ix * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[0]))), \ int(round(rpix[1] + iy * spacing_pixels * numpy.sign(self.model.wcs.wcs.cdelt[1]))) sc = pixel_to_skycoord(p[0], p[1], self.model.wcs, origin=0) log.info("Component at (%f, %f) [0-rel] %s" % (p[0], p[1], str(sc))) f = (100.0 + 1.0 * ix + iy * 10.0) # Channel images flux = numpy.array([[f]]) comp = create_skycomponent( flux=flux, frequency=[numpy.average(self.frequency)], direction=sc, polarisation_frame=PolarisationFrame('stokesI')) self.components.append(comp) # Predict the visibility from the components exactly. We always do this for each spectral channel self.componentvis.data['vis'] *= 0.0 predict_skycomponent_visibility(self.componentvis, self.components) insert_skycomponent(self.model, self.components) # Calculate the model convolved with a Gaussian. norm = 2.0 * numpy.pi self.cmodel = copy_image(self.model) self.cmodel.data[0, 0, :, :] = norm * convolve( self.model.data[0, 0, :, :], Gaussian2DKernel(1.0), normalize_kernel=False) export_image_to_fits(self.model, '%s/test_model.fits' % self.dir) export_image_to_fits(self.cmodel, '%s/test_cmodel.fits' % self.dir)