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

Add Corsika7ID (+converter) and Particle.from_nucleus() #426

Merged
merged 30 commits into from
Oct 27, 2022

Conversation

The-Ludwig
Copy link
Contributor

@The-Ludwig The-Ludwig commented Oct 11, 2022

I didn't find a user friendly method to convert a Corsika 7 ID to standard PDGID, so I tried to implement it here.

While implementing it, I noticed there was no function to easily generate nucleus particles, so I added function Particle.from_nucleus(), which first generates the right PDGID out of the nucleus properties (according to this pdf) and then uses Particle.from_pdgid.

For the implementation of Corsika7ID I tried to copy the style of the other IDs. I hope it is okay-ish like this.

Next comment moved to Issue #427.
While working on this I was wondering: Would it be a good idea to implement an abstract base class like

from abc import ABC, abstractmehtod

class ForeignParticleID(ABC, int):
    @abstractmethod
    def to_pdgid() -> PDGID:
        pass

to let the other IDs present in this library inherit from this. Then we could have a method like Particle.from_foreign_id(id: ForeignParticleID).

The-Ludwig and others added 9 commits October 11, 2022 17:02
- added the class Corsika7ID (adapted from the class Geant3ID)
- some tests for the class
- added the script that generated the conversion table
- Corsika7ID has some functionality to see if conversion to PDGID is
  sensible: Check if the Corsika7ID relates to a particle via
  .is_particle(), get the human readable name via .name()
- This allows easy conversion from the corsika7 output to Corsika7ID
More structured order
Copy link
Contributor Author

@The-Ludwig The-Ludwig left a comment

Choose a reason for hiding this comment

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

Noticed a weird import order, fixed that

@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2022

Codecov Report

Base: 90.79% // Head: 89.94% // Decreases project coverage by -0.85% ⚠️

Coverage data is based on head (cffa874) compared to base (17e6595).
Patch coverage: 76.74% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #426      +/-   ##
==========================================
- Coverage   90.79%   89.94%   -0.86%     
==========================================
  Files          29       32       +3     
  Lines        1326     1412      +86     
==========================================
+ Hits         1204     1270      +66     
- Misses        122      142      +20     
Impacted Files Coverage Δ
src/particle/particle/particle.py 90.74% <68.75%> (-0.85%) ⬇️
src/particle/corsika/corsika7id.py 75.43% <75.43%> (ø)
src/particle/corsika/__init__.py 80.00% <80.00%> (ø)
src/particle/__init__.py 92.85% <100.00%> (+0.54%) ⬆️
src/particle/converters/__init__.py 87.50% <100.00%> (+1.78%) ⬆️
src/particle/converters/corsika.py 100.00% <100.00%> (ø)
src/particle/pdgid/functions.py 87.17% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@eduardo-rodrigues
Copy link
Member

Hello @The-Ludwig, thank you for the interest in the package and this contribution. I will look at it asap. Certainly we are always keen on including more links to other MC IDs ...

I very much prefer scoped MRs. Also it is often better to start some discussion with the maintainers before actual commits, to streamline the route to follow.

Can you move your discussion on ForeignParticleID to an actual separate "issue"?

As said I will look asap. This being said, why do you say there was a need for something like Particle.from_nucleus()? Could you not make the nucleus Particle with the finditer() method given that it provides a powerful "filtering" with lambda functions? To be seen if the lack of way was not more like a lack of an example.

@The-Ludwig
Copy link
Contributor Author

The-Ludwig commented Oct 12, 2022

Hej @eduardo-rodrigues, thanks for the reply!

Yes, I realized this PR went a little all over the place... Also, there will be certainly things which need improving (more tests, some weird variable naming, etc...). Please let me know what I can do to improve it.

Sure, I'll open an Issue.

True, you can always find a nucleus with for example Particle.findall('C12'), but this requires you to know the Symbol (C, in this case) instead of the atomic number (6, in this case, so Particle.findall('12', charge=6) is the best thing.
I just thought it's the more user-friendly to have a special function for nuclei, especially because you will stumble across that, if you search the package for 'nucleus', which I did. And since PDGIDs for nuclei are easily defined, why not implement it? Maybe that's also a thing for something like PDGID.from_nucleus_information.

@eduardo-rodrigues
Copy link
Member

Hello @The-Ludwig, I'm being a bit slow. No sure whether I mentioned that I was a bit loaded recently. In any case I will review this PR this week. Indeed really nice to see this extension in, which will I hope be of interest to astroparticle colleagues ... BTW, are you in astroparticles/cosmics, hence the need for Corsika? I know, I'm being curious ;-).

I didn't find a user friendly method to convert a Corsika 7 ID to standard PDGID, so I tried to implement it here.

Definitely the way to go when working in community software 👍 !

README.rst Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
@The-Ludwig
Copy link
Contributor Author

Hi @eduardo-rodrigues,
I clearified the error message in Corsika7ID.to_pdgid. Any thoughts on the conditional imports? Are they ok? CI gave a warning

@eduardo-rodrigues
Copy link
Member

Hi @eduardo-rodrigues, I clearified the error message in Corsika7ID.to_pdgid. Any thoughts on the conditional imports? Are they ok? CI gave a warning

Thanks a lot. Am looking in batches in between meetings ...
I also saw the CI checks give failures. Will look soon. Of course we need to have it all green on way or another :).

@eduardo-rodrigues
Copy link
Member

Otherwise I had to delete the test for the pdgid_to_corsika7id.csv script, since it is now in admin/ and I can't import it.

This is probably acceptable as one can still compare by hand the newly produced file, and Git kind of does it for you, actually. This being said, I did not try but one could still keep the test navigating the directories up one (relative) level. Maybe it is a bit shaky, though. Let's leave it as-is now.

@eduardo-rodrigues
Copy link
Member

eduardo-rodrigues commented Oct 25, 2022

Hmm, those imports are a bit annoying if they provoke circular dependencies. Are you sure of those being circular? Did not check carefully enough but did not see the "circle".
In any case you can shut-up the linting related to warnings

************* Module particle.corsika.corsika7id
Warning: src/particle/corsika/corsika7id.py:174:8: C0415: Import outside toplevel (particle.particle.Particle) (import-outside-toplevel)
Warning: src/particle/corsika/corsika7id.py:206:8: C0415: Import outside toplevel (particle.particle.InvalidParticle) (import-outside-toplevel)

with a line comment - something like # pylint: disable=C0415?

If you try and fix locally and then commit? The other CI / Check failures are weird.

Copy link
Member

@eduardo-rodrigues eduardo-rodrigues 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 again for this great and welcome addition 👍!

I'm hereby approving modulo the somewhat minor CI failures, to reflect the fact that I consider the review of the addition done.

@The-Ludwig
Copy link
Contributor Author

Did not check carefully enough but did not see the "circle".

I checked again and if I do a top-level import I get ImportError: cannot import name 'Corsika7ID' from partially initialized module 'particle.corsika' (most likely due to a circular import) (/home/ludwig/Documents/particle/src/particle/corsika/__init__.py).

I'll suppress the warning.

@eduardo-rodrigues
Copy link
Member

Have you tried with a relative import? I think you are doing absolute imports there.

@The-Ludwig
Copy link
Contributor Author

Have you tried with a relative import? I think you are doing absolute imports there.

I used from ..particle.particle import InvalidParticle at the top of corsika7id.py.

@eduardo-rodrigues
Copy link
Member

Oh, see it. OK.

@eduardo-rodrigues
Copy link
Member

These failures are annoying and in fact "universal" at the moment, as I see them also in #430 where a non-code file is added. I will not merge immediately because we need to run the tests for this big addition.

@henryiii, you still have time to comment, if you want.

@eduardo-rodrigues eduardo-rodrigues added the ⚙️ enhancement New feature or request label Oct 25, 2022
@eduardo-rodrigues eduardo-rodrigues merged commit 4134600 into scikit-hep:master Oct 27, 2022
@eduardo-rodrigues
Copy link
Member

Hello @The-Ludwig, as you can see from https://app.codecov.io/gh/scikit-hep/particle/tree/master/src/particle/corsika, the present test coverage for the module you added is not fantastic. In the new year I will try and continue some recent commits to improve coverage, and wanted to ask you whether you would be willing to take care of improving coverage for the corsika module? Let me know whether January is viable to you. Advance thanks and season greetings!

@eduardo-rodrigues
Copy link
Member

Happy New Year @The-Ludwig! Let me know what you think of the above ... Many thanks.

@The-Ludwig
Copy link
Contributor Author

Happy new year @eduardo-rodrigues ! :) I've not been online much in the past weeks, sorry!
I'd like to improve the coverage for the corsika module. I will start working on that today and create a PR.
Anything special I should keep in mind
?

@eduardo-rodrigues
Copy link
Member

That's great news 👍 !

Nothing special. Have a look at the present coverage at https://app.codecov.io/gh/scikit-hep/particle/blob/master/src/particle/corsika/corsika7id.py or locally and check also similar test files, as it can help.

Advance thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data files ⚙️ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants