Skip to content

Commit f58d349

Browse files
authored
Allow user to change default resolution from command line (#140)
* Allow user to change default resolution from command line * Apply default_res to restored view
1 parent 52f82d2 commit f58d349

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

openmc_plotter/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def main():
2121
help='Ignore plot_settings.pkl file if present.')
2222
ap.add_argument('-s', '--threads', type=int, default=None,
2323
help='If present, number of threads used to generate plots.')
24+
ap.add_argument('-r', '--resolution', type=int, default=None,
25+
help='Default number of pixels in each direction')
2426
ap.add_argument('model_path', nargs='?', default=os.curdir,
2527
help='Location of model XML file or a directory containing '
2628
'XML files (default is current dir)')
@@ -68,7 +70,8 @@ def run_app(user_args):
6870

6971
font_metric = QtGui.QFontMetrics(app.font())
7072
screen_size = app.primaryScreen().size()
71-
mainWindow = MainWindow(font_metric, screen_size, user_args.model_path, user_args.threads)
73+
mainWindow = MainWindow(font_metric, screen_size, user_args.model_path,
74+
user_args.threads, user_args.resolution)
7275
# connect splashscreen to main window, close when main window opens
7376
mainWindow.loadGui(use_settings_pkl=user_args.ignore_settings)
7477

openmc_plotter/main_window.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,17 @@ class MainWindow(QMainWindow):
4545
def __init__(self,
4646
font=QtGui.QFontMetrics(QtGui.QFont()),
4747
screen_size=QtCore.QSize(),
48-
model_path='.', threads=None):
48+
model_path='.',
49+
threads=None,
50+
resolution=None):
4951
super().__init__()
5052

5153
self.screen = screen_size
5254
self.font_metric = font
5355
self.setWindowTitle('OpenMC Plot Explorer')
5456
self.model_path = Path(model_path)
5557
self.threads = threads
58+
self.default_res = resolution
5659

5760
def loadGui(self, use_settings_pkl=True):
5861

@@ -471,7 +474,7 @@ def loadModel(self, reload=False, use_settings_pkl=True):
471474
if reload:
472475
self.resetModels()
473476
else:
474-
self.model = PlotModel(use_settings_pkl, self.model_path)
477+
self.model = PlotModel(use_settings_pkl, self.model_path, self.default_res)
475478

476479
# update plot and model settings
477480
self.updateRelativeBases()

openmc_plotter/plotmodel.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class PlotModel:
111111
If True, use plot_settings.pkl file to reload settings
112112
model_path : pathlib.Path
113113
Path to model XML file or directory
114+
default_res : int
115+
Default resolution as the number of pixels in each direction
114116
115117
Attributes
116118
----------
@@ -147,7 +149,7 @@ class PlotModel:
147149
have unapplied changes
148150
"""
149151

150-
def __init__(self, use_settings_pkl, model_path):
152+
def __init__(self, use_settings_pkl, model_path, default_res):
151153
""" Initialize PlotModel class attributes """
152154

153155
# Retrieve OpenMC Cells/Materials
@@ -174,7 +176,7 @@ def __init__(self, use_settings_pkl, model_path):
174176
self.previousViews = []
175177
self.subsequentViews = []
176178

177-
self.defaultView = self.getDefaultView()
179+
self.defaultView = self.getDefaultView(default_res)
178180

179181
if model_path.is_file():
180182
settings_pkl = model_path.with_name('plot_settings.pkl')
@@ -228,7 +230,8 @@ def __init__(self, use_settings_pkl, model_path):
228230
self.statepoint = None
229231

230232
self.currentView = PlotView(restore_view=view,
231-
restore_domains=restore_domains)
233+
restore_domains=restore_domains,
234+
default_res=default_res)
232235

233236
else:
234237
self.currentView = copy.deepcopy(self.defaultView)
@@ -256,14 +259,19 @@ def statepoint(self, statepoint):
256259
if self._statepoint and not self._statepoint.is_open:
257260
self._statepoint.open()
258261

259-
def getDefaultView(self):
262+
def getDefaultView(self, default_res):
260263
""" Generates default PlotView instance for OpenMC geometry
261264
262265
Centers plot view origin in every dimension if possible. Defaults
263266
to xy basis, with height and width to accomodate full size of
264267
geometry. Defaults to (0, 0, 0) origin with width and heigth of
265268
25 if geometry bounding box cannot be generated.
266269
270+
Parameters
271+
----------
272+
default_res : int
273+
Default resolution as the number of pixels in each direction
274+
267275
Returns
268276
-------
269277
default : PlotView instance
@@ -286,7 +294,8 @@ def getDefaultView(self):
286294
else:
287295
zcenter = 0.00
288296

289-
default = PlotView([xcenter, ycenter, zcenter], width, height)
297+
default = PlotView([xcenter, ycenter, zcenter], width, height,
298+
default_res=default_res)
290299
return default
291300

292301
def resetColors(self):
@@ -760,6 +769,8 @@ class ViewParam(openmc.lib.plot._PlotBase):
760769
Width of plot view in model units
761770
height : float
762771
Height of plot view in model units
772+
default_res : int
773+
Default resolution as the number of pixels in each direction
763774
764775
Attributes
765776
----------
@@ -781,7 +792,7 @@ class ViewParam(openmc.lib.plot._PlotBase):
781792
The universe level for the plot (default: -1 -> all universes shown)
782793
"""
783794

784-
def __init__(self, origin=(0, 0, 0), width=10, height=10):
795+
def __init__(self, origin=(0, 0, 0), width=10, height=10, default_res=1000):
785796
"""Initialize ViewParam attributes"""
786797
super().__init__()
787798

@@ -790,8 +801,8 @@ def __init__(self, origin=(0, 0, 0), width=10, height=10):
790801
self.origin = origin
791802
self.width = width
792803
self.height = height
793-
self.h_res = 1000
794-
self.v_res = 1000
804+
self.h_res = default_res
805+
self.v_res = default_res
795806
self.basis = 'xy'
796807
self.color_overlaps = False
797808

@@ -976,15 +987,22 @@ class PlotView:
976987
'h_res', 'v_res', 'basis', 'llc', 'urc', 'color_overlaps')
977988

978989
def __init__(self, origin=(0, 0, 0), width=10, height=10, restore_view=None,
979-
restore_domains=False):
990+
restore_domains=False, default_res=None):
980991
"""Initialize PlotView attributes"""
981992

982993
if restore_view is not None:
983994
self.view_ind = copy.copy(restore_view.view_ind)
984995
self.view_params = copy.copy(restore_view.view_params)
996+
if default_res is not None:
997+
p = self.view_params
998+
p.h_res = default_res
999+
p.v_res = int(default_res * p.height / p.width)
9851000
else:
9861001
self.view_ind = PlotViewIndependent()
987-
self.view_params = ViewParam(origin=origin, width=width, height=height)
1002+
if default_res is not None:
1003+
self.view_params = ViewParam(origin, width, height, default_res)
1004+
else:
1005+
self.view_params = ViewParam(origin, width, height)
9881006

9891007
# Get model domain info
9901008
if restore_domains and restore_view is not None:

0 commit comments

Comments
 (0)