def test_insert_skycomponent_lanczos(self): sc = create_skycomponent( direction=self.phasecentre, flux=numpy.array([[1.0]]), frequency=self.frequency, polarisation_frame=PolarisationFrame('stokesI')) dphasecentre = SkyCoord(ra=+181.0 * u.deg, dec=-58.0 * u.deg, frame='icrs', equinox=2000.0) 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') 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 # These test a regression but are not known a priori to be correct self.assertAlmostEqual(self.model.data[0, 0, 119, 150], 0.887186883218, 7) self.assertAlmostEqual(self.model.data[0, 0, 119, 151], -0.145093950704, 7)
def test_vis_auto_conversion_I(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [1000, 3, 1])) ipf = PolarisationFrame('stokesI') opf = PolarisationFrame('stokesI') cir = convert_pol_frame(stokes, ipf, opf, polaxis=2) st = convert_pol_frame(cir, opf, ipf, polaxis=2) assert_array_almost_equal(st.real, stokes, 15)
def import_image_from_fits(fitsfile: str, mute_warnings=True) -> Image: """ Read an Image from fits :param fitsfile: :return: Image """ fim = Image() with warnings.catch_warnings(): warnings.simplefilter('ignore') hdulist = fits.open(arl_path(fitsfile)) fim.data = hdulist[0].data fim.wcs = WCS(arl_path(fitsfile)) hdulist.close() if len(fim.data) == 2: fim.polarisation_frame = PolarisationFrame('stokesI') else: try: fim.polarisation_frame = polarisation_frame_from_wcs( fim.wcs, fim.data.shape) except: fim.polarisation_frame = PolarisationFrame('stokesI') log.debug( "import_image_from_fits: created %s image of shape %s, size %.3f (GB)" % (fim.data.dtype, str(fim.shape), image_sizeof(fim))) log.debug("import_image_from_fits: Max, min in %s = %.6f, %.6f" % (fitsfile, fim.data.max(), fim.data.min())) assert isinstance(fim, Image) return fim
def ingest_visibility(self, freq=None, chan_width=None, times=None, reffrequency=None, add_errors=False, block=True): if freq is None: freq = [1e8] if times is None: ntimes = 5 times = numpy.linspace(-numpy.pi / 3.0, numpy.pi / 3.0, ntimes) if chan_width is None: chan_width = [1e6] 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_pipeline_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, sky_pol_frame='stokesIQUV', data_pol_frame='linear', f=[100.0, 50.0, -10.0, 40.0]): f = numpy.array(f) 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, 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_blockvisibility(self.vis, self.comp)
def test_image_auto_conversion_I(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [3, 4, 128, 128])) ipf = PolarisationFrame('stokesI') opf = PolarisationFrame('stokesI') cir = convert_pol_frame(stokes, ipf, opf) st = convert_pol_frame(cir, opf, ipf) assert_array_almost_equal(st.real, stokes, 15)
def test_create_vis_iter_with_model(self): model = create_test_image(canonical=True, cellsize=0.001, frequency=self.frequency, phasecentre=self.phasecentre) comp = Skycomponent(direction=self.phasecentre, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame('stokesI')) vis_iter = create_blockvisibility_iterator( self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), integration_time=30.0, number_integrations=3, model=model, components=comp) fullvis = None totalnvis = 0 for i, vis in enumerate(vis_iter): assert vis.phasecentre == self.phasecentre assert vis.nvis if i == 0: fullvis = vis totalnvis = vis.nvis else: fullvis = append_visibility(fullvis, vis) totalnvis += vis.nvis assert fullvis.nvis == totalnvis
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) self.niter = 1000 self.lowcore = create_named_configuration('LOWBD2-CORE') self.nchan = 5 self.times = (numpy.pi / 12.0) * numpy.linspace(-3.0, 3.0, 7) self.frequency = numpy.linspace(0.9e8, 1.1e8, self.nchan) self.channel_bandwidth = numpy.array(self.nchan * [self.frequency[1] - self.frequency[0]]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-45.0 * u.deg, frame='icrs', equinox='J2000') self.vis = create_visibility(self.lowcore, self.times, self.frequency, self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI')) self.vis.data['vis'] *= 0.0 # Create model self.test_model = create_low_test_image_from_gleam(npixel=512, cellsize=0.001, phasecentre=self.vis.phasecentre, frequency=self.frequency, channel_bandwidth=self.channel_bandwidth) beam = create_low_test_beam(self.test_model) export_image_to_fits(beam, "%s/test_deconvolve_msmfsclean_beam.fits" % self.dir) self.test_model.data *= beam.data export_image_to_fits(self.test_model, "%s/test_deconvolve_msmfsclean_model.fits" % self.dir) 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) export_image_to_fits(self.dirty, "%s/test_deconvolve_msmfsclean_dirty.fits" % self.dir) export_image_to_fits(self.psf, "%s/test_deconvolve_msmfsclean_psf.fits" % self.dir) window = numpy.ones(shape=self.model.shape, dtype=numpy.bool) window[..., 129:384, 129:384] = True self.innerquarter = create_image_from_array(window, self.model.wcs)
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) 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=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.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) window = numpy.zeros(shape=self.model.shape, dtype=numpy.bool) window[..., 129:384, 129:384] = True self.innerquarter = create_image_from_array(window, self.model.wcs)
def test_phase_rotation(self): self.vis = create_visibility( 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_visibility( 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=1e-7) assert_allclose(rotatedvis.uvw, vismodel2.uvw, rtol=1e-7)
def test_scatter_gather(self): m31original = create_test_image( polarisation_frame=PolarisationFrame('stokesI')) assert numpy.max(numpy.abs(m31original.data)), "Original is empty" for nraster in [2, 4, 8]: m31model = create_test_image( polarisation_frame=PolarisationFrame('stokesI')) image_list = image_scatter(m31model, facets=nraster) for patch in image_list: assert patch.data.shape[3] == (m31model.data.shape[3] // nraster), \ "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[3], (m31model.data.shape[3] // nraster)) assert patch.data.shape[2] == (m31model.data.shape[2] // nraster), \ "Number of pixels in each patch: %d not as expected: %d" % (patch.data.shape[2], (m31model.data.shape[2] // nraster)) patch.data *= 2.0 m31model = image_gather(image_list, m31model, facets=nraster) diff = m31model.data - 2.0 * m31original.data assert numpy.max(numpy.abs( m31model.data)), "Raster is empty for %d" % nraster assert numpy.max( numpy.abs(diff)) == 0.0, "Raster set failed for %d" % nraster
def ingest_visibility(self, freq=1e8, chan_width=1e6, times=None, reffrequency=None, add_errors=False): 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') 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 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) comp = create_skycomponent( flux=flux, frequency=frequency, direction=sc, polarisation_frame=PolarisationFrame("stokesI")) comps.append(comp) predict_skycomponent_visibility(vt, comps) insert_skycomponent(model, comps) self.model = copy_image(model) export_image_to_fits(model, '%s/test_bags_model.fits' % (self.results_dir)) return vt
def actualSetUp(self, time=None, frequency=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') else: self.vis_pol = PolarisationFrame('stokesI') self.image_pol = PolarisationFrame('stokesI') if dopol: f = numpy.array([100.0, 20.0, -10.0, 1.0]) else: f = numpy.array([100.0]) if dospectral: numpy.array([f, 0.8 * f, 0.6 * f]) else: 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=512, cellsize=0.001, nchan=len(self.frequency), polarisation_frame=self.image_pol)
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) lowcore = create_named_configuration('LOWBD2-CORE') times = numpy.arange(-3.0, +3.0, 1.0) * numpy.pi / 12.0 vnchan = 8 frequency = numpy.linspace(0.8e8, 1.20e8, vnchan) channel_bandwidth = numpy.array(vnchan * [frequency[1] - frequency[0]]) # Define the component and give it some polarisation and spectral behaviour f = numpy.array([100.0, 20.0, -10.0, 1.0]) self.flux = numpy.array( [f, 0.9 * f, 0.8 * f, 0.7 * f, 0.6 * f, 0.5 * f, 0.4 * f, 0.3 * f]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.compabsdirection = SkyCoord(ra=17.0 * u.deg, dec=-36.5 * u.deg, frame='icrs', equinox='J2000') self.comp = create_skycomponent(flux=self.flux, frequency=frequency, direction=self.compabsdirection) self.image = create_test_image( frequency=frequency, phasecentre=self.phasecentre, cellsize=0.001, polarisation_frame=PolarisationFrame('stokesIQUV')) self.blockvis = create_blockvisibility_iterator( lowcore, times=times, frequency=frequency, channel_bandwidth=channel_bandwidth, phasecentre=self.phasecentre, weight=1, polarisation_frame=PolarisationFrame('linear'), integration_time=1.0, number_integrations=1, predict=predict_2d, components=self.comp, phase_error=0.1, amplitude_error=0.01, sleep=1.0) self.vis = create_blockvisibility( lowcore, times=times, frequency=frequency, channel_bandwidth=channel_bandwidth, phasecentre=self.phasecentre, weight=1, polarisation_frame=PolarisationFrame('stokesIQUV'), integration_time=1.0) self.vis = predict_2d(self.vis, self.image)
def test_circular_to_linear(self): stokes = numpy.array(random.uniform(-1.0, 1.0, [3, 4, 128, 128])) ipf = PolarisationFrame('stokesIQUV') opf = PolarisationFrame('circular') cir = convert_pol_frame(stokes, ipf, opf) wrong_pf = PolarisationFrame('linear') with self.assertRaises(ValueError): lin = convert_pol_frame(cir, opf, wrong_pf)
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 """ if frequency is None: frequency = [1e8] im = import_image_from_fits(arl_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 get_polarisation_map(vis: Visibility, im: Image = None): """ Get the mapping of visibility polarisations to image polarisations """ if vis.polarisation_frame == im.polarisation_frame: if vis.polarisation_frame == PolarisationFrame('stokesI'): return "stokesI->stokesI", lambda pol: 0 elif vis.polarisation_frame == PolarisationFrame('stokesIQUV'): return "stokesIQUV->stokesIQUV", lambda pol: pol return "unknown", lambda pol: pol
def test_stokes_conversion(self): assert self.m31image.polarisation_frame == PolarisationFrame("stokesI") stokes = create_test_image(cellsize=0.0001, polarisation_frame=PolarisationFrame("stokesIQUV")) assert stokes.polarisation_frame == PolarisationFrame("stokesIQUV") for pol_name in ['circular', 'linear']: polarisation_frame = PolarisationFrame(pol_name) polimage = convert_stokes_to_polimage(stokes, polarisation_frame=polarisation_frame) assert polimage.polarisation_frame == polarisation_frame polarisation_frame_from_wcs(polimage.wcs, polimage.shape) rstokes = convert_polimage_to_stokes(polimage) assert polimage.data.dtype == 'complex' assert rstokes.data.dtype == 'complex' numpy.testing.assert_array_almost_equal(stokes.data, rstokes.data.real, 12)
def test_subtract(self): vis1 = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vis1.data['vis'][...] = 1.0 vis2 = create_visibility(self.lowcore, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame("stokesIQUV")) vis2.data['vis'][...] = 1.0 zerovis = subtract_visibility(vis1, vis2) qa = qa_visibility(zerovis, context='test_qa') self.assertAlmostEqual(qa.data['maxabs'], 0.0, 7)
def convert_polimage_to_stokes(im: Image): """Convert a polarisation image to stokes (complex) """ assert type(im) == Image assert im.data.dtype == 'complex' if im.polarisation_frame == PolarisationFrame('linear'): cimarr = convert_linear_to_stokes(im.data) return create_image_from_array(cimarr, im.wcs, PolarisationFrame('stokesIQUV')) elif im.polarisation_frame == PolarisationFrame('circular'): cimarr = convert_circular_to_stokes(im.data) return create_image_from_array(cimarr, im.wcs, PolarisationFrame('stokesIQUV')) else: raise ValueError("Cannot convert %s to stokes" % (im.polarisation_frame.type))
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear'): 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_blockvisibility(self.vis, self.comp)
def __init__(self, data=None, frequency=None, channel_bandwidth=None, phasecentre=None, configuration=None, uvw=None, time=None, vis=None, weight=None, integration_time=None, polarisation_frame=PolarisationFrame('stokesI')): if data is None and vis is not None: ntimes = vis.shape[0] assert vis.shape == weight.shape nants = vis.shape[1] assert vis.shape[2] == nants nchan = vis.shape[3] npol = vis.shape[4] desc = [('uvw', '>f8', (nants, nants, 3)), ('time', '>f8'), ('integration_time', '>f8'), ('vis', '>c16', (nants, nants, nchan, npol)), ('weight', '>f8', (nants, nants, nchan, npol))] data = numpy.zeros(shape=[ntimes], dtype=desc) data['uvw'] = uvw data['time'] = time data['integration_time'] = integration_time data['vis'] = vis data['weight'] = weight self.data = data # numpy structured array self.frequency = frequency self.channel_bandwidth = channel_bandwidth self.phasecentre = phasecentre # Phase centre of observation self.configuration = configuration # Antenna/station configuration self.polarisation_frame = polarisation_frame
def __init__(self, direction=None, frequency=None, name=None, flux=None, shape='Point', polarisation_frame=PolarisationFrame('stokesIQUV'), **kwargs): """ Define the required structure :param direction: SkyCoord :param frequency: numpy.array [nchan] :param name: user friendly name :param flux: numpy.array [nchan, npol] :param shape: str e.g. 'Point' 'Gaussian' :param params: numpy.array shape dependent parameters :param polarisation_frame: Polarisation_frame """ self.direction = direction self.frequency = numpy.array(frequency) self.name = name self.flux = numpy.array(flux) self.shape = shape self.params = kwargs self.polarisation_frame = polarisation_frame assert len(self.frequency.shape) == 1 assert len(self.flux.shape) == 2 assert self.frequency.shape[0] == self.flux.shape[0], "Frequency shape %s, flux shape %s" % ( self.frequency.shape, self.flux.shape) assert polarisation_frame.npol == self.flux.shape[1], "Polarisation is %s,, flux shape %s" % ( polarisation_frame.type, self.flux.shape)
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='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')) 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 create_image_from_array( data: numpy.array, wcs: WCS = None, polarisation_frame=PolarisationFrame('stokesI')) -> Image: """ Create an image from an array and optional wcs :param data: Numpy.array :param wcs: World coordinate system :param polarisation_frame: Polarisation Frame :return: Image """ fim = Image() fim.polarisation_frame = polarisation_frame fim.data = data if wcs is None: fim.wcs = None else: fim.wcs = wcs.deepcopy() if image_sizeof(fim) >= 1.0: log.debug( "create_image_from_array: created %s image of shape %s, size %.3f (GB)" % (fim.data.dtype, str(fim.shape), image_sizeof(fim))) assert isinstance(fim, Image), "Type is %s" % type(fim) return fim
def test_phase_rotation_identity(self): self.vis = create_visibility( 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) newphasecenters = [ SkyCoord(182, -35, unit=u.deg), SkyCoord(182, -30, unit=u.deg), SkyCoord(177, -30, unit=u.deg), SkyCoord(176, -35, unit=u.deg), SkyCoord(216, -35, unit=u.deg), SkyCoord(180, -70, unit=u.deg) ] for newphasecentre in newphasecenters: # 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, newphasecentre, tangent=False), self.phasecentre, tangent=False) assert_allclose(rotatedvis.uvw, original_uvw, rtol=1e-7) assert_allclose(rotatedvis.vis, original_vis, rtol=1e-7)
def create_image_para_2(ny, nx, chan, pol, facet, phasecentre, cellsize=0.001, polarisation_frame=PolarisationFrame('linear'), FACET=2): wcs4 = WCS(naxis=4) wcs4.wcs.crpix = [ny * FACET // 2, nx * FACET // 2 + 1.0, 1.0, 1.0] wcs4.wcs.cdelt = [ -180.0 * cellsize / np.pi, +180.0 * cellsize / np.pi, 1.0, 1.0 ] wcs4.wcs.crval = [phasecentre.ra.deg, phasecentre.dec.deg, 1.0, 1.0] wcs4.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ'] wcs4.wcs.radesys = 'ICRS' wcs4.wcs.equinox = 2000.00 data = np.zeros([ny, nx]) keys = { "beam": 0, "major_loop": 0, "channel": chan, "time": 0, "facet": facet, "polarisation": pol } y = facet // FACET x = facet % FACET wcs4.wcs.crpix[0] -= x * nx wcs4.wcs.crpix[1] -= y * ny image_para = image_for_para(data, wcs4_to_wcs2(wcs4), keys) return image_para
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='J2000') 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=512, cellsize=0.001, nchan=self.vnchan, frequency=self.startfrequency)
def create_image(ny, nx, frequency, phasecentre, cellsize=0.001, polarisation_frame=PolarisationFrame('linear')): ''' 创建和上个函数等效的非并行的image :param ny: :param nx: :param frequency: :param phasecentre: :param cellsize: :param polarisation_frame: :return: ''' wcs4 = WCS(naxis=4) wcs4.wcs.crpix = [ny // 2, nx // 2 + 1.0, 1.0, 1.0] wcs4.wcs.cdelt = [ -180.0 * cellsize / np.pi, +180.0 * cellsize / np.pi, 1.0, frequency[1] - frequency[0] ] wcs4.wcs.crval = [ phasecentre.ra.deg, phasecentre.dec.deg, 1.0, frequency[0] ] wcs4.wcs.ctype = ["RA---SIN", "DEC--SIN", 'STOKES', 'FREQ'] wcs4.wcs.radesys = 'ICRS' wcs4.wcs.equinox = 2000.00 nchan = frequency.shape[0] npol = polarisation_frame.npol image = Image() image.wcs = wcs4 image.data = np.zeros([nchan, npol, ny, nx]) image.polarisation_frame = polarisation_frame return image
def test_create_low_test_beam(self): im = create_test_image( canonical=True, cellsize=0.002, frequency=numpy.array([1e8 - 5e7, 1e8, 1e8 + 5e7]), channel_bandwidth=numpy.array([5e7, 5e7, 5e7]), polarisation_frame=PolarisationFrame("stokesIQUV"), phasecentre=self.phasecentre) bm = create_low_test_beam(model=im) export_image_to_fits(bm, '%s/test_low_beam.fits' % (self.dir)) assert bm.data.shape[0] == 3 assert bm.data.shape[1] == 4 assert bm.data.shape[2] == im.data.shape[2] assert bm.data.shape[3] == im.data.shape[3] # Check to see if the beam scales as expected for i in [30, 40]: assert numpy.max( numpy.abs(bm.data[0, 0, 128, 128 - 2 * i] - bm.data[1, 0, 128, 128 - i])) < 0.02 assert numpy.max( numpy.abs(bm.data[0, 0, 128, 128 - 3 * i] - bm.data[2, 0, 128, 128 - i])) < 0.02 assert numpy.max( numpy.abs(bm.data[0, 0, 128 - 2 * i, 128] - bm.data[1, 0, 128 - i, 128])) < 0.02 assert numpy.max( numpy.abs(bm.data[0, 0, 128 - 3 * i, 128] - bm.data[2, 0, 128 - i, 128])) < 0.02