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

Adding options for disabling normalization and noise label for ProbabilisticLabeller, and checking picks for AddGap and ChannelDropout. #222

Merged
merged 8 commits into from
Aug 11, 2023

Conversation

zhong-yy
Copy link
Contributor

@zhong-yy zhong-yy commented Aug 4, 2023

Changes

  1. Create an bool-type variable "noise_column" in the PickLabeller class to determine whether a noise label will be constructed. If the noise_column is false, no noise label will be created, and labels will not be normalized.
  2. Update the SupervisedLabeller::_check_labels() function
  3. Update test_probabilistic_pick_labeller()

A visual example

from seisbench.generate import ProbabilisticLabeller
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
p=50
s=100
state_dict = {
    "X": (
        10 * np.random.rand(3, 200),
        {
            "trace_p_arrival_sample": p,
            "trace_s_arrival_sample": s,
        },
    )
}
fig,axs=plt.subplots(4,2,sharex="all")

for i,noise_column in enumerate([True,False]):
    labeller = ProbabilisticLabeller(
        dim=0, shape="gaussian",sigma=20, noise_column=noise_column
    )
    labeller(state_dict)

    state_dict["y"][0].shape
    print(np.all(state_dict["y"][0]>=0))

    for j in range(3):
        ax=axs[j][i]
        ax.plot(state_dict["X"][0][j,:].T)
    axs[3][i].plot(state_dict["y"][0].T)
    axs[3][i].axvline(p,color="blue",label="True P")
    axs[3][i].axvline(s,color="red",label="True S")
axs[3][1].legend()

image

 PickLabeller class to determine whether a noise
label will be constructed. If the noise_column is false,
no noise label will be created, and labels will not be
normalized
@zhong-yy zhong-yy changed the title Add option for disabling normalization and noise label Add an option for disabling normalization and noise label for ProbabilisticLabeller/PickLabeller Aug 4, 2023
@yetinam
Copy link
Member

yetinam commented Aug 4, 2023

Thanks for the PR! I might take some days until I get around to review it.

@yetinam yetinam self-requested a review August 4, 2023 15:33
@yetinam yetinam added the enhancement New feature or request label Aug 4, 2023
@yetinam yetinam added this to the v0.5 milestone Aug 4, 2023
@zhong-yy
Copy link
Contributor Author

zhong-yy commented Aug 5, 2023

Hi @yetinam, I also added some checks for the output of AddGap() and ChannelDropout(), see #223.

If the waveform segment containing a phase is zeroed out after a gap is added, the corresponding phase arrival will be set to NaN. If all channels are zeros after dropping some channels, all arrival samples will be set to NaN.

@yetinam
Copy link
Member

yetinam commented Aug 5, 2023

Thanks for the addition. Please make the zeroing from ChannelDropout optional as well. I'll put an explanation in the issue thread. Could you also add two short unit tests for the new changes?

@yetinam
Copy link
Member

yetinam commented Aug 5, 2023

I'd suggest using np.allclose instead of np.isclose(np.sum())

waveforms.
Set the threshold for determining whether a pick is within
a gap.
@zhong-yy
Copy link
Contributor Author

zhong-yy commented Aug 6, 2023

Thank you for your feedback. I just add an option check_picks_in_gap for ChannelDropout. I also changed the criterion for deciding whether a pick within a gap will be ignored. If the pick is within the gap and it is far enough from the border of the gap, then the pick is made NaN.

I will add two unit tests tomorrow or in a few days.

- test_channel_dropout_with_picks_in_gap
- test_add_gap_with_picks_in_gap
@zhong-yy
Copy link
Contributor Author

zhong-yy commented Aug 9, 2023

Hi @yetinam, in the latest commit, I added some code to deal with the case of multiple windows, and two unit tests for AddGap() and ChannelDropout in the situation where waveform traces containing picks are zeroed out.

@zhong-yy zhong-yy changed the title Add an option for disabling normalization and noise label for ProbabilisticLabeller/PickLabeller Option for disabling normalization and noise label for ProbabilisticLabeller. Checking picks within gap after channel dropping or adding a gap. Aug 9, 2023
@zhong-yy zhong-yy changed the title Option for disabling normalization and noise label for ProbabilisticLabeller. Checking picks within gap after channel dropping or adding a gap. Adding options for disabling normalization and noise label for ProbabilisticLabeller, and checking picks for AddGap and ChannelDropout. Aug 9, 2023
- renamed parameter to avoid abbreviation
- parametrized probabilistic pick labeller test
Copy link
Member

@yetinam yetinam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now reviewed the PR. Looks good and the test are very comprehensive! Thanks for the addition. I've added some very minor changes and will merge the PR once the CI passes.

Once again, thanks a lot for your contribution!

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
2 participants