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

Photon power law #103

Merged
merged 26 commits into from Sep 19, 2023
Merged

Photon power law #103

merged 26 commits into from Sep 19, 2023

Conversation

settwi
Copy link
Contributor

@settwi settwi commented Jun 5, 2023

PR

PR Description

Adds photon space broken power law.

Compare with f_bpow and bknpower.

The broken power law bins flux properly and uses an analytical antiderivative of a power law to do so.
The documentation is (mostly?) in line with other stuff I've seen in sunxspex so far.
Needs more tests!

Fixes #101

@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2023

Codecov Report

Patch coverage: 97.77% and project coverage change: +0.60% 🎉

Comparison is base (c40792c) 55.06% compared to head (9da8014) 55.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #103      +/-   ##
==========================================
+ Coverage   55.06%   55.66%   +0.60%     
==========================================
  Files          19       20       +1     
  Lines        3122     3167      +45     
==========================================
+ Hits         1719     1763      +44     
- Misses       1403     1404       +1     
Files Changed Coverage Δ
sunxspex/photon_power_law.py 97.77% <97.77%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@settwi
Copy link
Contributor Author

settwi commented Jun 5, 2023

The Python 3.7 checks will always fail because I'm using the walrus operator

Copy link
Member

@DanRyanIrish DanRyanIrish left a comment

Choose a reason for hiding this comment

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

Hi @settwi. This looks good. Could you convert the "plot test" into an actual test where you check the output values?

@settwi
Copy link
Contributor Author

settwi commented Jun 5, 2023

Yes! I'll work on that today. Thank you

Copy link
Collaborator

@samaloney samaloney left a comment

Choose a reason for hiding this comment

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

Nice additions @settwi comments below are more of a discussion for us all have rather than you to address/fix

  • Would a power_law_binned_flux be useful I know it can be achieved using the break energy but that's kinda opaque
  • Type annotations I'm a fan but we should probably make a decision as package/group
  • Is the root folder the correct place for these kind of functions
  • There are similar functions but for electrons in the thick target models could they be combined/integrated - less code is better than more code

sunxspex/photon_power_law.py Outdated Show resolved Hide resolved
changelog/103.feature.rst Show resolved Hide resolved
sunxspex/photon_power_law.py Show resolved Hide resolved
sunxspex/photon_power_law.py Outdated Show resolved Hide resolved
sunxspex/photon_power_law.py Outdated Show resolved Hide resolved
@settwi
Copy link
Contributor Author

settwi commented Jun 6, 2023

@samaloney thanks for the feedback! I'll address the style and testing feedback hopefully today and push up the changes.

@settwi
Copy link
Contributor Author

settwi commented Jun 9, 2023

I squashed a couple bugs, adjusted the formatting, and tried to address the testing concerns that folks mentioned. Please take a look and let me know if other things need to change. Thanks!

PS: i am stuck trying to get Sphinx to properly build. weird indentation errors. ugh

@samaloney @DanRyanIrish @KriSun95

settwi and others added 2 commits June 14, 2023 16:54
Co-authored-by: Shane Maloney <maloneys@tcd.ie>
Co-authored-by: Shane Maloney <maloneys@tcd.ie>
@settwi
Copy link
Contributor Author

settwi commented Jun 15, 2023

Thanks for the fixes @samaloney I am not sure why but I couldn't get my local Sphinx to build the documentation without errors

Are we good to merge?

@samaloney
Copy link
Collaborator

No worries a fresh install in a clean virtual env e.g. pip install -e .[dev] and it should just work but can be finicky.

As far as code is concerned I think the PR is good to go but I think there some 'meta' issues that need to be discussed I had suggest at the proposed monthly call?

@settwi
Copy link
Contributor Author

settwi commented Jun 21, 2023

@DanRyanIrish and @samaloney can we say your revisions have been satisfied and merge the PR?

@KriSun95
Copy link
Collaborator

KriSun95 commented Jul 6, 2023

I think this PR might be ready to merge. Should we add it in?

@settwi
Copy link
Contributor Author

settwi commented Jul 12, 2023

@samaloney @DanRyanIrish could one of you approve the PR if you think it's good to go?

Copy link
Member

@DanRyanIrish DanRyanIrish left a comment

Choose a reason for hiding this comment

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

This looks OK to me. A couple general style points though.

I think it's good practice to have readable variable names. In the tests and main code there are several 2- and 3-letter variable names that are not descriptive, making the code harder to understand.

Similarly, it's good practice name functions with verbs. That way you can tell it's a function/method from its name., e.g. power_law_binned_flux -> calculate_power_law_binned_flux

sunxspex/tests/test_photon_power_law.py Show resolved Hide resolved
Comment on lines +3 to +5
import numpy as np

import astropy.units as u
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import numpy as np
import astropy.units as u
import astropy.units as u
import numpy as np

See section on ordering imports in PEP 8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually ran autopep8 on this file multiple times :p

It looks like this example given in the PEP8 "Imports" section shows that the foo.bar package should be imported second?

import myclass
import foo.bar.yourclass

@settwi
Copy link
Contributor Author

settwi commented Jul 12, 2023 via email

Copy link
Member

@hayesla hayesla left a comment

Choose a reason for hiding this comment

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

this looks great @settwi!

changelog/103.feature.rst Outdated Show resolved Hide resolved
def compute_broken_power_law(
energy_edges: u.keV,
reference_energy: u.keV,
reference_flux: PHOTON_RATE_UNIT,
Copy link
Member

Choose a reason for hiding this comment

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

if there a reason this is called "reference_flux" rather that "normalization"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think it's an artifact from when the function had a slightly different implementation. i'll update the name!

reference_energy : `astropy.units.Quantity`
Energy at which the normalization is applied, i.e. :math:`E_0`.
reference_flux : `astropy.units.Quantity`
Normalization flux for the photon power law.
Copy link
Member

Choose a reason for hiding this comment

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

I would also add another description here for what this normalisation is

Copy link
Member

@DanRyanIrish DanRyanIrish left a comment

Choose a reason for hiding this comment

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

Hi @settwi. Sorry for taking so long to look at this. It also also looks good to me, although I notice a couple of the tests are failing. I've set the tests rerunning. Once they are passing and @hayesla's comments are addressed, we should get this merged!

@settwi
Copy link
Contributor Author

settwi commented Jul 24, 2023

hey @DanRyanIrish @hayesla i will implement Laura's comments. thanks for checking in.
as for the tests: i think some of them are not my fault that they don't pass. for one of them there is something messed up on the CI side i believe. the ones that i can fix i will fix though.
thanks!

@settwi
Copy link
Contributor Author

settwi commented Aug 9, 2023

@hayesla and @DanRyanIrish i've implemented Laura's comments and i think things are good to go. i know some tests are failing but i think most of them are out of my hands...

@settwi
Copy link
Contributor Author

settwi commented Sep 3, 2023

@samaloney @DanRyanIrish could you mark the pending changes as approved?

@KriSun95
Copy link
Collaborator

@settwi reminded me of a conversation with @DanRyanIrish at SPD that this was OK to be accepted from his point of view so, before any larger changes are made to the repo, I'm going to merge this PR. Any other changes down the line can be addressed in the refactoring.

@KriSun95 KriSun95 dismissed DanRyanIrish’s stale review September 19, 2023 17:00

Conversation at SPD with Dan made clear he was happy to accept the PR but physically couldn't at the time.

@KriSun95 KriSun95 merged commit 8155913 into sunpy:master Sep 19, 2023
5 of 10 checks passed
@settwi settwi deleted the photon-power-law branch September 19, 2023 17:15
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.

Photon-space broken power law
6 participants