示例#1
0
    def deconvolve(dirty, psf, model, facet, gthreshold, msk=None):
        if prefix == '':
            lprefix = "facet %d" % facet
        else:
            lprefix = "%s, facet %d" % (prefix, facet)

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

        if this_peak > 1.1 * gthreshold:
            kwargs['threshold'] = gthreshold
            result, _ = deconvolve_cube(dirty,
                                        psf,
                                        prefix=lprefix,
                                        mask=msk,
                                        **kwargs)

            if result.data.shape[0] == model.data.shape[0]:
                result.data += model.data
            return result
        else:

            return copy_image(model)
    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_list_serial_workflow %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_list_serial_workflow %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_list_serial_workflow %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)
    def load_invert_and_deconvolve(c):

        v1 = create_visibility_from_ms(input_vis[0], channum=[c])[0]
        v2 = create_visibility_from_ms(input_vis[1], channum=[c])[0]
        vf = append_visibility(v1, v2)
        vf = convert_visibility_to_stokes(vf)
        vf.configuration.diameter[...] = 35.0
        rows = vis_select_uvrange(vf, 0.0, uvmax=uvmax)
        v = create_visibility_from_rows(vf, rows)

        pol_frame = PolarisationFrame("stokesIQUV")

        m = create_image_from_visibility(v,
                                         npixel=npixel,
                                         cellsize=cellsize,
                                         polarisation_frame=pol_frame)

        if context == '2d':
            d, sumwt = invert_2d(v, m, dopsf=False)
            p, sumwt = invert_2d(v, m, dopsf=True)
        else:
            d, sumwt = invert_list_serial_workflow([v], [m],
                                                   context=context,
                                                   dopsf=False,
                                                   vis_slices=vis_slices)[0]
            p, sumwt = invert_list_serial_workflow([v], [m],
                                                   context=context,
                                                   dopsf=True,
                                                   vis_slices=vis_slices)[0]
        c, resid = deconvolve_cube(d,
                                   p,
                                   m,
                                   threshold=0.01,
                                   fracthresh=0.01,
                                   window_shape='quarter',
                                   niter=100,
                                   gain=0.1,
                                   algorithm='hogbom-complex')
        r = restore_cube(c, p, resid, psfwidth=psfwidth)
        return r
 def deconvolve_subimage(dirty, psf):
     assert isinstance(dirty, Image)
     assert isinstance(psf, Image)
     comp = deconvolve_cube(dirty, psf, **kwargs)
     return comp[0]
     bvt.configuration.diameter[...] = 35.0
     vt = convert_blockvisibility_to_visibility(bvt)
     vt = convert_visibility_to_stokes(vt)
     
     cellsize = 20.0 * numpy.pi / (180.0 * 3600.0)
     npixel = 512
     
     model = create_image_from_visibility(vt, cellsize=cellsize, npixel=npixel,
                                          polarisation_frame=PolarisationFrame('stokesIQUV'))
     dirty, sumwt = invert_list_serial_workflow([vt], [model], context='2d')[0]
     psf, sumwt = invert_list_serial_workflow([vt], [model], context='2d', dopsf=True)[0]
     export_image_to_fits(dirty, '%s/compare_imaging_sim2_dirty.fits' % (results_dir))
     export_image_to_fits(psf, '%s/compare_imaging_sim2_psf.fits' % (results_dir))
     
     # Deconvolve using clean
     comp, residual = deconvolve_cube(dirty, psf, niter=10000, threshold=0.001, fractional_threshold=0.001,
                                      window_shape='quarter', gain=0.7, scales=[0, 3, 10, 30])
     
     restored = restore_cube(comp, psf, residual)
     export_image_to_fits(restored, '%s/compare_imaging_sim2_restored.fits' % (results_dir))
     export_image_to_fits(residual, '%s/compare_imaging_sim2_residual.fits' % (results_dir))
     
     qa = qa_image(restored)
     
     assert numpy.abs(qa.data['max'] - 1.006140596404203) < 1e-7, qa
     assert numpy.abs(qa.data['maxabs'] - 1.006140596404203) < 1e-7, qa
     assert numpy.abs(qa.data['min'] + 0.23890808520954754) < 1e-7, qa
     assert numpy.abs(qa.data['rms'] - 0.007366519782047875) < 1e-7, qa
     assert numpy.abs(qa.data['medianabs'] - 0.0005590537883509844) < 1e-7, qa
 except ModuleNotFoundError as error:
     print(error.__class__.__name__ + ": " + error.msg)
     pass