def test_griddata_invert_wterm(self): self.actualSetUp(zerow=False) gcf, cf = create_awterm_convolutionfunction(self.model, nw=100, wstep=8.0, oversampling=8, support=32, use_aaf=True) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits(cf_image, "%s/test_gridding_wterm_cf.fits" % self.dir) griddata = create_griddata_from_image(self.model, nw=1) griddata, sumwt = grid_visibility_to_griddata(self.vis, griddata=griddata, cf=cf) im = fft_griddata_to_image(griddata, gcf) im = normalize_sumwt(im, sumwt) if self.persist: export_image_to_fits( im, '%s/test_gridding_dirty_wterm.fits' % self.dir) self.check_peaks(im, 97.13215242859648)
def test_griddata_invert_awterm(self): self.actualSetUp(zerow=False) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) pb = make_pb(self.model) if self.persist: export_image_to_fits(pb, "%s/test_gridding_awterm_pb.fits" % self.dir) gcf, cf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=100, wstep=8.0, oversampling=16, support=32, use_aaf=True) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits(cf_image, "%s/test_gridding_awterm_cf.fits" % self.dir) griddata = create_griddata_from_image(self.model, nw=100, wstep=8.0) griddata, sumwt = grid_visibility_to_griddata(self.vis, griddata=griddata, cf=cf) im = fft_griddata_to_image(griddata, gcf) im = normalize_sumwt(im, sumwt) if self.persist: export_image_to_fits( im, '%s/test_gridding_dirty_awterm.fits' % self.dir) self.check_peaks(im, 97.13240677427714)
def test_griddata_predict_awterm(self): self.actualSetUp(zerow=False) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) pb = make_pb(self.model) if self.persist: export_image_to_fits(pb, "%s/test_gridding_awterm_pb.fits" % self.dir) gcf, cf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=100, wstep=8.0, oversampling=16, support=32, use_aaf=True) griddata = create_griddata_from_image(self.model, nw=100, wstep=8.0) griddata = fft_image_to_griddata(self.model, griddata, gcf) newvis = degrid_visibility_from_griddata(self.vis, griddata=griddata, cf=cf) qa = qa_visibility(newvis) assert qa.data['rms'] < 120.0, str(qa) self.plot_vis(newvis, 'awterm')
def test_griddata_invert_aterm_noover(self): self.actualSetUp(zerow=True) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) pb = make_pb(self.model) if self.persist: export_image_to_fits(pb, "%s/test_gridding_aterm_pb.fits" % self.dir) gcf, cf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=1, oversampling=1, support=16, use_aaf=True) griddata = create_griddata_from_image(self.model) griddata, sumwt = grid_visibility_to_griddata(self.vis, griddata=griddata, cf=cf) im = fft_griddata_to_image(griddata, gcf) im = normalize_sumwt(im, sumwt) if self.persist: export_image_to_fits( im, '%s/test_gridding_dirty_aterm_noover.fits' % self.dir) self.check_peaks(im, 97.10594988491549)
def test_fill_awterm_to_convolutionfunction(self): make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) pb = make_pb(self.image) if self.persist: export_image_to_fits( pb, "%s/test_convolutionfunction_awterm_pb.fits" % self.dir) gcf, cf = create_awterm_convolutionfunction(self.image, make_pb=make_pb, nw=201, wstep=8, oversampling=8, support=60, use_aaf=True) assert numpy.max(numpy.abs(cf.data)) > 0.0 if self.persist: export_image_to_fits( gcf, "%s/test_convolutionfunction_awterm_gcf.fits" % self.dir) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_awterm_cf.fits" % self.dir) peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert peak_location == (0, 0, 100, 4, 4, 30, 30), peak_location assert numpy.abs(cf.data[peak_location] - (0.07761529943522588 - 0j)) < 1e-7, \ cf.data[peak_location] u_peak, v_peak = cf.grid_wcs.sub([1, 2]).wcs_pix2world( peak_location[-2], peak_location[-1], 0) assert numpy.abs(u_peak) < 1e-7, u_peak assert numpy.abs(v_peak) < 1e-7, u_peak bboxes = calculate_bounding_box_convolutionfunction(cf) assert len(bboxes) == 201, len(bboxes) assert len(bboxes[0]) == 3, len(bboxes[0]) assert bboxes[-1][0] == 200, bboxes[-1][0] peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert peak_location == (0, 0, 100, 4, 4, 30, 30), peak_location cf_clipped = apply_bounding_box_convolutionfunction( cf, fractional_level=1e-3) peak_location = numpy.unravel_index( numpy.argmax(numpy.abs(cf_clipped.data)), cf_clipped.shape) assert peak_location == (0, 0, 100, 4, 4, 21, 21), peak_location cf_image = convert_convolutionfunction_to_image(cf_clipped) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_awterm_clipped_cf.fits" % self.dir)
def test_fill_wterm_to_convolutionfunction(self): gcf, cf = create_awterm_convolutionfunction(self.image, make_pb=None, nw=201, wstep=8.0, oversampling=8, support=60, use_aaf=True) if self.persist: export_image_to_fits( gcf, "%s/test_convolutionfunction_wterm_gcf.fits" % self.dir) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_wterm_cf.fits" % self.dir) peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert peak_location == (0, 0, 100, 4, 4, 30, 30), peak_location assert numpy.abs(cf.data[peak_location] - (0.1870600903328245-0j)) < 1e-7, \ cf.data[peak_location] u_peak, v_peak = cf.grid_wcs.sub([1, 2]).wcs_pix2world( peak_location[-2], peak_location[-1], 0) assert numpy.abs(u_peak) < 1e-7, u_peak assert numpy.abs(v_peak) < 1e-7, u_peak cf_clipped = apply_bounding_box_convolutionfunction(cf, 1e-3) cf_image = convert_convolutionfunction_to_image(cf_clipped) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_wterm_clipped_real_cf.fits" % self.dir) cf_image = convert_convolutionfunction_to_image(cf_clipped) cf_image.data = numpy.imag(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_wterm_clipped_imag_cf.fits" % self.dir) peak_location = numpy.unravel_index( numpy.argmax(numpy.abs(cf_clipped.data)), cf_clipped.shape) assert peak_location == (0, 0, 100, 4, 4, 27, 27), peak_location assert numpy.abs(cf_clipped.data[peak_location] - (0.1870600903328245-0j)) < 1e-7, \ cf_clipped.data[peak_location] u_peak, v_peak = cf_clipped.grid_wcs.sub([1, 2]).wcs_pix2world( peak_location[-2], peak_location[-1], 0) assert numpy.abs(u_peak) < 1e-7, u_peak assert numpy.abs(v_peak) < 1e-7, u_peak
def test_predict_wterm(self): self.actualSetUp(zerow=False) gcfcf = create_awterm_convolutionfunction(self.model, nw=100, wstep=8.0, oversampling=8, support=100, use_aaf=True) self._predict_base(name='predict_wterm', gcfcf=gcfcf, fluxthreshold=5.0)
def test_invert_wterm(self): self.actualSetUp(zerow=False) gcfcf = create_awterm_convolutionfunction(self.model, nw=100, wstep=8.0, oversampling=8, support=100, use_aaf=True) self._invert_base(name='invert_wterm', positionthreshold=35.0, check_components=False, gcfcf=gcfcf)
def test_fill_aterm_to_convolutionfunction_noover(self): make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) pb = make_pb(self.image) if self.persist: export_image_to_fits( pb, "%s/test_convolutionfunction_aterm_pb.fits" % self.dir) gcf, cf = create_awterm_convolutionfunction(self.image, make_pb=make_pb, nw=1, wstep=1e-7, oversampling=1, support=32, use_aaf=True) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_aterm_noover_cf.fits" % self.dir) peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert numpy.abs(cf.data[peak_location] - 0.0776153022780847 + 0j) < 1e-7, cf.data[peak_location] assert peak_location == (0, 0, 0, 0, 0, 16, 16), peak_location u_peak, v_peak = cf.grid_wcs.sub([1, 2]).wcs_pix2world( peak_location[-2], peak_location[-1], 0) assert numpy.abs(u_peak) < 1e-7, u_peak assert numpy.abs(v_peak) < 1e-7, u_peak if self.persist: export_image_to_fits( gcf, "%s/test_convolutionfunction_aterm_noover_gcf.fits" % self.dir) cf_clipped = apply_bounding_box_convolutionfunction( cf, fractional_level=0.001) cf_image = convert_convolutionfunction_to_image(cf_clipped) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_aterm_clipped_noover_cf.fits" % self.dir) peak_location = numpy.unravel_index( numpy.argmax(numpy.abs(cf_clipped.data)), cf_clipped.shape) assert peak_location == (0, 0, 0, 0, 0, 5, 5), peak_location
def test_compare_aterm_kernels(self): make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) _, cf = create_awterm_convolutionfunction(self.image, make_pb=make_pb, oversampling=16, support=32, use_aaf=True) cf.data = numpy.real(cf.data) _, cf_noover = create_awterm_convolutionfunction(self.image, make_pb=make_pb, oversampling=1, support=32, use_aaf=True) cf_noover.data = numpy.real(cf_noover.data) cf.data[...] -= cf_noover.data[0, 0, 0, 0, 0] cf.data[...] /= numpy.max(cf_noover.data) assert numpy.abs(cf.data[0, 0, 0, 8, 8, 16, 16]) < 1e-6, cf.data[0, 0, 0, 8, 8, 16, 16]
def test_compare_wterm_kernels(self): _, cf = create_awterm_convolutionfunction(self.image, nw=110, wstep=8, oversampling=8, support=60, use_aaf=True) cf.data = numpy.real(cf.data) peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert peak_location == (0, 0, 55, 4, 4, 30, 30), peak_location assert numpy.abs(cf.data[peak_location] - (0.18704481681878257 - 0j)) < 1e-7, \ cf.data[peak_location] _, cf_noover = create_awterm_convolutionfunction(self.image, nw=111, wstep=8, oversampling=1, support=60, use_aaf=True) cf_noover.data = numpy.real(cf_noover.data) cf.data[...] -= cf_noover.data[0, 0, 0, 0, 0] cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_compare_wterm_kernels.fits" % self.dir) assert numpy.abs(cf.data[0, 0, 0, 4, 4, 30, 30]) < 5e-6, cf.data[0, 0, 0, 4, 4, 30, 30]
def test_predict_awterm(self): self.actualSetUp(zerow=False) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) gcfcf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=100, wstep=8.0, oversampling=4, support=100, use_aaf=True) self._predict_base(name='predict_awterm', fluxthreshold=35.0, gcfcf=gcfcf)
def test_compare_wterm_symmetry(self): _, cf = create_awterm_convolutionfunction(self.image, nw=110, wstep=8, oversampling=8, support=60, use_aaf=True) peak_location = numpy.unravel_index(numpy.argmax(numpy.abs(cf.data)), cf.shape) assert peak_location == (0, 0, 55, 4, 4, 30, 30), peak_location assert numpy.abs(cf.data[peak_location] - (0.18704481681878257 - 0j)) < 1e-12, cf.data[peak_location] # Side to side in u,v p1 = (0, 0, 55, 4, 4, 25, 25) p2 = (0, 0, 55, 4, 4, 35, 35) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 p1 = (0, 0, 55, 4, 4, 25, 25) p2 = (0, 0, 55, 4, 4, 25, 35) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 p1 = (0, 0, 55, 4, 4, 25, 25) p2 = (0, 0, 55, 4, 4, 35, 35) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 p1 = (0, 0, 45, 4, 4, 25, 25) p2 = (0, 0, 45, 4, 4, 35, 35) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 p1 = (0, 0, 45, 4, 4, 25, 25) p2 = (0, 0, 45, 4, 4, 25, 35) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 p1 = (0, 0, 45, 4, 4, 25, 25) p2 = (0, 0, 45, 4, 4, 35, 25) assert numpy.abs(cf.data[p1] - cf.data[p2]) < 1e-15 # w, -w must be conjugates p1 = (0, 0, 55 - 30, 4, 4, 25, 25) p2 = (0, 0, 55 + 30, 4, 4, 25, 25) assert numpy.abs(cf.data[p1] - numpy.conjugate(cf.data[p2])) < 1e-15 p1 = (0, 0, 55 - 30, 4, 4, 25, 25) p2 = (0, 0, 55 + 30, 4, 4, 35, 35) assert numpy.abs(cf.data[p1] - numpy.conjugate(cf.data[p2])) < 1e-15
def test_griddata_predict_wterm(self): self.actualSetUp(zerow=False) gcf, cf = create_awterm_convolutionfunction(self.model, nw=100, wstep=10.0, oversampling=16, support=32, use_aaf=True) griddata = create_griddata_from_image(self.model, nw=100, wstep=10.0) griddata = fft_image_to_griddata(self.model, griddata, gcf) newvis = degrid_visibility_from_griddata(self.vis, griddata=griddata, cf=cf) newvis.data['vis'][...] -= self.vis.data['vis'][...] qa = qa_visibility(newvis) self.plot_vis(newvis, 'wterm') assert qa.data['rms'] < 11.0, str(qa)
def test_griddata_predict_aterm(self): self.actualSetUp(zerow=True) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) griddata = create_griddata_from_image(self.model) gcf, cf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=1, oversampling=16, support=32, use_aaf=True) griddata = fft_image_to_griddata(self.model, griddata, gcf) newvis = degrid_visibility_from_griddata(self.vis, griddata=griddata, cf=cf) qa = qa_visibility(newvis) assert qa.data['rms'] < 120.0, str(qa)
def test_fill_wterm_to_convolutionfunction_nopswf(self): gcf, cf = create_awterm_convolutionfunction(self.image, make_pb=None, nw=201, wstep=8.0, oversampling=8, support=60, use_aaf=False) if self.persist: export_image_to_fits( gcf, "%s/test_convolutionfunction_wterm_nopswf_gcf.fits" % self.dir) cf_image = convert_convolutionfunction_to_image(cf) cf_image.data = numpy.real(cf_image.data) if self.persist: export_image_to_fits( cf_image, "%s/test_convolutionfunction_wterm_nopswf_cf.fits" % self.dir)
def actualSetUp(self, add_errors=False, freqwin=3, block=True, dospectral=True, dopol=False, zerow=False, makegcfcf=False): self.npixel = 256 self.low = create_named_configuration('LOWBD2', rmax=750.0) self.freqwin = freqwin self.bvis_list = list() self.ntimes = 5 self.cellsize = 0.0005 # Choose the interval so that the maximum change in w is smallish integration_time = numpy.pi * (24 / (12 * 60)) self.times = numpy.linspace(-integration_time * (self.ntimes // 2), integration_time * (self.ntimes // 2), self.ntimes) if freqwin > 1: self.frequency = numpy.linspace(0.8e8, 1.2e8, self.freqwin) self.channelwidth = numpy.array( freqwin * [self.frequency[1] - self.frequency[0]]) else: self.frequency = numpy.array([1.0e8]) self.channelwidth = numpy.array([4e7]) 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.bvis_list = [ ingest_unittest_visibility( self.low, numpy.array([self.frequency[freqwin]]), numpy.array([self.channelwidth[freqwin]]), self.times, self.vis_pol, self.phasecentre, block=block, zerow=zerow) for freqwin, _ in enumerate(self.frequency) ] self.model_list = [ create_unittest_model(self.bvis_list[freqwin], self.image_pol, cellsize=self.cellsize, npixel=self.npixel) for freqwin, _ in enumerate(self.frequency) ] self.components_list = [ create_unittest_components(self.model_list[freqwin], flux[freqwin, :][numpy.newaxis, :], single=False) for freqwin, _ in enumerate(self.frequency) ] self.model_list = [ insert_skycomponent(self.model_list[freqwin], self.components_list[freqwin]) for freqwin, _ in enumerate(self.frequency) ] self.bvis_list = [ dft_skycomponent_visibility(self.bvis_list[freqwin], self.components_list[freqwin]) for freqwin, _ in enumerate(self.frequency) ] centre = self.freqwin // 2 # Calculate the model convolved with a Gaussian. self.model = self.model_list[centre] self.cmodel = smooth_image(self.model) if self.persist: export_image_to_fits(self.model, '%s/test_imaging_model.fits' % self.dir) if self.persist: export_image_to_fits(self.cmodel, '%s/test_imaging_cmodel.fits' % self.dir) if add_errors and block: self.bvis_list = [ insert_unittest_errors(self.bvis_list[i]) for i, _ in enumerate(self.frequency) ] self.components = self.components_list[centre] if makegcfcf: self.gcfcf = [ create_awterm_convolutionfunction(self.model, nw=61, wstep=16.0, oversampling=8, support=64, use_aaf=True) ] self.gcfcf_clipped = [ (self.gcfcf[0][0], apply_bounding_box_convolutionfunction(self.gcfcf[0][1], fractional_level=1e-3)) ] self.gcfcf_joint = [ create_awterm_convolutionfunction(self.model, nw=11, wstep=16.0, oversampling=8, support=64, use_aaf=True) ] else: self.gcfcf = None self.gcfcf_clipped = None self.gcfcf_joint = None
def test_invert_awterm_block(self): self.actualSetUp(zerow=False, block=True) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) gcfcf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=100, wstep=8.0, oversampling=4, support=100, use_aaf=True) self._invert_base(name='invert_awterm_block', positionthreshold=35.0, check_components=False, gcfcf=gcfcf)
if nw % 2 == 0: nw = nw + 1 print(w_min, w_max, w_range, wstep, nw) # In[7]: #%timeit dirty_ng,_ = invert_ng(blockvis, model, normalize=True) # In[10]: # Make Rascil kernel start = time.time() gcfcf_2d = create_awterm_convolutionfunction(model, make_pb=None, nw=nw, wstep=wstep, oversampling=8, support=32, use_aaf=False, maxsupport=512) elapsed = time.time() - start print("Elapsed time = ", elapsed, "sec") #start = time.time() #gcfcf_wt = create_awterm_convolutionfunction(model, make_pb=None, nw=nw, wstep=wstep, oversampling=8, # support=32, use_aaf=False, maxsupport=512, wtowers=True) #wtkern_invert = gcf2wkern2(gcfcf_wt) #elapsed = time.time() - start #print("Elapsed time = ", elapsed, "sec") #wtkern_predict = gcf2wkern2(gcfcf, conjugate=True)
def test_invert_awterm_spec_IQUV(self): self.actualSetUp(zerow=False, freqwin=5, image_pol=PolarisationFrame("stokesIQUV")) make_pb = functools.partial(create_pb_generic, diameter=35.0, blockage=0.0, use_local=False) gcfcf = create_awterm_convolutionfunction(self.model, make_pb=make_pb, nw=100, wstep=8.0, oversampling=4, support=100, use_aaf=True) self._invert_base(name='invert_awterm_spec_IQUV', positionthreshold=35.0, check_components=False, gcfcf=gcfcf)