Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postprocessing: filter those too-close phase picks and save just one of them #139

Open
JUNZHU-SEIS opened this issue Nov 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@JUNZHU-SEIS
Copy link
Contributor

Similar to PhaseNet, a minimal separation could be set to filter those picks too-close to each other and only save the most significant one.
More details are in lines 26-28 from https://github.com/AI4EPS/PhaseNet/blob/master/phasenet/detect_peaks.py

@yetinam
Copy link
Member

yetinam commented Nov 8, 2022

Hey @JUNZHU-SEIS,

I agree, that would indeed be a good helper function. Maybe it could go into seisbench.util? There could also be a weighting factor between phase types because different phases tend to have different confidences.

Would you be interested in writing a PR for this?

@yetinam yetinam added the enhancement New feature or request label Nov 8, 2022
@JUNZHU-SEIS
Copy link
Contributor Author

Hi, @yetinam
Sorry for the delayed response.
Here I provide a function to achieve "removing too close picks". Hope it useful and can be adopted in the seisbench.util.

def remove_too_close_detections(detections, charfct, win=100):
# parameter description:
#               detections: An ndarry of indices of P picks or S picks. Do NOT use both the P and S picks.
#               charfct: Probability vector of the corresponding phase (i.e., model output). It is also an ndarry object.
#               win: the minimal separation between consecutive picks
# return:
#               uniqs: a subset of the detections, with close picks removed and highest picks saved
#               deleted_pool: a list of the removed picks

    deleted_pool = []
    uniqs = set()
    for i,win_s in enumerate(detections[:-1]):
        # if the current pick (win_s) is in the list of deleted_pool (see below for how the pool is defined), skip the loop
        if win_s in deleted_pool: continue
        win_e = win_s + win # the window following the current pick with a length of win
        densedetections = detections[i+1:][detections[i+1:]<win_e] # find picks in the window [win_s+1: win_s+win]
        if len(densedetections):
            # if there exist more than one pick in the window, only save the pick with the highest probability and delete the others
            all = np.insert(densedetections, 0, win_s)
            deleted_pool.extend(all)
            highestpeak = all[np.argmax(charfct[all])]
            uniqs.add(highestpeak)
            deleted_pool.remove(highestpeak)
        else:
            # otherwise, if no pick in the window, save the current pick 
            uniqs.add(win_s)
    deleted_pool = list(set(deleted_pool))
    uniqs = np.sort(np.array(list(uniqs)))
    return uniqs,deleted_pool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants