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

Gamma-ray packet source refactor #2546

Merged
merged 25 commits into from
Apr 24, 2024

Conversation

andrewfullard
Copy link
Contributor

📝 Description

Type: 🎢 infrastructure

Refactors the gamma-ray packet creation to use a standard packet source-style setup.

🚦 Testing

How did you test these changes?

  • Testing pipeline
  • Other method (describe)
  • My changes can't be tested (explain why)

☑️ Checklist

  • I requested two reviewers for this pull request
  • I updated the documentation according to my changes
  • I built the documentation by applying the build_docs label

Note: If you are not allowed to perform any of these actions, ping (@) a contributor.

@andrewfullard andrewfullard self-assigned this Mar 12, 2024
@andrewfullard andrewfullard changed the title First steps Gamma-ray packet source refactor Mar 12, 2024
Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 21.89542% with 239 lines in your changes are missing coverage. Please review.

Project coverage is 66.77%. Comparing base (bf50d1e) to head (b1b3a9d).
Report is 4 commits behind head on master.

❗ Current head b1b3a9d differs from pull request most recent head d4ff4b8. Consider uploading reports for the commit d4ff4b8 to get more accurate results

Files Patch % Lines
tardis/energy_input/gamma_ray_packet_source.py 13.74% 182 Missing ⚠️
...energy_input/tests/test_gamma_ray_packet_source.py 36.36% 28 Missing ⚠️
tardis/energy_input/main_gamma_ray_loop.py 0.00% 15 Missing ⚠️
tardis/energy_input/GXPacket.py 15.38% 11 Missing ⚠️
tardis/energy_input/gamma_ray_transport.py 0.00% 1 Missing ⚠️
tardis/energy_input/samplers.py 0.00% 1 Missing ⚠️
tardis/montecarlo/montecarlo_numba/opacities.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2546      +/-   ##
==========================================
- Coverage   68.05%   66.77%   -1.29%     
==========================================
  Files         171      172       +1     
  Lines       14300    14453     +153     
==========================================
- Hits         9732     9651      -81     
- Misses       4568     4802     +234     

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

@andrewfullard andrewfullard marked this pull request as ready for review March 27, 2024 19:29
self.nu_cmf = nu_cmf
self.status = status
self.shell = shell
self.time_current = time_current
Copy link
Member

Choose a reason for hiding this comment

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

What is time_current?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current local time value of the packet, if there was a clock attached to it

self.shell = shell
self.time_current = time_current
self.number_of_packets = len(self.energy_rf)
self.tau = -np.log(np.random.random(self.number_of_packets))
Copy link
Member

Choose a reason for hiding this comment

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

Is this tau same as the mean life of isotopes? Shall we give a separate name for this variable if this the optical depth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that we are in a radiative transfer code, I think we should rename the mean lifetime instead

@@ -289,9 +288,6 @@ def gamma_packet_loop(
energy_out[bin_index, time_index] += rest_energy / (
Copy link
Member

Choose a reason for hiding this comment

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

Instead of the energy_out, shall we dump the information into an array which which record the "escaping" packets information. That will help in getting the gamma-ray spectra in a post-processing step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

energy_out is such an array, but we can record more packet information if you want. I consider this out of scope for this PR though.

@@ -322,7 +318,6 @@ def gamma_packet_loop(
energy_plot_df_rows,
energy_out,
deposition_estimator,
packets_out,
bin_width,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the bin_width as an output? WE can do that later in a post-processing step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not, but the blame said you added it. I can remove it, but it may be out of scope for this PR.

nus_rf = np.zeros(number_of_packets)
nus_cmf = np.zeros(number_of_packets)
times = np.zeros(number_of_packets)
statuses = np.ones(number_of_packets, dtype=np.int64) * 3
Copy link
Member

Choose a reason for hiding this comment

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

Why it is multiplied by 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the default status of the packet. I will add a comment to clarify.

)

# get the time step index of the packets
initial_time_indexes = sampled_packets_df["time"]
Copy link
Member

Choose a reason for hiding this comment

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

time is an index of the data frame

Copy link
Member

Choose a reason for hiding this comment

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

They are actual times and not indices.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I think they would be more useful as indices instead of actual times. Times are useful for plotting but not much else in my opinion. I know I am probably referencing the index incorrectly regardless and will fix the code here.

@andrewfullard andrewfullard merged commit b8788a1 into tardis-sn:master Apr 24, 2024
8 of 9 checks passed
KasukabeDefenceForce pushed a commit to KasukabeDefenceForce/tardis that referenced this pull request Apr 25, 2024
* First steps

Radioactive packet source
GXPacket collection
Some initial methods

* Add more methods to the packet source

* Documentation, cleanup, positronium handling

* Black formatting, cleanup

* Fix kappa_calculation import loop

* Working packet source

Creates a Packet collection with all necessary packet properties

* Positron deposition and packet tracker arrays

* Fix parents dict

* Result now mostly consistent with master

* Fix kappa calculation test

* Adds missing docstring for calculate_energy_factors

* Fix util tests and black

* Testing skeleton for packet source

* black tests

* Address comments

* Beginnings of an alternate packet source for the dataframe

* Possible deposition fix, import fixes

* Added old functions

* Cleanup, comments, and more dataframe sampling setup

* Corrected packet time computation

* Modified sampling to use positron information

* Remove packet sampling call and replace with dataframe method

* Update method call to match current usage

* Comment responses

* More comments, improve packet dataframe index handling

---------

Co-authored-by: Knights-Templars <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants