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

Create samples with packet energies #2572

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions tardis/energy_input/gamma_ray_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,80 @@
)

return isotope_decay_df


def distribute_packets(isotope_decay_df):
"""
Function to distribute packets based on the energy of the decay.

Parameters
----------
isotope_decay_df : pd.DataFrame
dataframe of isotopes for each shell with their decay mode, number of decays, radiation type,
radiation energy and radiation intensity.

Returns
-------
isotope_decay_df : pd.DataFrame
dataframe of isotopes for each shell with their decay mode, number of decays, radiation type,
radiation energy and radiation intensity, normalized energy and packets.
"""

isotope_decay_df["normalized_energy"] = (

Check warning on line 189 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L189

Added line #L189 was not covered by tests
isotope_decay_df["decay_energy_erg"]
/ isotope_decay_df["decay_energy_erg"].sum()
)

return isotope_decay_df

Check warning on line 194 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L194

Added line #L194 was not covered by tests


def sample_single_packet(isotope_decay_df):
"""
Function to sample packet energy from the energy distribution of the decay.

Parameters
----------
isotope_decay_df : pd.DataFrame
dataframe of isotopes for each shell with their decay mode, number of decays, radiation type,
radiation energy and radiation intensity, normalized energy and packets.

Returns
-------
sampled_packet : pd.Series
A Series of sampled packets using the normalized energy in each channel.

"""

sampled_packet = isotope_decay_df.sample(

Check warning on line 214 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L214

Added line #L214 was not covered by tests
weights="normalized_energy", random_state=np.random.RandomState(seed=29)
) # random state for reproducibility

return sampled_packet

Check warning on line 218 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L218

Added line #L218 was not covered by tests


def sample_packets(isotope_decay_df, number_of_packets):
"""
Function to sample packets based on the energy of the decay.

Parameters
----------
isotope_decay_df : pd.DataFrame
dataframe of isotopes for each shell with their decay mode, number of decays, radiation type,
radiation energy and radiation intensity, normalized energy and packets.
number_of_packets : int
number of packets to distribute.

Returns
-------
sampled_packets : numpy.ndarray
Creates an array of packets.
"""

sampled_packets = np.array(

Check warning on line 239 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L239

Added line #L239 was not covered by tests
[
sample_single_packet(isotope_decay_df)
for i in range(number_of_packets)
]
)

return sampled_packets

Check warning on line 246 in tardis/energy_input/gamma_ray_channel.py

View check run for this annotation

Codecov / codecov/patch

tardis/energy_input/gamma_ray_channel.py#L246

Added line #L246 was not covered by tests
Loading