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

fix(rfi): fix misalignment between mask and data in sumthreshold #272

Merged
merged 2 commits into from
May 28, 2024

Conversation

ssiegelx
Copy link
Contributor

Also removes unnecessary slices.

@ssiegelx ssiegelx requested a review from ljgray May 28, 2024 15:16
@ssiegelx
Copy link
Contributor Author

Here is a simple example illustrating what I think is a bug in the sumthreshold method:

nx = 256
data = np.zeros(nx)

m = 32
i = nx // 2

data[i:(i+m)] = 1.0

## Taken from origin sumthreshold
centre = m // 2 - 1

dconv = convolve1d(data, weights=np.ones(m, dtype=float), origin=-centre)

flag_temp = dconv >= m

flag = np.zeros(nx, dtype=bool)
for ii in range(nx - m + 1):
    flag[ii:(ii+m)] += flag_temp[ii]


plt.plot(data, marker='o', color='k')
plt.plot(dconv / m, color='b')
plt.plot(flag, color='r')

Screenshot 2024-05-28 at 11 20 00 AM

You can see that instead of the signal being flagged, the data immediately after the signal is flagged.

Here is the result if we use origin=centre instead:
Screenshot 2024-05-28 at 11 24 21 AM
The mask is properly aligned with the excursion.

@ljgray
Copy link
Contributor

ljgray commented May 28, 2024

Interesting - is the behaviour the same if m is odd?

@ssiegelx
Copy link
Contributor Author

For m = 1 it will be properly aligned, but for other odd values of m there will be a shift that is proportional to the size of the window.

@ssiegelx ssiegelx merged commit 7da7e03 into master May 28, 2024
4 checks passed
@ssiegelx ssiegelx deleted the ss/sumthreshold-bug branch May 28, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants