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
Add function to determine pivot energy for any spectral model #4635
Conversation
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty,
Really helpful feature ! See inline comments.
Thanks a lot @Astro-Kirsty . With this PR, I think that it would be great to have some tutorials with this new feature.... e.g. the spectral analysis or 3D detailed analysis |
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty !
Is is sufficient to see the thinnest band among the range of energies supplied by the user? The decorrelation energy may not even lie in the given range.
If the energy array is too coarsely binned, the estimate will be incorrect. Finding the minima of the error might be better, no?
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Codecov Report
@@ Coverage Diff @@
## main #4635 +/- ##
==========================================
- Coverage 95.09% 95.06% -0.04%
==========================================
Files 222 221 -1
Lines 31750 31561 -189
==========================================
- Hits 30193 30002 -191
- Misses 1557 1559 +2
... and 21 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Thanks @Astro-Kirsty ! This looks better, but it is still an issue that this does not guarantee you are returning the decorrelation energy. This is just the minimum error point in the given range (without letting users know if the actual pivot lies outside). I tried with
maybe an option? What do you think? |
I agree @AtreyeeS. Using |
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Implemented the code using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty .
fsolve
is a root finder, not a minimizer. Is it really adapted here? Shouldn't one use something like minimize_scalar
instead?
Those methods require an interval to search for the minimum. We have to see if it is possible to keep pivot_energy
a simple property in this context.
One should probably check that a proper minimum is found and yield an error if not.
An option would be to implement: where the bounds are predefined by default as the And as you mention, to add that if the minimizer is not successful, then it should alert the user |
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Updated to make sure there is no issue with units. Added an if statement for the std. The scipy minimize functions will always minimize a function, even if there is no minimum (i.e. a constant array of values). Hence providing the user with an incorrect, nonsensical pivot energy. Therefore, adding this if statement takes care of this. I also adapted the test functions to ensure this was included. |
Thanks @Astro-Kirsty . There is a test failing, could you increase the tolerance? I suppose the method won't be precise below the percent. |
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Thanks @registerrier. It was not failing on my laptop which is odd. I have increased the tolerance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty . This looks good.
The only missing thing to me is a test with some correlation. e.g. use an exp-cutoff with the same parameters and correlation matrix as the PWL test and check you get the same result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty this is a nice feature, I have just one question :
|
||
bounds = [np.log(self.reference.value) - 3, np.log(self.reference.value) + 3] | ||
|
||
std = np.std(min_func(x=np.linspace(bounds[0], bounds[1], 100))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the choice of the number of steps in linespace can affect the precision ?
If yes it should be configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! no more comments from me
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
Signed-off-by: Astro-Kirsty <AstroKirsty@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty, all good for me.
I am still wondering if one could not have an optional argument about the energy range of computation. But this can be added later if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Astro-Kirsty,
Seems good to me !
Description
This PR is addressing the feature request from issue #4016.
I have added a
pivot_energy
function to theSpectralModel
class that finds the energy at which the error butterfly is minimum. This function is then 'overridden' in thePowerLawSpectralModel
where there is an analytical equation available.Please note: this must be performed in log space (as I understand) because the butterfly minimum occurs in the log space plot.
Dear reviewer
I am certainly open to suggestions/feedback on this issue.