Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: scaling factor for window with negative value#25122

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
oscargus merged 5 commits intomatplotlib:mainfromgapplef:patch-1
Feb 7, 2023

Conversation

gapplef
Copy link
Contributor

@gapplefgapplef commentedFeb 1, 2023
edited by oscargus
Loading

PR Summary

Simply drop thenp.abs() on window to fix the wrong scaling factor for window with negative value. For more detail refer to#24821

Caution: With this fix, the behavior would change for window with complex value.
Withnp.abs() on window, it seems can handle complex value, but I don't think it's the right way to do it. As it can't fall back to real value case for complex value with zero imaginary part and negative real part (for example -1 + 0j).
Also, I didn't understand the need for complex window, so here I simply ignore the complex case. And this is consistent with the implementation ofscipy.

Closes#24821

Related to#22828 (not sure it can be closed, that seems to try to deal with the complex case as well, but is there one?).

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

Simply drop the `np.abs()` on window to fix the wrong scaling factor for window with negative value.For more detail refer tomatplotlib#24821**Caution**: With this fix, the behavior would change for window with complex value.With `np.abs()` on window, it seems can handle complex value, but I don't think it's the right way to do it. As it can't fall back to real value case for complex value with zero imaginary part and negative real part (for example -1 + 0j).Also, I didn't understand the need for complex window, so here I simply ignore the complex case. And this is consistent with the implementation of [scipy](https://github.com/scipy/scipy/blob/d9f75db82fdffef06187c9d8d2f0f5b36c7a791b/scipy/signal/_spectral_py.py#L1854-L1859).
@jklymak
Copy link
Member

I think these are correct. Can you add some tests, particularly if you can somehow create a flattop w/o using scipy (we don't use it for our tests, unfortunately). For tests, I'd calculate the spectrum of random numbers and just show that its average equals an expected value, perhaps with a bit of floating point slop (np.testing.allclose)?

I don't think this needs a what's new or anything - it only applies to windows with negative co-efficients, which are relatively rare.

@jklymakjklymak added this to thev3.7.1 milestoneFeb 1, 2023
Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

Add new test function for scale factor of flattop window.Also remove the unnecessary `np.abs()` on window in other functions.
@gapplef
Copy link
ContributorAuthor

I have add the new functiontest_psd_window_flattop, with reference totest_psd_window_hanning andtest_psd_windowarray_scale_by_freq.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

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

Looks close to me. Not sure about some of the testing details so please check. Note we expect all the code in tests to be run, so please remove the dead block.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and discussion that lead to it! The lint issue needs to be dealt with, and we need a second review, but I believe this is correct and should go in...

@oscargus
Copy link
Member

Agree that the second abs in#4328 was not really on purpose (since it was not tested for) and that this should be the correct fix.

Should we close#22828?

@oscargus
Copy link
Member

Thanks@gapplef and congratulations on your first merged PR! Hope to see you around!

@gapplef
Copy link
ContributorAuthor

🎉 🎊 Thanks for your discussion and help!@jklymak@oscargus

@ksundenksunden modified the milestones:v3.7.1,v3.7.0Feb 9, 2023
@ksundenksunden mentioned this pull requestFeb 20, 2023
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@oscargusoscargusoscargus approved these changes

Assignees
No one assigned
Projects
Milestone
v3.7.0
Development

Successfully merging this pull request may close these issues.

[Bug]: Windows correction is not correct inmlab._spectral_helper
4 participants
@gapplef@jklymak@oscargus@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp