コード例 #1
0
def calskymodel_fit_gaintable(evis,
                              calskymodel,
                              gain=0.1,
                              niter=3,
                              tol=1e-3,
                              **kwargs):
    """Fit a gaintable to a visibility
    
    This is the update to the gain part of the window

    :param evis: Expected vis for this ssm
    :param calskymodel: csm element being fit
    :param gain: Gain in step
    :param niter: Number of iterations
    :param kwargs: Gaintable
    """
    previous_gt = copy_gaintable(calskymodel[1])
    gt = copy_gaintable(calskymodel[1])
    model_vis = copy_visibility(evis, zero=True)
    model_vis = predict_skymodel_visibility(model_vis, calskymodel[0])
    gt = solve_gaintable(evis,
                         model_vis,
                         gt=gt,
                         niter=niter,
                         phase_only=True,
                         gain=0.5,
                         tol=1e-4,
                         **kwargs)
    gt.data['gain'][...] = gain * gt.data['gain'][...] + (
        1 - gain) * previous_gt.data['gain'][...]
    gt.data['gain'][...] /= numpy.abs(previous_gt.data['gain'][...])
    return gt
コード例 #2
0
def create_modelpartition(vis: BlockVisibility, skymodels, **kwargs):
    """Create a set of associations between skymodel and gaintable

    :param vis: BlockVisibility to process
    :param skymodels: List of skyModels
    :param kwargs:
    :return:
    """
    gt = create_gaintable_from_blockvisibility(vis, **kwargs)
    return [(copy_skymodel(sm), copy_gaintable(gt)) for sm in skymodels]
コード例 #3
0
def solve_modelpartition(vis,
                         skymodels,
                         niter=10,
                         tol=1e-8,
                         gain=0.25,
                         **kwargs):
    """ Solve for model partitions

    Solve by iterating, performing E step and M step.

    :param vis: Initial visibility
    :param components: Initial components to be used
    :param gaintables: Initial gain tables to be used
    :param kwargs:
    :return: The individual data models and the residual visibility
    """
    model_partition = create_modelpartition(vis, skymodels=skymodels, **kwargs)

    for iter in range(niter):
        new_modelpartitions = list()
        evis_all = modelpartition_expectation_all(vis, model_partition)
        log.debug("solve_modelpartition: Iteration %d" % (iter))
        for window_index, csm in enumerate(model_partition):
            evis = modelpartition_expectation_step(vis,
                                                   evis_all,
                                                   csm,
                                                   gain=gain,
                                                   **kwargs)
            new_csm = modelpartition_maximisation_step(evis, csm, **kwargs)
            new_modelpartitions.append((new_csm[0], new_csm[1]))

            flux = new_csm[0].components[0].flux[0, 0]
            qa = qa_gaintable(new_csm[1])
            residual = qa.data['residual']
            rms_phase = qa.data['rms-phase']
            log.debug(
                "solve_modelpartition:\t Window %d, flux %s, residual %.3f, rms phase %.3f"
                % (window_index, str(flux), residual, rms_phase))

        model_partition = [(copy_skymodel(csm[0]), copy_gaintable(csm[1]))
                           for csm in new_modelpartitions]

    residual_vis = copy_visibility(vis)
    final_vis = modelpartition_expectation_all(vis, model_partition)
    residual_vis.data['vis'][
        ...] = vis.data['vis'][...] - final_vis.data['vis'][...]
    return model_partition, residual_vis
 def create_calskymodel(vis, skymodel):
     gt = create_gaintable_from_blockvisibility(vis, **kwargs)
     return (copy_skymodel(skymodel), copy_gaintable(gt))