Commit 2015f2af authored by Andrew Quinn's avatar Andrew Quinn
Browse files

Merge branch '18-add-pole-pair-identification-function-to-modal' into 'master'

WIP: Resolve "add pole-pair identification function to modal"

See merge request !15
parents 6251708d 8ed66b3b
Loading
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -862,3 +862,34 @@ def get_cluster_average(clusters, vals):
        out[..., c] = vals[..., clusters == c].mean(axis=-1)

    return out


def find_pole_pairs(pole_inds, mode_indices):
    """Find pole pairs within a subset of the poles. Useful for recombining
    poles into pairs after model-reduction or thresholding.

    """

    # Make sure that we track the modes as pairs of poles where necessary
    thresh_modes = []
    thresh_modes_extracted = []
    seen_inds = []
    idx = 0
    for pole in pole_inds:
        if pole in seen_inds:
            continue
        foundmode = None
        for mode in mode_indices:
            if pole in mode:
                foundmode = mode
                break
        if foundmode is None:
            raise Exception("Could not find pole")
        for pole in foundmode:
            seen_inds.append(pole)
            thresh_modes_extracted.append(idx)
            idx += 1

        thresh_modes.append(foundmode)

    return thresh_modes