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 setUp(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0) self.frequency = numpy.linspace(1.0e8, 1.1e8, 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=2000.0) self.compabsdirection = SkyCoord(ra=+181.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox=2000.0) # self.compabsdirection = SkyCoord(ra=+182 * u.deg, dec=-36.5 * u.deg, frame='icrs', equinox=2000.0) pcof = self.phasecentre.skyoffset_frame() self.compreldirection = self.compabsdirection.transform_to(pcof) self.comp = Skycomponent(direction=self.compreldirection, frequency=self.frequency, flux=self.flux)
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 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 createVis(self, config, dec=-35.0): self.config = create_named_configuration(config) self.phasecentre = SkyCoord(ra=+15 * u.deg, dec=dec * u.deg, frame='icrs', equinox=2000.0) self.vis = create_visibility(self.config, self.times, self.frequency, channel_bandwidth=self.channel_bandwidth, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'))
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 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.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 60.0, 30.0) vnchan = 3 self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]])
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 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 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 setUp(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = numpy.linspace(-300.0, 300.0, 11) * numpy.pi / 43200.0 self.frequency = numpy.array([1e8]) self.channel_bandwidth = numpy.array([1e8]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000')
def setUp(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 30 * 3.76, 3.76) df = 27343.75000 self.frequency = numpy.array([1e8 - df, 1e8, 1e8 + df]) self.channel_bandwidth = numpy.array([27343.75, 27343.75, 27343.75]) self.phasecentre = SkyCoord(ra=+0.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.blockvis = create_blockvisibility(self.lowcore, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth)
def telescope_management_kernel(ixs, config, rmax): ''' 生成总的conf类,留待telescope_data_kernel进一步划分 :param ixs: :return: iter[(key, conf)] ''' ix = next(ixs)[0] conf = create_named_configuration(config, rmax=rmax) result = (ix, conf) label = "Telescope Management (0.0 MB, 0.00 Tflop) " print(label + str(result)) return iter([result])
def setUp(self): self.dir = './test_results' os.makedirs(self.dir, exist_ok=True) self.frequency = numpy.linspace(1e8, 1.5e8, 3) self.channel_bandwidth = numpy.array([2.5e7, 2.5e7, 2.5e7]) self.flux = numpy.array([[100.0], [100.0], [100.0]]) self.phasecentre = SkyCoord(ra=+15.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox=2000.0) self.config = create_named_configuration('LOWBD2-CORE') self.times = numpy.linspace(-300.0, 300.0, 3) * numpy.pi / 43200.0 nants = self.config.xyz.shape[0] assert nants > 1 assert len(self.config.names) == nants assert len(self.config.mount) == nants
def test_predict_sky_components_coalesce(self): sc = create_low_test_skycomponents_from_gleam(flux_limit=10.0, polarisation_frame=PolarisationFrame("stokesI"), frequency=self.frequency, kind='cubic', phasecentre=SkyCoord("17h20m31s", "-00d58m45s"), radius=0.1) self.config = create_named_configuration('LOWBD2-CORE') self.phasecentre = SkyCoord("17h20m31s", "-00d58m45s") sampling_time = 3.76 self.times = numpy.arange(0.0, + 300 * sampling_time, sampling_time) self.vis = create_blockvisibility(self.config, self.times, self.frequency, phasecentre=self.phasecentre, weight=1.0, polarisation_frame=PolarisationFrame('stokesI'), channel_bandwidth=self.channel_bandwidth) self.vis = predict_skycomponent_blockvisibility(self.vis, sc) cvt = coalesce_visibility(self.vis, time_coal=1.0) assert cvt.cindex is not None
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear', f=None, vnchan=3): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.linspace(0.0, 30.0, 3) self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) if f is None: f = [100.0, 50.0, -10.0, 40.0] if sky_pol_frame == 'stokesI': f = [100.0] self.flux = numpy.outer( numpy.array( [numpy.power(freq / 1e8, -0.7) for freq in self.frequency]), 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_visibility(self.vis, self.comp)
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 actualSetup(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0) self.times = [0.0] self.frequency = numpy.linspace(1.0e8, 1.1e8, 1) self.channel_bandwidth = numpy.array([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]) f = numpy.array([100.0]) self.flux = numpy.array([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.comp_actual_direction = SkyCoord(ra=+180.2 * u.deg, dec=-35.1 * u.deg, frame='icrs', equinox='J2000') self.comp_start_direction = SkyCoord(ra=+180.0 * u.deg, dec=-35.0 * u.deg, frame='icrs', equinox='J2000') self.comp = Skycomponent(direction=self.comp_actual_direction, frequency=self.frequency, flux=self.flux, polarisation_frame=PolarisationFrame("stokesI"))
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 setUp(self): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0) vnchan = 3 self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) # 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')
def actualSetup(self, sky_pol_frame='stokesIQUV', data_pol_frame='linear'): self.lowcore = create_named_configuration('LOWBD2-CORE') self.times = (numpy.pi / 43200.0) * numpy.arange(0.0, 300.0, 30.0) vnchan = 3 self.frequency = numpy.linspace(1.0e8, 1.1e8, vnchan) self.channel_bandwidth = numpy.array( vnchan * [self.frequency[1] - self.frequency[0]]) # 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]) 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') if sky_pol_frame == 'stokesI': self.flux = self.flux[:, 0][:, numpy.newaxis] 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_visibility(self.vis, self.comp)
def actualSetUp(self, add_errors=False, freqwin=7, block=False, dospectral=True, dopol=False): self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.vis_graph_list = list() self.ntimes = 5 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) if freqwin > 1: self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.channelwidth = numpy.array([1e6]) 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 * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.vis_graph_list = [ delayed(ingest_unittest_visibility)(self.low, [self.frequency[i]], [self.channelwidth[i]], self.times, self.vis_pol, self.phasecentre, block=block) for i, _ in enumerate(self.frequency) ] self.model_graph = [ delayed(create_unittest_model, nout=freqwin)(self.vis_graph_list[0], self.image_pol, npixel=self.params['npixel']) for i, _ in enumerate(self.frequency) ] self.components_graph = [ delayed(create_unittest_components)(self.model_graph[i], flux[i, :][numpy.newaxis, :]) for i, _ in enumerate(self.frequency) ] # Apply the LOW primary beam and insert into model self.model_graph = [ delayed(insert_skycomponent, nout=1)(self.model_graph[freqwin], self.components_graph[freqwin]) for freqwin, _ in enumerate(self.frequency) ] self.vis_graph_list = [ delayed(predict_skycomponent_visibility)( self.vis_graph_list[freqwin], self.components_graph[freqwin]) for freqwin, _ in enumerate(self.frequency) ] # Calculate the model convolved with a Gaussian. model = self.model_graph[0].compute() self.cmodel = smooth_image(model) export_image_to_fits(model, '%s/test_imaging_delayed_model.fits' % self.dir) export_image_to_fits(self.cmodel, '%s/test_imaging_delayed_cmodel.fits' % self.dir) if add_errors and block: self.vis_graph_list = [ delayed(insert_unittest_errors)(self.vis_graph_list[i]) for i, _ in enumerate(self.frequency) ]
def create_simulate_vis_graph(config='LOWBD2-CORE', phasecentre=SkyCoord(ra=+15.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000'), frequency=None, channel_bandwidth=None, times=None, polarisation_frame=PolarisationFrame("stokesI"), order='frequency', format='blockvis', rmax=1000.0) -> delayed: """ Create a graph to simulate an observation The simulation step can generate a single BlockVisibility or a list of BlockVisibility's. The parameter keyword determines the way that the list is constructed. If order='frequency' then len(frequency) BlockVisibility's with all times are created. If order='time' then len(times) BlockVisibility's with all frequencies are created. If order = 'both' then len(times) * len(times) BlockVisibility's are created each with a single time and frequency. If order = None then all data are created in one BlockVisibility. The output format can be either 'blockvis' (for calibration) or 'vis' (for imaging) :param config: Name of configuration: def LOWBDS-CORE :param phasecentre: Phase centre def: SkyCoord(ra=+15.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') :param frequency: def [1e8] :param channel_bandwidth: def [1e6] :param times: Observing times in radians: def [0.0] :param polarisation_frame: def PolarisationFrame("stokesI") :param order: 'time' or 'frequency' or 'both' or None: def 'frequency' :param format: 'blockvis' or 'vis': def 'blockvis' :param kwargs: :return: vis_graph_list with different frequencies in different elements """ if format == 'vis': create_vis = create_visibility else: create_vis = create_blockvisibility if times is None: times = [0.0] if channel_bandwidth is None: channel_bandwidth = [1e6] if frequency is None: frequency = [1e8] conf = create_named_configuration(config, rmax=rmax) if order == 'time': log.debug("create_simulate_vis_graph: Simulating distribution in %s" % order) vis_graph_list = list() for i, time in enumerate(times): vis_graph_list.append( delayed(create_vis, nout=1)(conf, [times[i]], frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=polarisation_frame)) elif order == 'frequency': log.debug("create_simulate_vis_graph: Simulating distribution in %s" % order) vis_graph_list = list() for j, _ in enumerate(frequency): vis_graph_list.append( delayed(create_vis, nout=1)(conf, times, frequency=[frequency[j]], channel_bandwidth=[channel_bandwidth[j]], weight=1.0, phasecentre=phasecentre, polarisation_frame=polarisation_frame)) elif order == 'both': log.debug( "create_simulate_vis_graph: Simulating distribution in time and frequency" ) vis_graph_list = list() for i, _ in enumerate(times): for j, _ in enumerate(frequency): vis_graph_list.append( delayed(create_vis, nout=1)(conf, [times[i]], frequency=[frequency[j]], channel_bandwidth=[channel_bandwidth[j]], weight=1.0, phasecentre=phasecentre, polarisation_frame=polarisation_frame)) elif order is None: log.debug("create_simulate_vis_graph: Simulating into single %s" % format) vis_graph_list = list() vis_graph_list.append( delayed(create_vis, nout=1)(conf, times, frequency=frequency, channel_bandwidth=channel_bandwidth, weight=1.0, phasecentre=phasecentre, polarisation_frame=polarisation_frame)) else: raise NotImplementedError("order $s not known" % order) return vis_graph_list
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)
def test_unknown_configuration(self): with self.assertRaises(ValueError): self.config = create_named_configuration("SKA1-OWL")
def test_clip_configuration(self): for rmax in [ 100.0, 3000.0, 1000.0, 3000.0, 10000.0, 30000.0, 100000.0 ]: self.config = create_named_configuration('LOWBD2', rmax=rmax) assert self.config.size() > 0.0
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, add_errors=False, freqwin=1, block=False, dospectral=True, dopol=False): self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.vis_graph_list = list() self.ntimes = 5 self.times = numpy.linspace(-3.0, +3.0, self.ntimes) * numpy.pi / 12.0 self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) if freqwin > 1: self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.channelwidth = numpy.array([1e6]) 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 * numpy.power(freq / 1e8, -0.7) for freq in self.frequency]) else: flux = numpy.array([f]) self.phasecentre = SkyCoord(ra=+180.0 * u.deg, dec=-60.0 * u.deg, frame='icrs', equinox='J2000') self.componentvis = ingest_unittest_visibility(self.low, self.frequency, self.channelwidth, self.times, self.vis_pol, self.phasecentre, block=block) self.model = create_unittest_model(self.componentvis, self.image_pol, npixel=self.params['npixel']) self.components = create_unittest_components(self.model, flux) self.model = insert_skycomponent(self.model, self.components) self.componentvis.data['vis'][...] = 0.0 self.componentvis = predict_skycomponent_visibility( self.componentvis, self.components) 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) if add_errors: self.componentvis = insert_unittest_errors(self.componentvis)
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_visibility(vis, peel) # Make a gaintable and apply it to the visibility of the peeling source gt = create_gaintable_from_blockvisibility(vis, timeslice='auto') gt = simulate_gaintable(gt, phase_error=0.01, amplitude_error=0.01, timeslice='auto') gt.data['gain'] *= 0.3 vis = apply_gaintable(vis, gt, timeslice='auto') # 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_visibility(vis, sc) assert numpy.max(numpy.abs(vis.vis)) > 0.0 # 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.7, "Peak residual %.6f too large" % (residual) im, sumwt = invert_timeslice(vis, model, timeslice='auto') qa = qa_image(im) assert numpy.abs(qa.data['max'] - 14.2) < 1.0, str(qa)