@@ -37,7 +37,7 @@ def sample_initial_particles(self, n_samples: int = 1000, prn_seed: int = None):
3737 materials = openmc .Materials ()
3838 model .materials = materials
3939
40- sph = openmc .Sphere (r = 9999999999 , boundary_type = "vacuum" )
40+ sph = openmc .Sphere (r = 99999999999 , boundary_type = "vacuum" )
4141 cell = openmc .Cell (region = - sph )
4242 geometry = openmc .Geometry ([cell ])
4343 model .geometry = geometry
@@ -72,6 +72,9 @@ def plot_source_energy(
7272 prn_seed : int = 1 ,
7373 energy_bins : typing .Union [str , np .array ] = "auto" ,
7474 name : typing .Optional [str ] = None ,
75+ yaxis_type : str = "linear" ,
76+ xaxis_type : str = "linear" ,
77+ xaxis_units : str = "MeV" ,
7578):
7679 """makes a plot of the initial creation positions of an OpenMC source
7780
@@ -88,14 +91,22 @@ def plot_source_energy(
8891 Numpy bins can also be manually set by passing in a numpy array
8992 of bin edges.
9093 name: the legend name to use
94+ yaxis_type: The type (scale) to use for the Y axis. Options are 'log'
95+ or 'linear.
96+ xaxis_type: The type (scale) to use for the Y axis. Options are 'log'
97+ or 'linear.
98+ xaxis_units: The units to use for the x axis. Options are 'eV' or 'MeV'.
9199 """
92100
101+ if xaxis_units not in ["eV" , "MeV" ]:
102+ raise ValueError (f"xaxis_units must be either 'eV' or 'MeV' not { xaxis_units } " )
103+
93104 if figure is None :
94105 figure = plotly .graph_objects .Figure ()
95106 figure .update_layout (
96107 title = "Particle energy" ,
97- xaxis = {"title" : "Energy (eV)" },
98- yaxis = {"title" : "Probability" },
108+ xaxis = {"title" : f "Energy [ { xaxis_units } ]" , "type" : xaxis_type },
109+ yaxis = {"title" : "Probability" , "type" : yaxis_type },
99110 showlegend = True ,
100111 )
101112
@@ -109,11 +120,13 @@ def plot_source_energy(
109120 # scaling by strength
110121 if isinstance (self , openmc .SourceBase ):
111122 probability = probability * self .strength
112-
123+ energy = bin_edges [:- 1 ]
124+ if xaxis_units == "MeV" :
125+ energy = energy / 1e6
113126 # Plot source energy histogram
114127 figure .add_trace (
115128 plotly .graph_objects .Scatter (
116- x = bin_edges [: - 1 ] ,
129+ x = energy ,
117130 y = probability * np .diff (bin_edges ),
118131 line = {"shape" : "hv" },
119132 hoverinfo = "text" ,
0 commit comments