@@ -261,16 +261,24 @@ def plot_bragg_bank(main_window):
261261 # multiple GSAS file/single bank mode: get GSAS group from tree
262262 gss_group_list = main_window .rietveld_ui .treeWidget_braggWSList .get_main_nodes ()
263263 gss_group_list .remove ('workspaces' )
264-
265264 else :
266265 # single GSAS file mode
267266 status , ret_obj = main_window .rietveld_ui .treeWidget_braggWSList .get_current_main_nodes ()
267+ # ZYP -> Sometimes, it can happen that the returned `status` here is
268+ # `True`, but we have empty `ret_obj`. So we need to tackle such a
269+ # situation. Since this will happen when multiple GSS files exist in wks,
270+ # and therefore when this happens, we just simply roll into the multiple GSS mode.
268271 if status :
269- gss_group = ret_obj [0 ]
272+ if len (ret_obj ) > 0 :
273+ gss_group = ret_obj [0 ]
274+ else :
275+ gss_group_list = main_window .rietveld_ui .treeWidget_braggWSList .get_main_nodes ()
276+ gss_group_list .remove ('workspaces' )
270277 else :
271278 raise RuntimeError (
272279 'Unable to get current selected main node(s) due to {0}.' .format (ret_obj ))
273- gss_group_list = [gss_group ]
280+ if len (ret_obj ) > 0 :
281+ gss_group_list = [gss_group ]
274282
275283 # remove banks from plot
276284 for gss_group_name in gss_group_list :
@@ -282,22 +290,42 @@ def plot_bragg_bank(main_window):
282290 for ws_group in gss_group_list :
283291 plot_data_dict [ws_group ] = new_bank_list [:]
284292
293+ # ZYP -> Check whether selected bank (to plot) exists or not.
294+ # ZYP -> If not, no action will be taken and msg will be printed out to terminal.
295+ banks_checker_ok = True
296+ leaf_dict_temp = main_window .rietveld_ui .treeWidget_braggWSList ._leafDict
297+ for ws_group in gss_group_list :
298+ for bank_to_check in plot_data_dict [ws_group ]:
299+ if int (bank_to_check ) > len (leaf_dict_temp [ws_group ]):
300+ print ("Bank-{0} not existing in {1} and therefore not to be plotted." .format (bank_to_check , ws_group ))
301+ banks_checker_ok = False
302+ break
303+
285304 if plot_multi_gss :
286305 main_window .rietveld_ui .graphicsView_bragg .set_to_single_gss (False )
287306 else :
288307 main_window .rietveld_ui .graphicsView_bragg .set_to_single_gss (True )
289308 status , ws_name_list = main_window .rietveld_ui .treeWidget_braggWSList .get_current_main_nodes ()
309+ # ZYP -> Sometimes, it can happen that the returned `status` here is
310+ # `True`, but we have empty `ret_obj`. So we need to tackle such a
311+ # situation. Since this will happen when multiple GSS files exist in wks,
312+ # and therefore when this happens, we just simply roll into the multiple GSS mode.
313+ if len (ws_name_list ) == 0 :
314+ ws_name_list = main_window .rietveld_ui .treeWidget_braggWSList .get_main_nodes ()
315+ ws_name_list .remove ("workspaces" )
290316 plot_data_dict = {ws_name_list [0 ]: plot_data_dict [ws_name_list [0 ]]}
291317
292318 # plot new
293- main_window .rietveld_ui .graphicsView_bragg .plot_banks (
294- plot_data_dict , main_window ._currBraggXUnit )
319+ # ZYP -> Check whether selected bank (to plot) exists or not.
320+ if banks_checker_ok :
321+ main_window .rietveld_ui .graphicsView_bragg .plot_banks (
322+ plot_data_dict , main_window ._currBraggXUnit )
295323
296- # reset
297- reset_bragg_data_range (main_window , main_window ._currBraggXUnit )
324+ # reset
325+ reset_bragg_data_range (main_window , main_window ._currBraggXUnit )
298326
299- # rescale
300- do_rescale_bragg (main_window )
327+ # rescale
328+ do_rescale_bragg (main_window )
301329
302330
303331def do_rescale_bragg (main_window ):
@@ -526,10 +554,18 @@ def plot_bragg(main_window, ws_list, bankIds, clear_canvas=False):
526554
527555 # plot all workspsaces
528556 plot_data_dict = dict ()
557+ leaf_dict_temp = main_window .rietveld_ui .treeWidget_braggWSList ._leafDict
529558 for bragg_ws_name in ws_list :
530559 # construct dictionary for plotting
531560 # main_window._myController.get_bank_numbers(ws_group)
532- plot_data_dict [bragg_ws_name ] = bankIds
561+ to_plot = []
562+ for bank_temp in bankIds :
563+ if int (bank_temp ) <= len (leaf_dict_temp [bragg_ws_name ]):
564+ to_plot .append (bank_temp )
565+ else :
566+ print ("Bank-{0} not existing in {1} and therefore not to be plotted." .format (bank_temp , bragg_ws_name ))
567+ # plot_data_dict[bragg_ws_name] = bankIds
568+ plot_data_dict [bragg_ws_name ] = to_plot
533569
534570 # plot
535571 main_window .rietveld_ui .graphicsView_bragg .plot_banks (
0 commit comments