Ejemplo n.º 1
0
 def test_deconvolve_mmclean_quadratic_psf(self):
     self.comp, self.residual = deconvolve_cube(self.dirty,
                                                self.psf,
                                                niter=self.niter,
                                                gain=0.1,
                                                algorithm='mmclean',
                                                scales=[0, 3, 10],
                                                threshold=0.01,
                                                nmoments=2,
                                                findpeak='ARL',
                                                fractional_threshold=0.01,
                                                window=self.innerquarter,
                                                psf_support=32)
     export_image_to_fits(
         self.comp,
         "%s/test_deconvolve_mmclean_quadratic_psf-comp.fits" % self.dir)
     export_image_to_fits(
         self.residual,
         "%s/test_deconvolve_mmclean_quadratic_psf-residual.fits" %
         self.dir)
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(
         self.cmodel,
         "%s/test_deconvolve_mmclean_quadratic_psf-clean.fits" % self.dir)
     assert numpy.max(self.residual.data) < 3.0
Ejemplo n.º 2
0
 def test_deconvolve_hogbom(self):
     self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=10000, gain=0.1, algorithm='hogbom',
                                                threshold=0.01)
     export_image_to_fits(self.residual, "%s/test_deconvolve_hogbom-residual.fits" % (self.dir))
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(self.cmodel, "%s/test_deconvolve_hogbom-clean.fits" % (self.dir))
     assert numpy.max(self.residual.data) < 1.2
Ejemplo n.º 3
0
 def test_deconvolve_msclean(self):
     self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=1000, gain=0.7, algorithm='msclean',
                                                scales=[0, 3, 10, 30], threshold=0.01)
     export_image_to_fits(self.comp, "%s/test_deconvolve_msclean-comp.fits" % (self.dir))
     export_image_to_fits(self.residual, "%s/test_deconvolve_msclean-residual.fits" % (self.dir))
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(self.cmodel, "%s/test_deconvolve_msclean-clean.fits" % (self.dir))
     assert numpy.max(self.residual.data) < 1.2
Ejemplo n.º 4
0
 def test_deconvolve_hogbom_subpsf(self):
     
     self.comp, self.residual = deconvolve_cube(self.dirty, psf=self.psf, psf_support=200, window='quarter',
                                                niter=10000, gain=0.1, algorithm='hogbom', threshold=0.01)
     export_image_to_fits(self.residual, "%s/test_deconvolve_hogbom_subpsf-residual.fits" % (self.dir))
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(self.cmodel, "%s/test_deconvolve_hogbom_subpsf-clean.fits" % (self.dir))
     assert numpy.max(self.residual.data[..., 56:456, 56:456]) < 1.2
 def test_deconvolve_mmclean_no_taylor_noscales(self):
     self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=self.niter, gain=0.1,
                                                algorithm='mmclean',
                                                scales=[0], threshold=0.01, nmoment=1, findpeak='ARL',
                                                fractional_threshold=0.01, window=self.innerquarter)
     if self.persist: export_image_to_fits(self.comp, "%s/test_deconvolve_mmclean_notaylor_noscales-comp.fits" % self.dir)
     if self.persist: export_image_to_fits(self.residual, "%s/test_deconvolve_mmclean_notaylor_noscales-residual.fits" % self.dir)
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     if self.persist: export_image_to_fits(self.cmodel, "%s/test_deconvolve_mmclean_notaylor_noscales-clean.fits" % self.dir)
     assert numpy.max(self.residual.data) < 3.0
 def test_deconvolve_mmclean_no_taylor_edge(self):
     self.comp, self.residual = deconvolve_cube(self.dirty, self.psf, niter=self.niter, gain=0.1,
                                                algorithm='mmclean',
                                                scales=[0, 3, 10], threshold=0.01, nmoment=1, findpeak='ARL',
                                                fractional_threshold=0.01, window_shape='no_edge', window_edge=32)
     export_image_to_fits(self.comp, "%s/test_deconvolve_mmclean_notaylor-comp.fits" % self.dir)
     export_image_to_fits(self.residual, "%s/test_deconvolve_mmclean_notaylor-residual.fits" % self.dir)
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(self.cmodel, "%s/test_deconvolve_mmclean_notaylor-clean.fits" % self.dir)
     assert numpy.max(self.residual.data) < 3.0
Ejemplo n.º 7
0
 def test_deconvolve_msclean_subpsf(self):
     
     self.comp, self.residual = deconvolve_cube(self.dirty, psf=self.psf, psf_support=200,
                                                window=self.innerquarter, niter=1000, gain=0.7,
                                                algorithm='msclean', scales=[0, 3, 10, 30], threshold=0.01)
     export_image_to_fits(self.comp, "%s/test_deconvolve_msclean_subpsf-comp.fits" % (self.dir))
     export_image_to_fits(self.residual, "%s/test_deconvolve_msclean_subpsf-residual.fits" % (self.dir))
     self.cmodel = restore_cube(self.comp, self.psf, self.residual)
     export_image_to_fits(self.cmodel, "%s/test_deconvolve_msclean_subpsf-clean.fits" % (self.dir))
     assert numpy.max(self.residual.data[..., 56:456, 56:456]) < 1.0
Ejemplo n.º 8
0
def main():
    dlg_string = os.environ['DLG_UID']
    dlg_string = dlg_string[(dlg_string.rindex('_') + 1):len(dlg_string)]
    dlg_uid = dlg_string.split('/')
    Freq_Iteration = int(dlg_uid[1])  # derived from ID
    Facet_Iteration = int(dlg_uid[2])  # derived from ID
    vt = load(1)
    phasecentre_array = [[+15, -45], [+15.2, -45], [+15, -44], [+14.8, -45],
                         [+15, -46]]

    phasecentre = SkyCoord(ra=phasecentre_array[Facet_Iteration][0] * u.deg,
                           dec=phasecentre_array[Facet_Iteration][1] * u.deg,
                           frame='icrs',
                           equinox='J2000')

    model = create_image_from_visibility(vt,
                                         phasecentre=phasecentre,
                                         cellsize=0.001,
                                         npixel=256)
    dirty, sumwt = invert_function(vt, model)
    psf, sumwt = invert_function(vt, model, dopsf=True)

    #show_image(dirty)
    print("Max, min in dirty image = %.6f, %.6f, sumwt = %f" %
          (dirty.data.max(), dirty.data.min(), sumwt))

    print("Max, min in PSF         = %.6f, %.6f, sumwt = %f" %
          (psf.data.max(), psf.data.min(), sumwt))

    export_image_to_fits(
        dirty, '%s/imaging_dirty_%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))
    export_image_to_fits(
        psf, '%s/imaging_psf_%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))

    # Deconvolve using clean

    comp, residual = deconvolve_cube(dirty,
                                     psf,
                                     niter=1000,
                                     threshold=0.001,
                                     fracthresh=0.01,
                                     window_shape='quarter',
                                     gain=0.7,
                                     scales=[0, 3, 10, 30])

    restored = restore_cube(comp, psf, residual)

    export_image_to_fits(
        restored, '%s/imaging_clean%02d_%02d.fits' %
        (results_dir, Freq_Iteration, Facet_Iteration))
    dump(2, restored)
def solve_image_arlexecute(vis: Visibility, model: Image, components=None, context='2d', **kwargs) -> \
        (Visibility, Image, Image):
    """Solve for image using deconvolve_cube and specified predict, invert

    This is the same as a majorcycle/minorcycle algorithm. The components are removed prior to deconvolution.
    
    See also arguments for predict, invert, deconvolve_cube functions.2d

    :param vis:
    :param model: Model image
    :param predict: Predict function e.g. predict_2d, predict_wstack
    :param invert: Invert function e.g. invert_2d, invert_wstack
    :return: Visibility, model
    """
    nmajor = get_parameter(kwargs, 'nmajor', 5)
    thresh = get_parameter(kwargs, "threshold", 0.0)
    log.info("solve_image_arlexecute: Performing %d major cycles" % nmajor)
    
    # The model is added to each major cycle and then the visibilities are
    # calculated from the full model
    vispred = copy_visibility(vis, zero=True)
    visres = copy_visibility(vis, zero=True)

    vispred = predict_arlexecute(vispred, model, context=context, **kwargs)
    
    if components is not None:
        vispred = predict_skycomponent_visibility(vispred, components)
    
    visres.data['vis'] = vis.data['vis'] - vispred.data['vis']
    dirty, sumwt = invert_arlexecute(visres, model, context=context, dopsf=False, **kwargs)
    assert sumwt.any() > 0.0, "Sum of weights is zero"
    psf, sumwt = invert_arlexecute(visres, model, context=context, dopsf=True, **kwargs)
    assert sumwt.any() > 0.0, "Sum of weights is zero"
    
    for i in range(nmajor):
        log.info("solve_image_arlexecute: Start of major cycle %d" % i)
        cc, res = deconvolve_cube(dirty, psf, **kwargs)
        model.data += cc.data
        vispred.data['vis'][...]=0.0
        vispred = predict_arlexecute(vispred, model, context=context, **kwargs)
        visres.data['vis'] = vis.data['vis'] - vispred.data['vis']
        dirty, sumwt = invert_arlexecute(visres, model, context=context, dopsf=False, **kwargs)
        if numpy.abs(dirty.data).max() < 1.1 * thresh:
            log.info("Reached stopping threshold %.6f Jy" % thresh)
            break
        log.info("solve_image_arlexecute: End of minor cycles")

    log.info("solve_image_arlexecute: End of major cycles")
    return visres, model, dirty
Ejemplo n.º 10
0
    def deconvolve(dirty, psf, model, facet, gthreshold):
        import time
        starttime = time.time()
        if prefix == '':
            lprefix = "facet %d" % facet
        else:
            lprefix = "%s, facet %d" % (prefix, facet)

        nmoments = get_parameter(kwargs, "nmoments", 0)

        if nmoments > 0:
            moment0 = calculate_image_frequency_moments(dirty)
            this_peak = numpy.max(numpy.abs(
                moment0.data[0, ...])) / dirty.data.shape[0]
        else:
            this_peak = numpy.max(numpy.abs(dirty.data[0, ...]))

        if this_peak > 1.1 * gthreshold:
            log.info(
                "deconvolve_arlexecute %s: cleaning - peak %.6f > 1.1 * threshold %.6f"
                % (lprefix, this_peak, gthreshold))
            kwargs['threshold'] = gthreshold
            result, _ = deconvolve_cube(dirty, psf, prefix=lprefix, **kwargs)

            if result.data.shape[0] == model.data.shape[0]:
                result.data += model.data
            else:
                log.warning(
                    "deconvolve_arlexecute %s: Initial model %s and clean result %s do not have the same shape"
                    % (lprefix, str(
                        model.data.shape[0]), str(result.data.shape[0])))

            flux = numpy.sum(result.data[0, 0, ...])
            log.info(
                '### %s, %.6f, %.6f, True, %.3f # cycle, facet, peak, cleaned flux, clean, time?'
                % (lprefix, this_peak, flux, time.time() - starttime))

            return result
        else:
            log.info(
                "deconvolve_arlexecute %s: Not cleaning - peak %.6f <= 1.1 * threshold %.6f"
                % (lprefix, this_peak, gthreshold))
            log.info(
                '### %s, %.6f, %.6f, False, %.3f # cycle, facet, peak, cleaned flux, clean, time?'
                % (lprefix, this_peak, 0.0, time.time() - starttime))

            return copy_image(model)
Ejemplo n.º 11
0
 def deconvolve_subimage(dirty, psf):
     assert isinstance(dirty, Image)
     assert isinstance(psf, Image)
     comp = deconvolve_cube(dirty, psf, **kwargs)
     return comp[0]
def ical_serial(block_vis: BlockVisibility,
                model: Image,
                components=None,
                context='2d',
                controls=None,
                **kwargs):
    """ Post observation image, deconvolve, and self-calibrate

    :param vis:
    :param model: Model image
    :param components: Initial components
    :param context: Imaging context
    :param controls: calibration controls dictionary
    :return: model, residual, restored
    """
    nmajor = get_parameter(kwargs, 'nmajor', 5)
    log.info("ical_serial: Performing %d major cycles" % nmajor)

    do_selfcal = get_parameter(kwargs, "do_selfcal", False)

    if controls is None:
        controls = create_calibration_controls(**kwargs)

    # The model is added to each major cycle and then the visibilities are
    # calculated from the full model
    vis = convert_blockvisibility_to_visibility(block_vis)
    block_vispred = copy_visibility(block_vis, zero=True)
    vispred = convert_blockvisibility_to_visibility(block_vispred)
    vispred.data['vis'][...] = 0.0
    visres = copy_visibility(vispred)

    vispred = predict_serial(vispred, model, context=context, **kwargs)

    if components is not None:
        vispred = predict_skycomponent_visibility(vispred, components)

    if do_selfcal:
        vis, gaintables = calibrate_function(vis,
                                             vispred,
                                             'TGB',
                                             controls,
                                             iteration=-1)

    visres.data['vis'] = vis.data['vis'] - vispred.data['vis']
    dirty, sumwt = invert_serial(visres, model, context=context, **kwargs)
    log.info("Maximum in residual image is %.6f" %
             (numpy.max(numpy.abs(dirty.data))))

    psf, sumwt = invert_serial(visres,
                               model,
                               dopsf=True,
                               context=context,
                               **kwargs)

    thresh = get_parameter(kwargs, "threshold", 0.0)

    for i in range(nmajor):
        log.info("ical_serial: Start of major cycle %d of %d" % (i, nmajor))
        cc, res = deconvolve_cube(dirty, psf, **kwargs)
        model.data += cc.data
        vispred.data['vis'][...] = 0.0
        vispred = predict_serial(vispred, model, context=context, **kwargs)
        if do_selfcal:
            vis, gaintables = calibrate_function(vis,
                                                 vispred,
                                                 'TGB',
                                                 controls,
                                                 iteration=i)
        visres.data['vis'] = vis.data['vis'] - vispred.data['vis']

        dirty, sumwt = invert_serial(visres, model, context=context, **kwargs)
        log.info("Maximum in residual image is %s" %
                 (numpy.max(numpy.abs(dirty.data))))
        if numpy.abs(dirty.data).max() < 1.1 * thresh:
            log.info("ical_serial: Reached stopping threshold %.6f Jy" %
                     thresh)
            break
        log.info("ical_serial: End of major cycle")

    log.info("ical_serial: End of major cycles")
    restored = restore_cube(model, psf, dirty, **kwargs)

    return model, dirty, restored