Skip to content

Commit e99db49

Browse files
committed
WIP: adding group tree items & plot groups
1 parent 3985cbe commit e99db49

File tree

5 files changed

+105
-20
lines changed

5 files changed

+105
-20
lines changed

GSASII/GSASIIdataGUI.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def new_util_find_library( name ):
6767
from . import GSASIIfpaGUI as G2fpa
6868
from . import GSASIIseqGUI as G2seq
6969
from . import GSASIIddataGUI as G2ddG
70+
from . import GSASIIgroupGUI as G2gr
7071

7172
try:
7273
wx.NewIdRef
@@ -8956,6 +8957,11 @@ def OnShowShift(event):
89568957
#import imp
89578958
#imp.reload(G2ddG)
89588959
G2ddG.MakeHistPhaseWin(G2frame)
8960+
elif G2frame.GPXtree.GetItemText(item).startswith('Groups/'):
8961+
# groupDict is defined (or item would not be in tree).
8962+
# At least for now, this does nothing, so advance to first group entry
8963+
item, cookie = G2frame.GPXtree.GetFirstChild(item)
8964+
wx.CallAfter(G2frame.GPXtree.SelectItem,item)
89598965
elif GSASIIpath.GetConfigValue('debug'):
89608966
print('Unknown tree item',G2frame.GPXtree.GetItemText(item))
89618967
############################################################################
@@ -9149,6 +9155,12 @@ def OnShowShift(event):
91499155
data = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)
91509156
G2pdG.UpdateReflectionGrid(G2frame,data,HKLF=True,Name=name)
91519157
G2frame.dataWindow.HideShow.Enable(True)
9158+
elif G2frame.GPXtree.GetItemText(parentID).startswith('Groups/'):
9159+
# groupDict is defined.
9160+
G2gr.UpdateGroup(G2frame,item)
9161+
elif GSASIIpath.GetConfigValue('debug'):
9162+
print(f'Unknown subtree item {G2frame.GPXtree.GetItemText(item)!r}',
9163+
f'\n\tparent: {G2frame.GPXtree.GetItemText(parentID)!r}')
91529164

91539165
if G2frame.PickId:
91549166
G2frame.PickIdText = G2frame.GetTreeItemsList(G2frame.PickId)

GSASII/GSASIIgroupGUI.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# -*- coding: utf-8 -*-
2+
'''
3+
Routines for working with groups of histograms.
4+
5+
Groups are defined in Controls entry ['Groups'] which contains three entries:
6+
7+
* Controls['Groups']['groupDict']
8+
a dict where each key is the name of the group and the value is a list of
9+
histograms in the group
10+
* Controls['Groups']['notGrouped']
11+
a count of the number of histograms that are not in any group
12+
* Controls['Groups']['template']
13+
the string used to set the grouping
14+
15+
See SearchGroups in :func:`GSASIIdataGUI.UpdateControls`.
16+
'''
17+
18+
# import math
19+
# import os
20+
# import re
21+
# import copy
22+
# import platform
23+
# import pickle
24+
# import sys
25+
# import random as ran
26+
27+
import numpy as np
28+
# import numpy.ma as ma
29+
import wx
30+
31+
from . import GSASIIpath
32+
from . import GSASIIdataGUI as G2gd
33+
# from . import GSASIIobj as G2obj
34+
# import GSASIIpwdGUI as G2pdG
35+
# from . import GSASIIimgGUI as G2imG
36+
# from . import GSASIIElem as G2el
37+
# from . import GSASIIfiles as G2fil
38+
# from . import GSASIIctrlGUI as G2G
39+
# from . import GSASIImath as G2mth
40+
# from . import GSASIIElem as G2elem
41+
# from . import GSASIIspc as G2spc
42+
# from . import GSASIIlattice as G2lat
43+
# from . import GSASIIpwd as G2pwd
44+
from . import GSASIIctrlGUI as G2G
45+
from . import GSASIIpwdplot as G2pwpl
46+
WACV = wx.ALIGN_CENTER_VERTICAL
47+
48+
def UpdateGroup(G2frame,item):
49+
G2gd.SetDataMenuBar(G2frame)
50+
G2frame.dataWindow.helpKey = "Groups/PWDR"
51+
topSizer = G2frame.dataWindow.topBox
52+
parent = G2frame.dataWindow.topPanel
53+
topSizer.Add(wx.StaticText(parent,label=' Group edit goes here someday'),0,WACV)
54+
topSizer.Add((-1,-1),1,wx.EXPAND)
55+
topSizer.Add(G2G.HelpButton(parent,helpIndex=G2frame.dataWindow.helpKey))
56+
G2G.HorizontalLine(G2frame.dataWindow.GetSizer(),G2frame.dataWindow)
57+
#G2frame.dataWindow.GetSizer().Add(text,1,wx.ALL|wx.EXPAND)
58+
G2frame.groupName = G2frame.GPXtree.GetItemText(item)
59+
G2pwpl.PlotPatterns(G2frame,plotType='GROUP')

GSASII/GSASIImiscGUI.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
99
'''
1010

11-
from __future__ import division, print_function
12-
1311
# # Allow this to be imported without wx present.
1412
# try:
1513
# import wx
@@ -554,6 +552,8 @@ def ProjFileOpen(G2frame,showProvenance=True):
554552
finally:
555553
dlg.Destroy()
556554
wx.BeginBusyCursor()
555+
groupDict = {}
556+
groupInserted = False # only need to do this once
557557
try:
558558
if GSASIIpath.GetConfigValue('show_gpxSize'):
559559
posPrev = 0
@@ -575,13 +575,23 @@ def ProjFileOpen(G2frame,showProvenance=True):
575575
#if unexpectedObject:
576576
# print(datum[0])
577577
# GSASIIpath.IPyBreak()
578+
# insert groups before any individual PDWR items
579+
if datum[0].startswith('PWDR') and groupDict and not groupInserted:
580+
Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text='Groups/PWDR')
581+
G2frame.GPXtree.SetItemPyData(Id,{})
582+
for nam in groupDict:
583+
sub = G2frame.GPXtree.AppendItem(parent=Id,text=nam)
584+
G2frame.GPXtree.SetItemPyData(sub,{})
585+
groupInserted = True
578586
Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text=datum[0])
579587
if datum[0] == 'Phases' and GSASIIpath.GetConfigValue('SeparateHistPhaseTreeItem',False):
580588
G2frame.GPXtree.AppendItem(parent=G2frame.root,text='Hist/Phase')
581589
if updateFromSeq and datum[0] == 'Phases':
582590
for pdata in data[1:]:
583591
if pdata[0] in Phases:
584592
pdata[1].update(Phases[pdata[0]])
593+
elif datum[0] == 'Controls':
594+
groupDict = datum[1].get('Groups',{}).get('groupDict',{})
585595
elif updateFromSeq and datum[0] == 'Covariance':
586596
data[0][1] = CovData
587597
elif updateFromSeq and datum[0] == 'Rigid bodies':

GSASII/GSASIIpwdplot.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def OnPlotKeyPress(event):
199199
try: #one way to check if key stroke will work on plot
200200
Parms,Parms2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.PatternId, 'Instrument Parameters'))
201201
except TypeError:
202-
G2frame.G2plotNB.status.SetStatusText('Select '+plottype+' pattern first',1)
202+
G2frame.G2plotNB.status.SetStatusText(f'Select {plottype} pattern first',1)
203203
return
204204
newPlot = False
205205
if event.key == 'w':
@@ -1602,6 +1602,19 @@ def onPartialConfig(event):
16021602
for i in 'Obs_color','Calc_color','Diff_color','Bkg_color':
16031603
pwdrCol[i] = '#' + GSASIIpath.GetConfigValue(i,getDefault=True)
16041604

1605+
groupName = None
1606+
groupDict = {}
1607+
if plotType == 'GROUP':
1608+
groupName = G2frame.groupName # set in GSASIIgroupGUI.UpdateGroup
1609+
Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
1610+
groupDict = Controls.get('Groups',{}).get('groupDict',{})
1611+
if groupName not in groupDict:
1612+
print(f'Unexpected: {groupName} not in groupDict')
1613+
return
1614+
# set data to first histogram in group
1615+
G2frame.PatternId = G2gd.GetGPXtreeItemId(G2frame, G2frame.root, groupDict[groupName][0])
1616+
data = G2frame.GPXtree.GetItemPyData(G2frame.PatternId)
1617+
16051618
if not G2frame.PatternId:
16061619
return
16071620
if 'PKS' in plottype: # This is probably not used anymore; PlotPowderLines seems to be called directly
@@ -1614,6 +1627,11 @@ def onPartialConfig(event):
16141627
else:
16151628
publish = None
16161629
new,plotNum,Page,Plot,limits = G2frame.G2plotNB.FindPlotTab('Powder Patterns','mpl',publish=publish)
1630+
# if we are changing histogram types (including group to individual, reset plot)
1631+
if not new and hasattr(Page,'prevPlotType'):
1632+
if Page.prevPlotType != plotType: new = True
1633+
Page.prevPlotType = plotType
1634+
16171635
if G2frame.ifSetLimitsMode and G2frame.GPXtree.GetItemText(G2frame.GPXtree.GetSelection()) == 'Limits':
16181636
# note mode
16191637
if G2frame.ifSetLimitsMode == 1:
@@ -1641,8 +1659,8 @@ def onPartialConfig(event):
16411659
G2frame.lastPlotType
16421660
except:
16431661
G2frame.lastPlotType = None
1644-
groupDict = {}
1645-
if plotType == 'PWDR':
1662+
1663+
if plotType == 'PWDR' or plotType == 'GROUP':
16461664
try:
16471665
Parms,Parms2 = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,
16481666
G2frame.PatternId, 'Instrument Parameters'))
@@ -1662,8 +1680,6 @@ def onPartialConfig(event):
16621680
G2frame.lastPlotType = Parms['Type'][1]
16631681
except TypeError: #bad id from GetGPXtreeItemId - skip
16641682
pass
1665-
Controls = G2frame.GPXtree.GetItemPyData(G2gd.GetGPXtreeItemId(G2frame,G2frame.root, 'Controls'))
1666-
groupDict = Controls.get('Groups',{}).get('groupDict',{})
16671683
try:
16681684
G2frame.FixedLimits
16691685
except:
@@ -2003,17 +2019,6 @@ def onPartialConfig(event):
20032019
xLabel = 'E, keV'
20042020
else:
20052021
xLabel = r'$\mathsf{2\theta}$'
2006-
# working here
2007-
groupName = None
2008-
if groupDict:
2009-
histname = G2frame.GPXtree.GetItemText(G2frame.PatternId)
2010-
for key in groupDict:
2011-
if histname in groupDict[key]:
2012-
groupName = key
2013-
break
2014-
else:
2015-
print('No group for histogram',histname)
2016-
20172022
if groupName is not None:
20182023
# plot a group of histograms
20192024
Page.Choice = [' key press',

GSASII/meson.build

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ py.install_sources([
99
'GSASIIGUI.py',
1010
'GSASIIElem.py',
1111
'GSASIIElemGUI.py',
12-
# 'GSASIIIO.py',
1312
'GSASIImiscGUI.py',
1413
'GSASIIIntPDFtool.py',
1514
'GSASIIconstrGUI.py',
@@ -20,11 +19,11 @@ py.install_sources([
2019
'GSASIIexprGUI.py',
2120
'GSASIIfiles.py',
2221
'GSASIIfpaGUI.py',
22+
'GSASIIgroupGUI.py',
2323
'GSASIIimage.py',
2424
'GSASIIimgGUI.py',
2525
'GSASIIindex.py',
2626
'GSASIIlattice.py',
27-
# 'GSASIIlog.py',
2827
'GSASIImapvars.py',
2928
'GSASIImath.py',
3029
'GSASIImpsubs.py',

0 commit comments

Comments
 (0)