Repository navigation
DynamicalPowerspectrum and DynamicalCrossspectrum cannot select the per-segment mean (use_common_mean) - #987
Open
bjricketts wants to merge 5 commits into
Open
bjricketts wants to merge 5 commits into
bjricketts wants to merge 5 commits into
Conversation
Contributor
Author
matteobachetti
requested changes
Sep 23, 2026
matteobachetti
left a comment
Member
There was a problem hiding this comment.
Thanks @bjricketts !
My main concern here is the poisson level machinery. I think it should be calculated per-segment if use_common_mean is False.
Other minor comments below
| ) | ||
| conv = avg.cs_all / avg.unnorm_cs_all | ||
| self.unnorm_conversion = np.nanmean(conv) | ||
| conv = np.asarray(avg.cs_all) / np.asarray(avg.unnorm_cs_all) |
Member
There was a problem hiding this comment.
Now that we are at it, maybe better to use np.asanyarray?
Co-authored-by: Matteo Bachetti <matteo@matteobachetti.it>
Co-authored-by: Matteo Bachetti <matteo@matteobachetti.it>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Relevant Issue(s)/PR(s)
Closes #986
Provide an overview of the implemented solution or the fix and elaborate on the modifications.
AveragedPowerspectrumandAveragedCrossspectrumalready takeuse_common_mean. The dynamical classes build their matrix from those objects but never accepted or passed the flag, so every column was normalised by the mean count rate of the whole observation and the per-segment option was unreachable. This adds the argument to both classes and passes it through. The default isTrue, so existing behaviour is unchanged.With
norm="frac"anduse_common_mean=False, each column is normalised by its own mean count rate, which is what you want when comparing the columns with each other: a change in count rate at constant fractional rms, as produced by a linear rms-flux relation, no longer rescales the matrix.Changes:
DynamicalCrossspectrum.__init__andDynamicalPowerspectrum.__init__takeuse_common_mean=Trueand store it;_make_matrixpasses it to the averaged spectrum.use_common_meanis documented as a parameter and an attribute, and thenormentry now says which mean the normalisation uses.unnorm_conversionis a per-segment array whenuse_common_mean=False. This factor converts normalised back to unnormalised powers and is used bycompute_rms; with a per-segment mean it differs from segment to segment, so the previousnp.nanmean(conv)over the whole matrix would have madecompute_rmswrong. It is constant across frequency within a segment, so the mean over frequency is exact. The scalar is kept whenuse_common_mean=True.compute_rmsindexes that factor per segment, so its result is now independent of the flag (there is a test for this).rebin_timeandrebin_by_n_intervalscarry the array along so it stays the same length as the time axis.DynamicalPowerspectrum.power_colorswarns whenuse_common_mean=Falseand nopoisson_poweris given, because the default level is computed frommeanrate, which is still the mean over the whole observation.Any other comments?
A per-segment
meanratearray and apoisson_levelproperty orsubtract_poisson_noise()would be relevant additions. Those would needavg_pds_from_iterablesandavg_cs_from_iterablesto keep the per-segment photon counts, and turning the existing scalarmeanrateinto an array would also breakpower_colors.