Skip to content
Open
Changes from all 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
104 changes: 103 additions & 1 deletion tools/ALARAJOYWrapper/xs_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,99 @@ def plot_single_nuc_rxn_xs(
ax.set_ylabel('Cross-Section [b]')
ax.set_title(title)
ax.grid()
ax.legend()

return ax

def convert_to_eV(energy_vline_arg, parser=None):
"""
Convert an energy value to units of electron-volts, if it is specified to
be in some SI multiple of eV (i.e. MeV).

Arguments:
energy_vline_arg (list of str): List specifying the neutron energy to
denote with a vertical line. If only a single value is provided,
then eV units will be assumed. Otherwise, any SI unit prefix can
be supplied as the second value in the list, to be converted
internally to eV (i.e. ['14.1', 'MeV'] will be converted to
1.41e+07 eV).
parser (argparser.ArgumentParser, optional): Option to include the
argparser ArgumentParser object through which to channel
improperly supplied `energy_vline_arg` values. Needed if being
called within `main()`.
(Defaults to None)

Returns:
converted_energy (float): Energy value in electron-volts
"""

conversion_dict = {
'a' : 1e-18,
'f' : 1e-15,
'p' : 1e-12,
'n' : 1e-9,
'u' : 1e-6, # Accepts u or "μ" for micro-
'μ' : 1e-6, # Accepts u or "μ" for micro-
'm' : 1e-3,
'c' : 1e-2,
'k' : 1e3,
'M' : 1e6,
'G' : 1e9,
'T' : 1e12,
'P' : 1e15,
'E' : 1e18
}

vline_energy = float(energy_vline_arg[0])
if len(energy_vline_arg) == 2:
energy_units = energy_vline_arg[1]
elif len(energy_vline_arg) > 2:
error_message = (
'Too many values for energy_vline. ' \
'Can provide upt to two values: energy, energy_units'
)
if parser:
parser.error(error_message)
else:
raise TypeError(error_message)

if energy_units and energy_units.lower() != 'eV':
vline_energy *= conversion_dict[energy_units[0]]

return vline_energy

def plot_neutron_energy_axvline(ax, energy_vline_arg, parser=None):
"""
Given a pre-exisisting Matplotlib Axes object, include a vertical line at
a specified energy to highlight the cross-section data in that region.

Arguments:
ax (matplotlib.axes._axes.Axes): Matplotlib Axes object of the plot
being constructed.
energy_vline_arg (list of str): List specifying the neutron energy to
denote with a vertical line. If only a single value is provided,
then eV units will be assumed. Otherwise, any SI unit prefix can
be supplied as the second value in the list, to be converted
internally to eV (i.e. ['14.1', 'MeV'] will be converted to
1.41e+07 eV).
parser (argparser.ArgumentParser, optional): Option to include the
argparser ArgumentParser object through which to channel
improperly supplied `energy_vline_arg` values. Needed if being
called within `main()`.
(Defaults to None)

Returns:
ax (matplotlib.axes._axes.Axes): Updated Matplotlib Axes object of the
plot being constructed.
"""

vline_energy = convert_to_eV(energy_vline_arg, parser)
ax.axvline(
vline_energy,
color='r',
alpha=0.4,
label=f'{vline_energy:.2e} eV',
linestyle='--'
)

return ax

Expand Down Expand Up @@ -360,6 +452,9 @@ def main():

parser = argparse.ArgumentParser()
parser.add_argument('--yaml', '-y')
parser.add_argument(
'--energy_vline', '-e', nargs='*'
)
args = parser.parse_args()

with open(args.yaml, 'r') as f:
Expand Down Expand Up @@ -423,9 +518,16 @@ def main():
ax, element, A, emitted,
continuous_dict, groupwise_dict
)
if args.energy_vline:
plot_neutron_energy_axvline(
ax, args.energy_vline, parser=parser
)

plot_path = set_plot_save_path(
element, A, emitted, tendl_dir, groupwise_dict.keys()
)

ax.legend()
plt.savefig(plot_path)

print(
Expand Down
Loading