11from ast import literal_eval
22from collections import defaultdict
33import copy
4+ import hashlib
45import itertools
5- import threading
66import os
7+ from pathlib import Path
78import pickle
8- import hashlib
9+ import threading
910
1011from PySide2 .QtWidgets import QItemDelegate , QColorDialog , QLineEdit , QMessageBox
1112from PySide2 .QtCore import QAbstractTableModel , QModelIndex , Qt , QSize , QEvent
1819from .statepointmodel import StatePointModel
1920from .plot_colors import random_rgb , reset_seed
2021
21- ID , NAME , COLOR , COLORLABEL , MASK , HIGHLIGHT = tuple ( range (0 , 6 ) )
22+ ID , NAME , COLOR , COLORLABEL , MASK , HIGHLIGHT = range (6 )
2223
2324_VOID_REGION = - 1
2425_NOT_FOUND = - 2
2829_PROPERTY_INDICES = {'temperature' : 0 , 'density' : 1 }
2930
3031_REACTION_UNITS = 'Reactions per Source Particle'
31- _FLUX_UNITS = 'Particle-cm per Source Particle'
3232_PRODUCTION_UNITS = 'Particles Produced per Source Particle'
3333_ENERGY_UNITS = 'eV per Source Particle'
3434
6060 'Std. Dev.' : 'std_dev' ,
6161 'Rel. Error' : 'rel_err' }
6262
63- def hash_file (filename ):
63+
64+ def hash_file (path ):
6465 # return the md5 hash of a file
6566 h = hashlib .md5 ()
66- with open (filename , 'rb' ) as file :
67+ with path . open ('rb' ) as file :
6768 chunk = 0
6869 while chunk != b'' :
6970 # read 32768 bytes at a time
@@ -72,50 +73,66 @@ def hash_file(filename):
7273 return h .hexdigest ()
7374
7475
75- class PlotModel ():
76- """ Geometry and plot settings for OpenMC Plot Explorer model
76+ def hash_model (model_path ):
77+ """Get hash values for materials.xml and geometry.xml (or model.xml)"""
78+ if model_path .is_file ():
79+ mat_xml_hash = hash_file (model_path )
80+ geom_xml_hash = ""
81+ elif (model_path / 'model.xml' ).exists ():
82+ mat_xml_hash = hash_file (model_path / 'model.xml' )
83+ geom_xml_hash = ""
84+ else :
85+ mat_xml_hash = hash_file (model_path / 'materials.xml' )
86+ geom_xml_hash = hash_file (model_path / 'geometry.xml' )
87+ return mat_xml_hash , geom_xml_hash
7788
78- Parameters
79- ----------
80- use_settings_pkl : bool
81- If True, use plot_settings.pkl file to reload settings
8289
83- Attributes
84- ----------
85- geom : openmc.Geometry instance
86- OpenMC Geometry of the model
87- modelCells : collections.OrderedDict
88- Dictionary mapping cell IDs to openmc.Cell instances
89- modelMaterials : collections.OrderedDict
90- Dictionary mapping material IDs to openmc.Material instances
91- ids : NumPy int array (v_res, h_res, 1)
92- Mapping of plot coordinates to cell/material ID by pixel
93- ids_map : NumPy int32 array (v_res, h_res, 3)
94- Mapping of cell and material ids
95- properties : Numpy float array (v_res, h_res, 3)
96- Mapping of cell temperatures and material densities
97- image : NumPy int array (v_res, h_res, 3)
98- The current RGB image data
99- statepoint : StatePointModel
100- Simulation data model used to display tally results
101- applied_filters : tuple of ints
102- IDs of the applied filters for the displayed tally
103- previousViews : list of PlotView instances
104- List of previously created plot view settings used to undo
105- changes made in plot explorer
106- subsequentViews : list of PlotView instances
107- List of undone plot view settings used to redo changes made
108- in plot explorer
109- defaultView : PlotView instance
110- Default settings for given geometry
111- currentView : PlotView instance
112- Currently displayed plot settings in plot explorer
113- activeView : PlotView instance
114- Active state of settings in plot explorer, which may or may not
115- have unapplied changes
90+ class PlotModel :
91+ """Geometry and plot settings for OpenMC Plot Explorer model
92+
93+ Parameters
94+ ----------
95+ use_settings_pkl : bool
96+ If True, use plot_settings.pkl file to reload settings
97+ model_path : pathlib.Path
98+ Path to model XML file or directory
99+
100+ Attributes
101+ ----------
102+ geom : openmc.Geometry
103+ OpenMC Geometry of the model
104+ modelCells : collections.OrderedDict
105+ Dictionary mapping cell IDs to openmc.Cell instances
106+ modelMaterials : collections.OrderedDict
107+ Dictionary mapping material IDs to openmc.Material instances
108+ ids : NumPy int array (v_res, h_res, 1)
109+ Mapping of plot coordinates to cell/material ID by pixel
110+ ids_map : NumPy int32 array (v_res, h_res, 3)
111+ Mapping of cell and material ids
112+ properties : Numpy float array (v_res, h_res, 3)
113+ Mapping of cell temperatures and material densities
114+ image : NumPy int array (v_res, h_res, 3)
115+ The current RGB image data
116+ statepoint : StatePointModel
117+ Simulation data model used to display tally results
118+ applied_filters : tuple of ints
119+ IDs of the applied filters for the displayed tally
120+ previousViews : list of PlotView instances
121+ List of previously created plot view settings used to undo
122+ changes made in plot explorer
123+ subsequentViews : list of PlotView instances
124+ List of undone plot view settings used to redo changes made
125+ in plot explorer
126+ defaultView : PlotView
127+ Default settings for given geometry
128+ currentView : PlotView
129+ Currently displayed plot settings in plot explorer
130+ activeView : PlotView
131+ Active state of settings in plot explorer, which may or may not
132+ have unapplied changes
116133 """
117134
118- def __init__ (self , use_settings_pkl ):
135+ def __init__ (self , use_settings_pkl , model_path ):
119136 """ Initialize PlotModel class attributes """
120137
121138 # Retrieve OpenMC Cells/Materials
@@ -147,8 +164,13 @@ def __init__(self, use_settings_pkl):
147164
148165 self .defaultView = self .getDefaultView ()
149166
150- if use_settings_pkl and os .path .isfile ('plot_settings.pkl' ):
151- with open ('plot_settings.pkl' , 'rb' ) as file :
167+ if model_path .is_file ():
168+ settings_pkl = model_path .with_name ('plot_settings.pkl' )
169+ else :
170+ settings_pkl = model_path / 'plot_settings.pkl'
171+
172+ if use_settings_pkl and settings_pkl .is_file ():
173+ with settings_pkl .open ('rb' ) as file :
152174 try :
153175 data = pickle .load (file )
154176 except AttributeError :
@@ -176,8 +198,7 @@ def __init__(self, use_settings_pkl):
176198
177199 # get materials.xml and geometry.xml hashes to
178200 # restore additional settings if possible
179- mat_xml_hash = hash_file ('materials.xml' )
180- geom_xml_hash = hash_file ('geometry.xml' )
201+ mat_xml_hash , geom_xml_hash = hash_model (model_path )
181202 if mat_xml_hash == data ['mat_xml_hash' ] and \
182203 geom_xml_hash == data ['geom_xml_hash' ]:
183204 restore_domains = True
@@ -1071,8 +1092,8 @@ def adopt_plotbase(self, view):
10711092 self .basis = view .basis
10721093
10731094
1074- class DomainView () :
1075- """ Represents view settings for OpenMC cell or material.
1095+ class DomainView :
1096+ """Represents view settings for OpenMC cell or material.
10761097
10771098 Parameters
10781099 ----------
0 commit comments