-
-
Notifications
You must be signed in to change notification settings - Fork 430
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 spectrum from packet dataframe #2601
Changes from all commits
56d8f44
ddb44a2
28f4554
64ab1f0
6fb737c
cc9fe35
88f7ea4
b523946
14ab57e
0a3a178
2089567
4b9dba4
c56cddc
f24a2c9
12a72f4
2215b88
ef3cd6a
4c027f5
960f2b8
6161f6a
7b123f8
5fb9903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import radioactivedecay as rd | ||
|
||
from tardis.energy_input.util import KEV2ERG | ||
from tardis.model.matter.decay import IsotopicMassFraction | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
|
@@ -75,18 +76,18 @@ def calculate_total_decays(inventories, time_delta): | |
dictionary of inventories for each shell | ||
|
||
time_end : float | ||
End time of simulation in days. | ||
End time of simulation step in days. | ||
|
||
|
||
Returns | ||
------- | ||
cumulative_decay_df : pd.DataFrame | ||
total decays for x g of isotope for time 't' | ||
""" | ||
time_delta = u.Quantity(time_delta, u.s) | ||
time_delta = u.Quantity(time_delta, u.d) | ||
total_decays = {} | ||
for shell, inventory in inventories.items(): | ||
total_decays[shell] = inventory.cumulative_decays(time_delta.value) | ||
total_decays[shell] = inventory.cumulative_decays(time_delta.value, "d") | ||
|
||
flattened_dict = {} | ||
|
||
|
@@ -109,7 +110,8 @@ def calculate_total_decays(inventories, time_delta): | |
|
||
def create_isotope_decay_df(cumulative_decay_df, gamma_ray_lines): | ||
""" | ||
Function to create a dataframe of isotopes for each shell with their decay mode, number of decays, radiation type, | ||
Function to create a dataframe of isotopes for each shell with their decay mode, | ||
number of decays, radiation type, | ||
radiation energy and radiation intensity. | ||
|
||
Parameters | ||
|
@@ -167,3 +169,91 @@ def create_isotope_decay_df(cumulative_decay_df, gamma_ray_lines): | |
) | ||
|
||
return isotope_decay_df | ||
|
||
|
||
def time_evolve_mass_fraction(raw_isotope_mass_fraction, time_array): | ||
""" | ||
Function to evolve the mass fraction of isotopes with time. | ||
|
||
Parameters | ||
---------- | ||
raw_isotope_mass_fraction : pd.DataFrame | ||
isotope mass fraction in mass fractions. | ||
time_array : np.array | ||
array of time in days. | ||
|
||
Returns | ||
------- | ||
time_evolved_isotope_mass_fraction : pd.DataFrame | ||
time evolved mass fraction of isotopes. | ||
""" | ||
|
||
initial_isotope_mass_fraction = raw_isotope_mass_fraction | ||
isotope_mass_fraction_list = [] | ||
|
||
for time in time_array: | ||
|
||
decayed_isotope_mass_fraction = IsotopicMassFraction( | ||
initial_isotope_mass_fraction | ||
).decay(time) | ||
isotope_mass_fraction_list.append(decayed_isotope_mass_fraction) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appending to arrays is bad for computer memory because you have to reallocate memory to change the size of the array. It's much better to initialize isotope_mass_fraction_list as an empty list with the appropriate size, something line len(time_array) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please address this comment @Knights-Templars |
||
initial_isotope_mass_fraction = decayed_isotope_mass_fraction | ||
|
||
time_evolved_isotope_mass_fraction = pd.concat( | ||
isotope_mass_fraction_list, keys=time_array, names=["time"] | ||
) | ||
|
||
return time_evolved_isotope_mass_fraction | ||
|
||
|
||
def time_evolve_cumulative_decay( | ||
raw_isotope_mass_fraction, shell_masses, gamma_ray_lines, time_array | ||
): | ||
""" | ||
Function to calculate the total decays for each isotope for each shell at each time step. | ||
|
||
Parameters | ||
---------- | ||
raw_isotope_mass_fraction : pd.DataFrame | ||
isotope abundance in mass fractions. | ||
shell_masses : numpy.ndarray | ||
shell masses in units of g | ||
gamma_ray_lines : pd.DataFrame | ||
gamma ray lines from nndc stored as a pandas dataframe. | ||
time_array : numpy.ndarray | ||
array of time steps in days. | ||
|
||
Returns | ||
------- | ||
time_evolve_decay_df : pd.DataFrame | ||
dataframe of isotopes for each shell with their decay mode, number of decays, radiation type, | ||
radiation energy and radiation intensity at each time step. | ||
|
||
""" | ||
|
||
isotope_decay_df_list = [] | ||
initial_isotope_mass_fraction = raw_isotope_mass_fraction | ||
|
||
dt = np.diff(time_array) | ||
|
||
for time in dt: | ||
|
||
isotope_dict = create_isotope_dicts( | ||
initial_isotope_mass_fraction, shell_masses | ||
) | ||
inventories = create_inventories_dict(isotope_dict) | ||
total_decays = calculate_total_decays(inventories, time) | ||
isotope_df_time = create_isotope_decay_df(total_decays, gamma_ray_lines) | ||
isotope_decay_df_list.append(isotope_df_time) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See Josh's previous comment on appending |
||
|
||
decayed_isotope_mass_fraction = IsotopicMassFraction( | ||
initial_isotope_mass_fraction | ||
).decay(time) | ||
|
||
initial_isotope_mass_fraction = decayed_isotope_mass_fraction | ||
|
||
time_evolved_decay_df = pd.concat( | ||
isotope_decay_df_list, keys=time_array, names=["time"] | ||
) | ||
|
||
return time_evolved_decay_df |
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.
Is this still needed? Could it be a logging command?