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
Handle the limit of p = 0 in p log2 p #3
Conversation
This patch defines a helper function, _xlog2x(x), that calculates x * log2(x) but handles the case x == 0 by returning 0 rather than nan. This is needed if the power spectrum has any component that is exactly zero: in particular, if the f = 0 component is zero.
Hi @jftsang, Thanks for the PR! A few questions:
Thanks, |
Hi @raphaelvallat,
Cheers, |
This is all perfect, thanks! One last thing before I merge: can you add your changes to the docs/changelog.rst file (with link to the current PR and if desired your GitHub username)? You'll need to start a new version of antropy, i.e. v0.1.5 Cheers, |
Done! I've also added a couple of unit tests. ~JMFT |
Merging now, thanks again for the PR! |
Having tested this on a very large file, I have just realised that this |
Follow up to raphaelvallat#3 Using np.nan_to_num is advantageous because it makes use of numpy's vectorization, instead of 'if x == 0', which applies the test pointwise.
Follow up to raphaelvallat#3. Using `np.where` is advantageous because it makes use of numpy's vectorization, instead of `if x == 0`, which applies the test pointwise. Using `@jit(nopython=True)` is also advantageous.
This patch defines a helper function, _xlog2x(x), that calculates
x * log2(x) but handles the case x == 0 by returning 0 rather than nan.
This is needed if the power spectrum has any component that is exactly
zero: in particular, if the f = 0 component is zero.