Skip to content

Commit 258a503

Browse files
committed
Combine separate functions for distribcell / cell instance plotting
1 parent 54c4b73 commit 258a503

1 file changed

Lines changed: 22 additions & 37 deletions

File tree

openmc_plotter/plotmodel.py

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,11 @@ def create_tally_image(self, view=None):
365365
view)
366366
return image + (units_out,)
367367
elif contains_distribcell or contains_cellinstance:
368-
# Select appropriate function
369-
if contains_distribcell:
370-
create_image = self._create_distribcell_image
371-
else:
372-
create_image = self._create_cellinstance_image
373-
374368
if tally_value == 'rel_err':
375-
mean_data = create_image(tally, 'mean', scores, nuclides)
376-
std_dev_data = create_image(tally, 'std_dev', scores, nuclides)
369+
mean_data = self._create_distribcell_image(
370+
tally, 'mean', scores, nuclides, contains_cellinstance)
371+
std_dev_data = self._create_distribcell_image(
372+
tally, 'std_dev', scores, nuclides)
377373
image_data = 100 * np.divide(
378374
std_dev_data[0], mean_data[0],
379375
out=np.zeros_like(mean_data[0]),
@@ -383,7 +379,8 @@ def create_tally_image(self, view=None):
383379
data_max = np.max(image_data)
384380
return image_data, None, data_min, data_max, '% error'
385381
else:
386-
image = create_image(tally, tally_value, scores, nuclides)
382+
image = self._create_distribcell_image(
383+
tally, tally_value, scores, nuclides, contains_cellinstance)
387384
return image + (units_out,)
388385
else:
389386
# same as above, get the std. dev. data
@@ -503,39 +500,27 @@ def _do_op(array, tally_value, ax=0):
503500

504501
return image_data, None, data_min, data_max
505502

506-
def _create_distribcell_image(self, tally, tally_value, scores, nuclides):
507-
dfilter = tally.find_filter(openmc.DistribcellFilter)
508-
509-
data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value)
510-
data = data.flatten()
511-
512-
cell_id = dfilter.bins[0]
513-
# create a mask for ids that match the cell
514-
image_data = np.full_like(self.ids, np.nan, dtype=float)
515-
516-
cell_id_mask = self.cell_ids == cell_id
517-
for i, v in enumerate(data):
518-
instance_mask = self.instances == i
519-
image_data[cell_id_mask & instance_mask] = v
520-
521-
data_min = np.min(data)
522-
data_max = np.max(data)
523-
image_data = np.ma.masked_where(image_data < 0.0, image_data)
524-
525-
return image_data, None, data_min, data_max
526-
527-
def _create_cellinstance_image(self, tally, tally_value, scores, nuclides):
528-
cellinst_filter = tally.find_filter(openmc.CellInstanceFilter)
529-
503+
def _create_distribcell_image(self, tally, tally_value, scores, nuclides, cellinstance=False):
504+
# Get flattened array of tally results
530505
data = tally.get_values(scores=scores, nuclides=nuclides, value=tally_value)
531506
data = data.flatten()
532507

533-
# create a mask for ids that match the cell
508+
# Create an empty array of appropriate shape for image
534509
image_data = np.full_like(self.ids, np.nan, dtype=float)
535510

536-
for v, (cell_id, instance) in zip(data, cellinst_filter.bins):
537-
cell_id_mask = self.cell_ids == cell_id
538-
instance_mask = self.instances == instance
511+
# Determine appropriate set of bins depending on filter type
512+
if cellinstance:
513+
f = tally.find_filter(openmc.CellInstanceFilter)
514+
bins = f.bins
515+
else:
516+
f = tally.find_filter(openmc.DistribcellFilter)
517+
bins = [(f.bins[0], i) for i in range(data.size)]
518+
519+
# Iterate over tally bins, setting any pixels that have matching (cell
520+
# ID, instance) each time
521+
for v, (cell_id, instance) in zip(data, bins):
522+
cell_id_mask = (self.cell_ids == cell_id)
523+
instance_mask = (self.instances == instance)
539524
image_data[cell_id_mask & instance_mask] = v
540525

541526
data_min = np.min(data)

0 commit comments

Comments
 (0)