Exemple #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
Exemple #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
 def test_deconvolve_and_restore_cube_mmclean(self):
     self.bigmodel.data *= 0.0
     visres, model, residual = solve_image(self.vis,
                                           self.bigmodel,
                                           nmajor=3,
                                           niter=1000,
                                           threshold=0.01,
                                           gain=0.7,
                                           window='quarter',
                                           scales=[0, 3, 10],
                                           fractional_threshold=0.1,
                                           algorithm='mmclean',
                                           nmoments=3)
     export_image_to_fits(
         model, '%s/test_solve_image_mmclean_solution.fits' % (self.dir))
     residual, sumwt = invert_2d(visres, model)
     export_image_to_fits(
         residual, '%s/test_solve_image_mmclean_residual.fits' % (self.dir))
     psf, sumwt = invert_2d(self.vis, model, dopsf=True)
     export_image_to_fits(
         psf, '%s/test_solve_image_mmclean_psf.fits' % (self.dir))
     restored = restore_cube(model=model, psf=psf, residual=residual)
     export_image_to_fits(
         restored, '%s/test_solve_image_mmclean_restored.fits' % (self.dir))
     assert numpy.max(numpy.abs(residual.data)) < 1.2
 def test_deconvolve_and_restore_cube_hogbom(self):
     self.bigmodel.data *= 0.0
     visres, model, _ = solve_image(self.vis,
                                    self.bigmodel,
                                    nmajor=5,
                                    niter=1000,
                                    threshold=0.01,
                                    gain=0.1,
                                    psf_support=200,
                                    window='quarter',
                                    fractional_threshold=0.1,
                                    algorithm='hogbom')
     assert numpy.max(numpy.abs(model.data)) > 0.0, "Model image is empty"
     export_image_to_fits(
         model,
         '%s/test_solve_skycomponent_hogbom_solution.fits' % (self.dir))
     residual, sumwt = invert_2d(visres, model)
     export_image_to_fits(
         residual,
         '%s/test_solve_skycomponent_msclean_residual.fits' % (self.dir))
     psf, sumwt = invert_2d(self.vis, model, dopsf=True)
     export_image_to_fits(
         psf, '%s/test_solve_skycomponent_hogbom_psf.fits' % (self.dir))
     restored = restore_cube(model=model, psf=psf, residual=residual)
     export_image_to_fits(
         restored,
         '%s/test_solve_skycomponent_hogbom_restored.fits' % (self.dir))
     assert numpy.max(numpy.abs(residual.data)) < 0.5
Exemple #5
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
Exemple #6
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
Exemple #9
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
Exemple #10
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)
Exemple #11
0
def restore_list_serial_workflow(model_imagelist, psf_imagelist,
                                 residual_imagelist, **kwargs):
    """ Create a graph to calculate the restored image

    :param model_imagelist: Model list
    :param psf_imagelist: PSF list
    :param residual_imagelist: Residual list
    :param kwargs: Parameters for functions in components
    :return:
    """
    return [
        restore_cube(model_imagelist[i], psf_imagelist[i][0],
                     residual_imagelist[i][0], **kwargs)
        for i, _ in enumerate(model_imagelist)
    ]
 def test_restore(self):
     self.cmodel = restore_cube(self.model, self.psf)
Exemple #13
0
def dprepb_imaging(vis_input):
    """The DPrepB/C imaging pipeline for visibility data.
        
    Args:
    vis_input (array): array of ARL visibility data and parameters.
    
    Returns:
    restored: clean image.
    """
    # Load the Input Data
    # ------------------------------------------------------
    vis1 = vis_input[0]
    vis2 = vis_input[1]
    channel = vis_input[2]
    stations = vis_input[3]
    lofar_stat_pos = vis_input[4]
    APPLY_IONO = vis_input[5]
    APPLY_BEAM = vis_input[6]
    MAKE_PLOTS = vis_input[7]
    UV_CUTOFF = vis_input[8]
    PIXELS_PER_BEAM = vis_input[9]
    POLDEF = vis_input[10]
    RESULTS_DIR = vis_input[11]
    FORCE_RESOLUTION = vis_input[12]
    ionRM1 = vis_input[13]
    times1 = vis_input[14]
    time_indices1 = vis_input[15]
    ionRM2 = vis_input[16]
    times2 = vis_input[17]
    time_indices2 = vis_input[18]
    twod_imaging = vis_input[19]
    npixel_advice = vis_input[20]
    cell_advice = vis_input[21]

    # Make a results directory on the worker:
    os.makedirs(RESULTS_DIR, exist_ok=True)

    # Redirect stdout, as Dask cannot print on workers
    # ------------------------------------------------------
    sys.stdout = open('%s/dask-log.txt' % (RESULTS_DIR), 'w')

    # Prepare Measurement Set
    # ------------------------------------------------------
    # Combine MSSS snapshots:
    vis = append_visibility(vis1, vis2)

    # Apply a uv-distance cut to the data:
    vis = uv_cut(vis, UV_CUTOFF)

    # Make some basic plots:
    if MAKE_PLOTS:
        uv_cov(vis)
        uv_dist(vis)

    # Imaging and Deconvolution
    # ------------------------------------------------------
    # Convert from XX/XY/YX/YY to I/Q/U/V:
    vis = convert_to_stokes(vis, POLDEF)

    # Image I, Q, U, V, per channel:
    if twod_imaging:
        dirty, psf = image_2d(vis, npixel_advice, cell_advice, channel,
                              RESULTS_DIR)
    else:
        dirty, psf = wstack(vis, npixel_advice, cell_advice, channel,
                            RESULTS_DIR)

    # Deconvolve (using complex Hogbom clean):
    comp, residual = deconvolve_cube_complex(dirty,
                                             psf,
                                             niter=100,
                                             threshold=0.001,
                                             fracthresh=0.001,
                                             window_shape='',
                                             gain=0.1,
                                             algorithm='hogbom-complex')

    # Convert resolution (FWHM in arcmin) to a psfwidth (standard deviation in pixels):
    clean_res = (((FORCE_RESOLUTION / 2.35482004503) / 60.0) * np.pi /
                 180.0) / cell_advice

    # Create the restored image:
    restored = restore_cube(comp, psf, residual, psfwidth=clean_res)

    # Save to disk:
    export_image_to_fits(
        restored, '%s/imaging_clean_WStack-%s.fits' % (RESULTS_DIR, channel))

    return restored
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