Skip to content

Commit 52f82d2

Browse files
authored
Fix handling of relative error for mesh tallies (#144)
1 parent f699110 commit 52f82d2

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

openmc_plotter/plotmodel.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -453,26 +453,20 @@ def create_tally_image(self, view: Optional[PlotView] = None):
453453
units_out = _SCORE_UNITS_VOL.get(scores[0], _REACTION_UNITS_VOL)
454454

455455
if tally_value == 'rel_err':
456-
# get both the std. dev. data and mean data
457-
# to create the relative error data
458-
mean_data = self._create_tally_mesh_image(tally,
459-
'mean',
460-
scores,
461-
nuclides,
462-
view)
463-
std_dev_data = self._create_tally_mesh_image(tally,
464-
'std_dev',
465-
scores,
466-
nuclides,
467-
view)
468-
image_data = 100 * np.divide(std_dev_data[0],
469-
mean_data[0],
470-
out=np.zeros_like(mean_data[0]),
471-
where=mean_data != 0)
472-
extents = mean_data[1]
473-
data_min = np.min(image_data)
474-
data_max = np.max(image_data)
475-
return image_data, extents, data_min, data_max, '% error'
456+
# Get both the std. dev. data and mean data to create the
457+
# relative error data
458+
mean_data = self._create_tally_mesh_image(
459+
tally, 'mean', scores, nuclides, view)[0]
460+
std_dev_data = self._create_tally_mesh_image(
461+
tally, 'std_dev', scores, nuclides, view)[0]
462+
with np.errstate(divide='ignore', invalid='ignore'):
463+
image_data = 100.0 * std_dev_data / mean_data
464+
if np.isnan(image_data).all():
465+
data_min, data_max = 0., 1.
466+
else:
467+
data_min = np.nanmin(image_data)
468+
data_max = np.nanmax(image_data)
469+
return image_data, None, data_min, data_max, '% error'
476470

477471
else:
478472
image = self._create_tally_mesh_image(tally,

0 commit comments

Comments
 (0)