Skip to content

Commit 784e3be

Browse files
committed
refactor value reference in prep for copy by group
1 parent 14d7ca2 commit 784e3be

2 files changed

Lines changed: 439 additions & 609 deletions

File tree

GSASII/GSASIIdataGUI.py

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,8 +7952,6 @@ def SearchGroups(event):
79527952
is judged by a common string that matches a template
79537953
supplied by the user
79547954
'''
7955-
ans = G2frame.OnFileSave(None)
7956-
if not ans: return
79577955
Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
79587956
for hist in Histograms:
79597957
if hist.startswith('PWDR '):
@@ -7962,63 +7960,9 @@ def SearchGroups(event):
79627960
G2G.G2MessageBox(G2frame,'No used PWDR histograms found to group. Histograms must be assigned phase(s).',
79637961
'Cannot group')
79647962
return
7965-
repeat = True
7966-
srchStr = hist[5:]
7967-
msg = ('Edit the histogram name below placing a question mark (?) '
7968-
'at the location '
7969-
'of characters that change between groups of '
7970-
'histograms. Use backspace or delete to remove '
7971-
'characters that should be ignored as they will '
7972-
'vary within a histogram group (e.g. Bank 1). '
7973-
'Be sure to leave enough characters so the string '
7974-
'can be uniquely matched.')
7975-
while repeat:
7976-
srchStr = G2G.StringSearchTemplate(G2frame,'Set match template',
7977-
msg,srchStr)
7978-
if srchStr is None: return # cancel pressed
7979-
reSrch = re.compile(srchStr.replace('.',r'\.').replace('?','.'))
7980-
setDict = {}
7981-
keyList = []
7982-
noMatchCount = 0
7983-
for hist in Histograms:
7984-
if hist.startswith('PWDR '):
7985-
m = reSrch.search(hist)
7986-
if m:
7987-
key = hist[m.start():m.end()]
7988-
setDict[hist] = key
7989-
if key not in keyList: keyList.append(key)
7990-
else:
7991-
noMatchCount += 1
7992-
groupDict = {}
7993-
groupCount = {}
7994-
for k in keyList:
7995-
groupDict[k] = [hist for hist,key in setDict.items() if k == key]
7996-
groupCount[k] = len(groupDict[k])
7997-
7998-
msg1 = f'With template {srchStr!r} found '
7999-
8000-
buttons = []
8001-
if min(groupCount.values()) == max(groupCount.values()):
8002-
msg1 += f'{len(groupDict)} groups with {min(groupCount.values())} histograms each'
8003-
else:
8004-
msg1 += (f'{len(groupDict)} groups with between {min(groupCount.values())}'
8005-
f' and {min(groupCount.values())} histograms in each')
8006-
if noMatchCount:
8007-
msg1 += f"\n\nNote that {noMatchCount} PWDR histograms were not included in any groups"
8008-
#G2G.G2MessageBox(G2frame,msg1,'Grouping result')
8009-
# place a sanity check limit on the number of histograms in a group
8010-
if max(groupCount.values()) < 150:
8011-
buttons += [('OK', lambda event: event.GetEventObject().GetParent().EndModal(wx.ID_OK))]
8012-
else:
8013-
msg1 += '\n\nThis exceeds the maximum group length of 150 histograms'
8014-
buttons += [('try again', lambda event: event.GetEventObject().GetParent().EndModal(wx.ID_CANCEL))]
8015-
res = G2G.ShowScrolledInfo(G2frame,msg1,header='Grouping result',
8016-
buttonlist=buttons,height=150)
8017-
if res == wx.ID_OK:
8018-
repeat = False
8019-
8020-
data['Groups'] = {'groupDict':groupDict,'notGrouped':noMatchCount,
8021-
'template':srchStr}
7963+
ans = G2frame.OnFileSave(None)
7964+
if not ans: return
7965+
data['Groups'] = G2gr.SearchGroups(G2frame,Histograms,hist)
80227966
# wx.CallAfter(UpdateControls,G2frame,data)
80237967
ans = G2frame.OnFileSave(None)
80247968
if not ans: return

0 commit comments

Comments
 (0)