Skip to content

Commit 4623a16

Browse files
committed
🎨 Refactor species density profile calculations for improved clarity and efficiency
1 parent 8686035 commit 4623a16

File tree

1 file changed

+19
-51
lines changed

1 file changed

+19
-51
lines changed

process/io/plot_proc.py

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3628,60 +3628,28 @@ def plot_n_profiles(prof, demo_ranges, mfile_data, scan):
36283628

36293629
# build species density profiles from electron profile and fractions
36303630
# fracs = [fuel, alpha, protons, impurities, ions_total]
3631-
n_fuel, n_alpha, n_proton, n_imp, n_ions = [ne * f for f in fracs[:5]]
3632-
3633-
# convert to 1e19 m^-3 units for plotting (vectorised / less repetitive)
3634-
(
3635-
ne_plot,
3636-
n_fuel_plot,
3637-
n_alpha_plot,
3638-
n_proton_plot,
3639-
n_imp_plot,
3640-
n_ions_plot,
3641-
) = [arr / 1e19 for arr in (ne, n_fuel, n_alpha, n_proton, n_imp, n_ions)]
3631+
n_fuel = ne * fracs[0]
3632+
n_alpha = ne * fracs[1]
3633+
n_proton = ne * fracs[2]
3634+
n_imp = ne * fracs[3]
3635+
n_ions = ne * fracs[4]
3636+
3637+
# convert to 1e19 m^-3 units for plotting (vectorised)
3638+
ne_plot = ne / 1e19
3639+
n_fuel_plot = n_fuel / 1e19
3640+
n_alpha_plot = n_alpha / 1e19
3641+
n_proton_plot = n_proton / 1e19
3642+
n_imp_plot = n_imp / 1e19
3643+
n_ions_plot = n_ions / 1e19
36423644

36433645
prof.plot(
3644-
rho,
3645-
n_fuel_plot,
3646-
label=r"$n_{\text{fuel}}$",
3647-
color="#2ca02c",
3648-
linewidth=1.5,
3649-
)
3650-
prof.plot(
3651-
rho,
3652-
ne_plot,
3653-
label=r"$n_{e}$",
3654-
color="blue",
3655-
linewidth=1.5,
3656-
)
3657-
prof.plot(
3658-
rho,
3659-
n_alpha_plot,
3660-
label=r"$n_{\alpha}$",
3661-
color="#d62728",
3662-
linewidth=1.5,
3663-
)
3664-
prof.plot(
3665-
rho,
3666-
n_proton_plot,
3667-
label=r"$n_{p}$",
3668-
color="#17becf",
3669-
linewidth=1.5,
3670-
)
3671-
prof.plot(
3672-
rho,
3673-
n_imp_plot,
3674-
label=r"$n_{Z}$",
3675-
color="#9467bd",
3676-
linewidth=1.5,
3677-
)
3678-
prof.plot(
3679-
rho,
3680-
n_ions_plot,
3681-
label=r"$n_{i,total}$",
3682-
color="#ff7f0e",
3683-
linewidth=1.5,
3646+
rho, n_fuel_plot, label=r"$n_{\text{fuel}}$", color="#2ca02c", linewidth=1.5
36843647
)
3648+
prof.plot(rho, ne_plot, label=r"$n_{e}$", color="blue", linewidth=1.5)
3649+
prof.plot(rho, n_alpha_plot, label=r"$n_{\alpha}$", color="#d62728", linewidth=1.5)
3650+
prof.plot(rho, n_proton_plot, label=r"$n_{p}$", color="#17becf", linewidth=1.5)
3651+
prof.plot(rho, n_imp_plot, label=r"$n_{Z}$", color="#9467bd", linewidth=1.5)
3652+
prof.plot(rho, n_ions_plot, label=r"$n_{i,total}$", color="#ff7f0e", linewidth=1.5)
36853653

36863654
# make legend use multiple columns (up to 4) and place it to the right to avoid overlapping the plots
36873655
handles, labels = prof.get_legend_handles_labels()

0 commit comments

Comments
 (0)