From 79a5302945e4a70c803d2e34c6948411b4f28199 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 22 Jun 2023 16:14:13 +0100 Subject: [PATCH 1/3] geometry plots in mm, cm, m, km --- openmc/universe.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/openmc/universe.py b/openmc/universe.py index 6acecf8006a..8b6e7bc50ab 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -303,7 +303,7 @@ def find(self, point): def plot(self, origin=None, width=None, pixels=40000, basis='xy', color_by='cell', colors=None, seed=None, - openmc_exec='openmc', axes=None, legend=False, + openmc_exec='openmc', axes=None, legend=False, axis_units='cm', legend_kwargs=_default_legend_kwargs, outline=False, **kwargs): """Display a slice plot of the universe. @@ -377,13 +377,13 @@ def plot(self, origin=None, width=None, pixels=40000, # Determine extents of plot if basis == 'xy': x, y = 0, 1 - xlabel, ylabel = 'x [cm]', 'y [cm]' + xlabel, ylabel = f'x [{axis_units}]', f'y [{axis_units}]' elif basis == 'yz': x, y = 1, 2 - xlabel, ylabel = 'y [cm]', 'z [cm]' + xlabel, ylabel = f'y [{axis_units}]', f'z [{axis_units}]' elif basis == 'xz': x, y = 0, 2 - xlabel, ylabel = 'x [cm]', 'z [cm]' + xlabel, ylabel = f'x [{axis_units}]', f'z [{axis_units}]' bb = self.bounding_box # checks to see if bounding box contains -inf or inf values @@ -408,10 +408,12 @@ def plot(self, origin=None, width=None, pixels=40000, pixels_y = math.sqrt(pixels / aspect_ratio) pixels = (int(pixels / pixels_y), int(pixels_y)) - x_min = origin[x] - 0.5*width[0] - x_max = origin[x] + 0.5*width[0] - y_min = origin[y] - 0.5*width[1] - y_max = origin[y] + 0.5*width[1] + axis_scaling_factor = {'km': 0.00001, 'm': 0.01, 'cm': 1, 'mm': 10} + + x_min = (origin[x] - 0.5*width[0]) * axis_scaling_factor[axis_units] + x_max = (origin[x] + 0.5*width[0]) * axis_scaling_factor[axis_units] + y_min = (origin[y] - 0.5*width[1]) * axis_scaling_factor[axis_units] + y_max = (origin[y] + 0.5*width[1]) * axis_scaling_factor[axis_units] with TemporaryDirectory() as tmpdir: model = openmc.Model() From 7f1678d24222259868a16a2529bbb6065cc33ceb Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 22 Jun 2023 16:30:16 +0100 Subject: [PATCH 2/3] added doc string for axis_units --- openmc/universe.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openmc/universe.py b/openmc/universe.py index 8b6e7bc50ab..849d1118755 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -360,6 +360,10 @@ def plot(self, origin=None, width=None, pixels=40000, outline : bool Whether outlines between color boundaries should be drawn + .. versionadded:: 0.13.4 + axis_units : {'km', 'm', 'cm', 'mm'} + Units used on the plot axis, the default is cm + .. versionadded:: 0.13.4 **kwargs Keyword arguments passed to :func:`matplotlib.pyplot.imshow` From cc0f4d2d7d33261a1e2f48cf9a0512bcf0abe45f Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 23 Jun 2023 00:25:09 +0100 Subject: [PATCH 3/3] Apply improvment from code review by @paulromano Co-authored-by: Paul Romano --- openmc/universe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/universe.py b/openmc/universe.py index 849d1118755..447746e576a 100644 --- a/openmc/universe.py +++ b/openmc/universe.py @@ -362,7 +362,7 @@ def plot(self, origin=None, width=None, pixels=40000, .. versionadded:: 0.13.4 axis_units : {'km', 'm', 'cm', 'mm'} - Units used on the plot axis, the default is cm + Units used on the plot axis .. versionadded:: 0.13.4 **kwargs