Skip to content

Commit 614abfe

Browse files
shimwellpaulromano
andauthored
Option units for geometry plot (openmc-dev#2575)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent dbc2191 commit 614abfe

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

‎openmc/universe.py‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def find(self, point):
303303

304304
def plot(self, origin=None, width=None, pixels=40000,
305305
basis='xy', color_by='cell', colors=None, seed=None,
306-
openmc_exec='openmc', axes=None, legend=False,
306+
openmc_exec='openmc', axes=None, legend=False, axis_units='cm',
307307
legend_kwargs=_default_legend_kwargs, outline=False,
308308
**kwargs):
309309
"""Display a slice plot of the universe.
@@ -360,6 +360,10 @@ def plot(self, origin=None, width=None, pixels=40000,
360360
outline : bool
361361
Whether outlines between color boundaries should be drawn
362362
363+
.. versionadded:: 0.13.4
364+
axis_units : {'km', 'm', 'cm', 'mm'}
365+
Units used on the plot axis
366+
363367
.. versionadded:: 0.13.4
364368
**kwargs
365369
Keyword arguments passed to :func:`matplotlib.pyplot.imshow`
@@ -377,13 +381,13 @@ def plot(self, origin=None, width=None, pixels=40000,
377381
# Determine extents of plot
378382
if basis == 'xy':
379383
x, y = 0, 1
380-
xlabel, ylabel = 'x [cm]', 'y [cm]'
384+
xlabel, ylabel = f'x [{axis_units}]', f'y [{axis_units}]'
381385
elif basis == 'yz':
382386
x, y = 1, 2
383-
xlabel, ylabel = 'y [cm]', 'z [cm]'
387+
xlabel, ylabel = f'y [{axis_units}]', f'z [{axis_units}]'
384388
elif basis == 'xz':
385389
x, y = 0, 2
386-
xlabel, ylabel = 'x [cm]', 'z [cm]'
390+
xlabel, ylabel = f'x [{axis_units}]', f'z [{axis_units}]'
387391

388392
bb = self.bounding_box
389393
# checks to see if bounding box contains -inf or inf values
@@ -408,10 +412,12 @@ def plot(self, origin=None, width=None, pixels=40000,
408412
pixels_y = math.sqrt(pixels / aspect_ratio)
409413
pixels = (int(pixels / pixels_y), int(pixels_y))
410414

411-
x_min = origin[x] - 0.5*width[0]
412-
x_max = origin[x] + 0.5*width[0]
413-
y_min = origin[y] - 0.5*width[1]
414-
y_max = origin[y] + 0.5*width[1]
415+
axis_scaling_factor = {'km': 0.00001, 'm': 0.01, 'cm': 1, 'mm': 10}
416+
417+
x_min = (origin[x] - 0.5*width[0]) * axis_scaling_factor[axis_units]
418+
x_max = (origin[x] + 0.5*width[0]) * axis_scaling_factor[axis_units]
419+
y_min = (origin[y] - 0.5*width[1]) * axis_scaling_factor[axis_units]
420+
y_max = (origin[y] + 0.5*width[1]) * axis_scaling_factor[axis_units]
415421

416422
with TemporaryDirectory() as tmpdir:
417423
model = openmc.Model()

0 commit comments

Comments
 (0)