Skip to content

Commit 751d211

Browse files
committed
WIP: get plotting working, fix display of groups. Next: table for edit of params
1 parent bdb60ed commit 751d211

File tree

3 files changed

+125
-60
lines changed

3 files changed

+125
-60
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 88 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,13 +4300,14 @@ def OnFileBrowse(self, event):
43004300
print (traceback.format_exc())
43014301

43024302

4303-
def StartProject(self):
4303+
def StartProject(self,selectItem=True):
43044304
'''Opens a GSAS-II project file & selects the 1st available data set to
43054305
display (PWDR, HKLF, REFD or SASD)
43064306
'''
43074307

43084308
Id = 0
43094309
phaseId = None
4310+
GroupId = None
43104311
seqId = None
43114312
G2IO.ProjFileOpen(self)
43124313
self.GPXtree.SetItemText(self.root,'Project: '+self.GSASprojectfile)
@@ -4326,26 +4327,36 @@ def StartProject(self):
43264327
seqId = item
43274328
elif name == "Phases":
43284329
phaseId = item
4330+
elif name.startswith("Groups"):
4331+
GroupId = item
43294332
elif name == 'Controls':
43304333
data = self.GPXtree.GetItemPyData(item)
43314334
if data:
43324335
for item in self.Refine: item.Enable(True)
43334336
item, cookie = self.GPXtree.GetNextChild(self.root, cookie)
43344337
if phaseId: # show all phases
43354338
self.GPXtree.Expand(phaseId)
4336-
if seqId:
4339+
if GroupId:
4340+
self.GPXtree.Expand(GroupId)
4341+
# select an item
4342+
if seqId and selectItem:
43374343
self.EnablePlot = True
43384344
SelectDataTreeItem(self,seqId)
43394345
self.GPXtree.SelectItem(seqId) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4340-
elif Id:
4346+
elif GroupId and selectItem:
4347+
self.EnablePlot = True
4348+
self.GPXtree.Expand(GroupId)
4349+
SelectDataTreeItem(self,GroupId)
4350+
self.GPXtree.SelectItem(GroupId) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4351+
elif Id and selectItem:
43414352
self.EnablePlot = True
43424353
self.GPXtree.Expand(Id)
43434354
SelectDataTreeItem(self,Id)
43444355
self.GPXtree.SelectItem(Id) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
4345-
elif phaseId:
4356+
elif phaseId and selectItem:
43464357
Id = phaseId
43474358
# open 1st phase
4348-
Id, unused = self.GPXtree.GetFirstChild(phaseId)
4359+
Id,_ = self.GPXtree.GetFirstChild(phaseId)
43494360
SelectDataTreeItem(self,Id)
43504361
self.GPXtree.SelectItem(Id) # as before for OSX
43514362
self.CheckNotebook()
@@ -7924,6 +7935,8 @@ def SearchGroups(event):
79247935
is judged by a common string that matches a template
79257936
supplied by the user
79267937
'''
7938+
ans = G2frame.OnFileSave(None)
7939+
if not ans: return
79277940
Histograms,Phases = G2frame.GetUsedHistogramsAndPhasesfromTree()
79287941
for hist in Histograms:
79297942
if hist.startswith('PWDR '):
@@ -7932,6 +7945,8 @@ def SearchGroups(event):
79327945
G2G.G2MessageBox(G2frame,'No PWDR histograms found to group',
79337946
'Cannot group')
79347947
return
7948+
repeat = True
7949+
srchStr = hist[5:]
79357950
msg = ('Edit the histogram name below placing a question mark (?) '
79367951
'at the location '
79377952
'of characters that change between groups of '
@@ -7940,40 +7955,71 @@ def SearchGroups(event):
79407955
'vary within a histogram group (e.g. Bank 1). '
79417956
'Be sure to leave enough characters so the string '
79427957
'can be uniquely matched.')
7943-
res = G2G.StringSearchTemplate(G2frame,'Set match template',msg,hist[5:])
7944-
re_res = re.compile(res.replace('.',r'\.').replace('?','.'))
7945-
setDict = {}
7946-
keyList = []
7947-
noMatchCount = 0
7948-
for hist in Histograms:
7949-
if hist.startswith('PWDR '):
7950-
m = re_res.search(hist)
7951-
if m:
7952-
key = hist[m.start():m.end()]
7953-
setDict[hist] = key
7954-
if key not in keyList: keyList.append(key)
7955-
else:
7956-
noMatchCount += 1
7957-
groupDict = {}
7958-
groupCount = {}
7959-
for k in keyList:
7960-
groupDict[k] = [hist for hist,key in setDict.items() if k == key]
7961-
groupCount[k] = len(groupDict[k])
7958+
while repeat:
7959+
srchStr = G2G.StringSearchTemplate(G2frame,'Set match template',
7960+
msg,srchStr)
7961+
if srchStr is None: return # cancel pressed
7962+
reSrch = re.compile(srchStr.replace('.',r'\.').replace('?','.'))
7963+
setDict = {}
7964+
keyList = []
7965+
noMatchCount = 0
7966+
for hist in Histograms:
7967+
if hist.startswith('PWDR '):
7968+
m = reSrch.search(hist)
7969+
if m:
7970+
key = hist[m.start():m.end()]
7971+
setDict[hist] = key
7972+
if key not in keyList: keyList.append(key)
7973+
else:
7974+
noMatchCount += 1
7975+
groupDict = {}
7976+
groupCount = {}
7977+
for k in keyList:
7978+
groupDict[k] = [hist for hist,key in setDict.items() if k == key]
7979+
groupCount[k] = len(groupDict[k])
79627980

7963-
msg = f'With template {res!r} found '
7964-
if min(groupCount.values()) == max(groupCount.values()):
7965-
msg += f'{len(groupDict)} groups with {min(groupCount.values())} histograms each'
7966-
else:
7967-
msg += (f'{len(groupDict)} groups with between {min(groupCount.values())}'
7968-
f' and {min(groupCount.values())} histograms in each')
7969-
if noMatchCount:
7970-
msg += f"\n\nNote that {noMatchCount} PWDR histograms were not included in any groups"
7971-
G2G.G2MessageBox(G2frame,msg,'Grouping result')
7972-
data['Groups'] = {'groupDict':groupDict,'notGrouped':noMatchCount,
7973-
'template':res}
7974-
wx.CallAfter(UpdateControls,G2frame,data)
7981+
msg1 = f'With template {srchStr!r} found '
7982+
if min(groupCount.values()) == max(groupCount.values()):
7983+
msg1 += f'{len(groupDict)} groups with {min(groupCount.values())} histograms each'
7984+
else:
7985+
msg1 += (f'{len(groupDict)} groups with between {min(groupCount.values())}'
7986+
f' and {min(groupCount.values())} histograms in each')
7987+
if noMatchCount:
7988+
msg1 += f"\n\nNote that {noMatchCount} PWDR histograms were not included in any groups"
7989+
#G2G.G2MessageBox(G2frame,msg1,'Grouping result')
7990+
res = G2G.ShowScrolledInfo(G2frame,msg1,header='Grouping result',
7991+
buttonlist=[
7992+
('OK', lambda event: event.GetEventObject().GetParent().EndModal(wx.ID_OK)),
7993+
('try again', lambda event: event.GetEventObject().GetParent().EndModal(wx.ID_CANCEL))
7994+
],
7995+
height=150)
7996+
if res == wx.ID_OK:
7997+
repeat = False
79757998

7976-
# start of UpdateControls
7999+
data['Groups'] = {'groupDict':groupDict,'notGrouped':noMatchCount,
8000+
'template':srchStr}
8001+
# wx.CallAfter(UpdateControls,G2frame,data)
8002+
ans = G2frame.OnFileSave(None)
8003+
if not ans: return
8004+
G2frame.clearProject() # clear out data tree
8005+
G2frame.StartProject(False)
8006+
#self.EnablePlot = True
8007+
Id = GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')
8008+
SelectDataTreeItem(G2frame,Id)
8009+
G2frame.GPXtree.SelectItem(Id) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
8010+
8011+
def ClearGroups(event):
8012+
del data['Groups']
8013+
ans = G2frame.OnFileSave(None)
8014+
if not ans: return
8015+
G2frame.clearProject() # clear out data tree
8016+
G2frame.StartProject(False)
8017+
#self.EnablePlot = True
8018+
Id = GetGPXtreeItemId(G2frame,G2frame.root, 'Controls')
8019+
SelectDataTreeItem(G2frame,Id)
8020+
G2frame.GPXtree.SelectItem(Id) # needed on OSX or item is not selected in tree; perhaps not needed elsewhere
8021+
8022+
#======= start of UpdateControls ===========================================
79778023
if 'SVD' in data['deriv type']:
79788024
G2frame.GetStatusBar().SetStatusText('Hessian SVD not recommended for initial refinements; use analytic Hessian or Jacobian',1)
79798025
else:
@@ -8037,6 +8083,11 @@ def SearchGroups(event):
80378083
btn = wx.Button(G2frame.dataWindow, wx.ID_ANY,'Define groupings')
80388084
btn.Bind(wx.EVT_BUTTON,SearchGroups)
80398085
subSizer.Add(btn)
8086+
if groupDict:
8087+
btn = wx.Button(G2frame.dataWindow, wx.ID_ANY,'Clear groupings')
8088+
subSizer.Add((5,-1))
8089+
subSizer.Add(btn)
8090+
btn.Bind(wx.EVT_BUTTON,ClearGroups)
80408091
subSizer.Add((-1,-1),1,wx.EXPAND)
80418092
mainSizer.Add(subSizer,0,wx.EXPAND)
80428093
mainSizer.Add((-1,8))

GSASII/GSASIImiscGUI.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import os
2323
import re
2424
import copy
25-
import platform
25+
#import platform
2626
import pickle
2727
import sys
2828
import random as ran
@@ -719,7 +719,7 @@ def ProjFileSave(G2frame):
719719
commit = g2repo.head.commit
720720
Controls['LastSavedUsing'] += f" git {commit.hexsha[:8]}"
721721
else:
722-
gv = getSavedVersionInfo()
722+
gv = GSASIIpath.getSavedVersionInfo()
723723
if gv is not None:
724724
Controls['LastSavedUsing'] += f" static {gv.git_version[:8]}"
725725
except:
@@ -730,7 +730,7 @@ def ProjFileSave(G2frame):
730730
while item:
731731
data = []
732732
name = G2frame.GPXtree.GetItemText(item)
733-
if name.startswith('Hist/Phase'): # skip over this
733+
if name.startswith('Hist/Phase') or name.startswith('Groups'): # skip over this
734734
item, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie)
735735
continue
736736
data.append([name,G2frame.GPXtree.GetItemPyData(item)])

GSASII/GSASIIpwdplot.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,8 +2020,7 @@ def onPartialConfig(event):
20202020
if Ymax is None: Ymax = max(xye[1])
20212021
Ymax = max(Ymax,max(xye[1]))
20222022
if Ymax is None: return # nothing to plot
2023-
offsetX = Page.plotStyle['Offset'][1]
2024-
offsetY = Page.plotStyle['Offset'][0]
2023+
offsetY,offsetX = Page.plotStyle.get('Offset',(0,0))[:2]
20252024
if Page.plotStyle['logPlot']:
20262025
Title = 'log('+Title+')'
20272026
elif Page.plotStyle['sqrtPlot']:
@@ -2116,32 +2115,44 @@ def onPartialConfig(event):
21162115
gridspec_kw=GS_kw)
21172116
Page.figure.subplots_adjust(left=5/100.,bottom=16/150.,
21182117
right=.99,top=1.-3/200.,hspace=0,wspace=0)
2118+
def adjustDim(i,nx):
2119+
'''MPL creates a 1-D array when nx=1, 2-D otherwise.
2120+
This adjusts the array addressing.
2121+
'''
2122+
if nx == 1:
2123+
return (0,1)
2124+
else:
2125+
return ((0,i),(1,i))
21192126
for i in range(nx):
2120-
Plots[0,i].set_xlim(gXmin[i],gXmax[i])
2121-
Plots[1,i].set_xlim(gXmin[i],gXmax[i])
2122-
Plots[1,i].set_ylim(DZmin,DZmax)
2127+
up,down = adjustDim(i,nx)
2128+
Plots[up].set_xlim(gXmin[i],gXmax[i])
2129+
Plots[down].set_xlim(gXmin[i],gXmax[i])
2130+
Plots[down].set_ylim(DZmin,DZmax)
21232131
if not Page.plotStyle.get('flTicks',False):
2124-
Plots[0,i].set_ylim(-len(Page.phaseList)*5,102)
2132+
Plots[up].set_ylim(-len(Page.phaseList)*5,102)
21252133
else:
2126-
Plots[0,i].set_ylim(-1,102)
2134+
Plots[up].set_ylim(-1,102)
21272135

21282136
# pretty up the tick labels
2129-
Plots[0,0].tick_params(axis='y', direction='inout', left=True, right=True)
2130-
Plots[1,0].tick_params(axis='y', direction='inout', left=True, right=True)
2131-
for ax in Plots[:,1:].ravel():
2132-
ax.tick_params(axis='y', direction='in', left=True, right=True)
2137+
up,down = adjustDim(0,nx)
2138+
Plots[up].tick_params(axis='y', direction='inout', left=True, right=True)
2139+
Plots[down].tick_params(axis='y', direction='inout', left=True, right=True)
2140+
if nx > 1:
2141+
for ax in Plots[:,1:].ravel():
2142+
ax.tick_params(axis='y', direction='in', left=True, right=True)
21332143
# remove 1st upper y-label so that it does not overlap with lower box
2134-
Plots[0,0].get_yticklabels()[0].set_visible(False)
2135-
Plots[1,0].set_ylabel(r'$\mathsf{\Delta I/\sigma_I}$',fontsize=12)
2144+
Plots[up].get_yticklabels()[0].set_visible(False)
2145+
Plots[down].set_ylabel(r'$\mathsf{\Delta I/\sigma_I}$',fontsize=12)
21362146
if Page.plotStyle['sqrtPlot']:
2137-
Plots[0,0].set_ylabel(r'$\rm\sqrt{Normalized\ intensity}$',fontsize=12)
2147+
Plots[up].set_ylabel(r'$\rm\sqrt{Normalized\ intensity}$',fontsize=12)
21382148
else:
2139-
Plots[0,0].set_ylabel('Normalized Intensity',fontsize=12)
2149+
Plots[up].set_ylabel('Normalized Intensity',fontsize=12)
21402150
Page.figure.text(0.001,0.03,commonltrs,fontsize=13)
21412151
Page.figure.supxlabel(xLabel)
21422152
for i,h in enumerate(groupDict[groupName]):
2143-
Plot = Plots[0,i]
2144-
Plot1 = Plots[1,i]
2153+
up,down = adjustDim(i,nx)
2154+
Plot = Plots[up]
2155+
Plot1 = Plots[down]
21452156
if Page.plotStyle['qPlot']:
21462157
pos = 0.98
21472158
ha = 'right'
@@ -2208,10 +2219,13 @@ def onPartialConfig(event):
22082219
Plot.axvline(xt,color=plcolor,
22092220
picker=True,pickradius=3.,
22102221
label='_FLT_'+phase,lw=0.5)
2211-
# Not sure if this does anything
2212-
G2frame.dataWindow.moveTickLoc.Enable(False)
2213-
G2frame.dataWindow.moveTickSpc.Enable(False)
2222+
try: # try used as in PWDR menu not Groups
2223+
# Not sure if this does anything
2224+
G2frame.dataWindow.moveTickLoc.Enable(False)
2225+
G2frame.dataWindow.moveTickSpc.Enable(False)
22142226
# G2frame.dataWindow.moveDiffCurve.Enable(True)
2227+
except:
2228+
pass
22152229
Page.canvas.draw()
22162230
return
22172231
elif G2frame.Weight and not G2frame.Contour:

0 commit comments

Comments
 (0)