Skip to content

Commit 6a1e0a5

Browse files
committed
Merge remote-tracking branch 'origin/main' into MAXIV-HDF5
2 parents 6808e9b + 7baa794 commit 6a1e0a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+662
-318
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#from . import GSASIIstrMain as G2stMn
4545
from . import GSASIImiscGUI as G2IO
4646
from .tutorialIndex import tutorialIndex
47-
if sys.version_info[0] >= 3:
48-
unicode = str
49-
basestring = str
5047

5148
# Define a short names for convenience
5249
DULL_YELLOW = (230,230,190)
@@ -406,7 +403,7 @@ def __init__(self,parent,loc,key,nDig=None,notBlank=True,xmin=None,xmax=None,
406403
self.type = int
407404
elif 'float' in str(type(val)):
408405
self.type = float
409-
elif isinstance(val,str) or isinstance(val,unicode):
406+
elif isinstance(val,str):
410407
self.type = str
411408
elif val is None:
412409
raise Exception("ValidatedTxtCtrl error: value of "+str(key)+
@@ -4762,11 +4759,7 @@ def __init__(self,G2frame,title,parmDict,varyList,fullVaryList,
47624759
self.frozenList = []
47634760
# make lists of variables of different types along with lists of parameter names, histogram #s, phase #s,...
47644761
self.parmNames = sorted(list(parmDict.keys()))
4765-
if '2' in platform.python_version_tuple()[0]:
4766-
basestr = basestring
4767-
else:
4768-
basestr = str
4769-
splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],basestr)]
4762+
splitNames = [item.split(':') for item in self.parmNames if len(item) > 3 and not isinstance(self.parmDict[item],str)]
47704763
globNames = [':'.join(item) for item in splitNames if not item[0] and not item[1]]
47714764
if len(globNames):
47724765
self.choiceDict['Global'] = G2obj.SortVariables(globNames)
@@ -5022,11 +5015,7 @@ def __init__(self, parent):
50225015
def SetContents(self,parent):
50235016
self.varList = []
50245017
for name in parent.choiceDict[parent.parmChoice]:
5025-
if '2' in platform.python_version_tuple()[0]:
5026-
basestr = basestring
5027-
else:
5028-
basestr = str
5029-
if isinstance(parent.parmDict[name],basestr): continue
5018+
if isinstance(parent.parmDict[name],str): continue
50305019
if 'Refined' in parent.listSel and (name not in parent.fullVaryList
50315020
) and (name not in parent.varyList):
50325021
continue
@@ -5281,19 +5270,24 @@ def SetWildAfter(d,name,wname,mode):
52815270
# Callbacks to display info in table
52825271
def OnGetItemText(self, item, col):
52835272
name = self.varList[item]
5273+
atmParNam = None
5274+
if name.split(':')[2].startswith('dA'):
5275+
atmParNam = name.replace(':dA',':A')
52845276
if col == 0:
52855277
return str(item)
52865278
elif col == 1:
5279+
if atmParNam: return atmParNam
52875280
return name
52885281
elif col == 2:
52895282
if name in self.parmWin.fullVaryList and name in self.parmWin.frozenList:
5290-
return "F"
5283+
return "F"
52915284
elif name in self.parmWin.varyList:
52925285
return "R"
52935286
elif name in self.parmWin.fullVaryList:
52945287
return "C"
52955288
return ""
52965289
elif col == 3:
5290+
if atmParNam: name = atmParNam
52975291
try:
52985292
value = G2fil.FormatSigFigs(self.parmWin.parmDict[name])
52995293
except ValueError:

GSASII/GSASIIdataGUI.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,11 +3340,9 @@ class SumDialog(wx.Dialog):
33403340
'''Used to sum images or powder patterns. Allows user to supply
33413341
scale factor(s) when summing data.
33423342
3343-
TODO: clean up the scrolling & resize on this dialog
3344-
Can we use the copy down button from CIF?
3345-
TODO: move it to GSASIIctrlGUI?
3346-
BHT: this class should not be in the middle of the (already too complex)
3347-
GSASIImain class.
3343+
TODO: clean up the scrolling & resize on this dialog. Can we use the copy down button from CIF?
3344+
TODO: move it to GSASIIctrlGUI? (BHT) this class should not be in
3345+
the middle of the (already too complex) GSASIImain class.
33483346
'''
33493347
def __init__(self,parent,title,text,dataType,data,dataList,Limits=None):
33503348
wx.Dialog.__init__(self,parent,-1,title,size=(400,250),
@@ -3736,8 +3734,8 @@ def OnImageSum(self,event):
37363734
newimagefile = dlg.GetPath()
37373735
newimagefile = G2IO.FileDlgFixExt(dlg,newimagefile)
37383736
G2IO.PutG2Image(newimagefile,Comments,Data,Npix,newImage)
3739-
Imax = np.amax(newImage)
3740-
Imin = np.amin(newImage)
3737+
Imax = int(np.amax(newImage))
3738+
Imin = int(np.amin(newImage))
37413739
newImage = []
37423740
self.GPXtree.SetItemPyData(Id,[imSize,newimagefile])
37433741
self.GPXtree.SetItemPyData(self.GPXtree.AppendItem(Id,text='Comments'),Comments)

GSASII/GSASIIfiles.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import os
1414
import sys
1515
import glob
16+
import copy
1617
#import inspect
1718
import re
1819

1920
import numpy as np
21+
import numpy.ma as ma
2022

2123
from . import GSASIIpath
2224
from . import GSASIIlattice as G2lat
@@ -2165,7 +2167,8 @@ def loadTree(self):
21652167
# the main info goes into Data, but the 0th
21662168
# element contains refinement results, carry
21672169
# that over too now.
2168-
self.Histograms[name]['Data'] = self.G2frame.GPXtree.GetItemPyData(item)[1]
2170+
# make coopy so we can shift TOF
2171+
self.Histograms[name]['Data'] = copy.deepcopy(self.G2frame.GPXtree.GetItemPyData(item)[1])
21692172
self.Histograms[name][0] = self.G2frame.GPXtree.GetItemPyData(item)[0]
21702173
item2, cookie2 = self.G2frame.GPXtree.GetFirstChild(item)
21712174
while item2:
@@ -2177,6 +2180,18 @@ def loadTree(self):
21772180
for hist in self.Histograms:
21782181
if hist.startswith("PWDR"):
21792182
d = self.powderDict
2183+
# shift TOF from midpoint to bin start
2184+
if 'T' in self.Histograms[hist]['Instrument Parameters'][0]['Type'][0]:
2185+
if hasattr(self.Histograms[hist]['Data'][0],'mask'):
2186+
m = self.Histograms[hist]['Data'][0].mask
2187+
x = self.Histograms[hist]['Data'][0].data
2188+
# one half the averaged bin widths -- ~backs out the previous shift
2189+
halfbin = (np.append(x[1]-x[0],np.diff(x)) + np.append(np.diff(x),x[-1]-x[-2]))/4
2190+
self.Histograms[hist]['Data'][0] = ma.array(x-halfbin,mask=m)
2191+
else:
2192+
x = self.Histograms[hist]['Data'][0]
2193+
halfbin = (np.append(x[1]-x[0],np.diff(x)) + np.append(np.diff(x),x[-1]-x[-2]))/4
2194+
self.Histograms[hist]['Data'][0] -= halfbin
21802195
elif hist.startswith("HKLF"):
21812196
d = self.xtalDict
21822197
elif hist.startswith("SASD"):

GSASII/GSASIIimage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@
4646

4747
def peneCorr(tth,dep,dist):
4848
''' Compute empirical position correction due to detector absorption
49+
4950
:param float/array tth: angle between detector normal & scattered ray vector
5051
:param float dep: coefficient
5152
:param float dist: sample to detector surface in mm
52-
:returns: float/array distance: correction for penetration'''
53+
:returns: float/array distance: correction for penetration
54+
'''
5355

5456
return dep*(1.-npcosd(tth))*dist**2/1000. #best one
5557

5658
def GetTthP(x,y,parmDict):
5759
''' Compute angle between detector normal & sample scattering ray vector
60+
5861
:param float/array x: detector x-position in mm
5962
:param float/array y: detector y-position in mm
6063
:param dict parmDict: dictionary of detector orientation parameters in fitting routine

GSASII/GSASIIimgGUI.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,10 +2044,12 @@ def OnLoadPixelMask(event):
20442044
# was loaded rather than a search
20452045
data['SpotMask']['spotMask'] = maskImage > 0
20462046
nmasked = sum(data['SpotMask']['spotMask'].flatten())
2047-
frac = nmasked/data['SpotMask']['spotMask'].size
2047+
frac = 100*nmasked/data['SpotMask']['spotMask'].size
20482048
G2G.G2MessageBox(G2frame,
20492049
f'Mask removes {nmasked} pixels ({frac:.3f}%)',
20502050
'Mask loaded')
2051+
wx.CallAfter(UpdateMasks,G2frame,data)
2052+
wx.CallAfter(G2plt.PlotExposedImage,G2frame,event=event)
20512053

20522054
def OnFindPixelMask(event):
20532055
'''Do auto search for pixels to mask

GSASII/GSASIImiscGUI.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def LoadImage2Tree(imagefile,G2frame,Comments,Data,Npix,Image):
266266
TreeName = G2obj.MakeUniqueLabel(TreeLbl,ImgNames)
267267
Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text=TreeName)
268268
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Comments'),Comments)
269-
Imax = np.amax(Image)
269+
Imax = int(np.amax(Image))
270270
if G2frame.imageDefault:
271271
Data.update(copy.deepcopy(G2frame.imageDefault))
272272
Data['showLines'] = True

GSASII/GSASIIpath.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,24 +1781,6 @@ def makeScriptShortcut():
17811781
return
17821782
return newfil
17831783

1784-
# see if a directory for local modifications is defined. If so, stick that in the path
1785-
if os.path.exists(os.path.expanduser('~/.G2local/')):
1786-
sys.path.insert(0,os.path.expanduser('~/.G2local/'))
1787-
fl = glob.glob(os.path.expanduser('~/.G2local/GSASII*.py*'))
1788-
files = ""
1789-
prev = None
1790-
for f in sorted(fl): # make a list of files, dropping .pyc files where a .py exists
1791-
f = os.path.split(f)[1]
1792-
if os.path.splitext(f)[0] == prev: continue
1793-
prev = os.path.splitext(f)[0]
1794-
if files: files += ", "
1795-
files += f
1796-
if files:
1797-
print("*"*75)
1798-
print("Warning: the following source files are locally overridden in "+os.path.expanduser('~/.G2local/'))
1799-
print(" "+files)
1800-
print("*"*75)
1801-
18021784
BinaryPathFailed = False
18031785
BinaryPathLoaded = False
18041786
binaryPath = ''

GSASII/GSASIIphsGUI.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13377,10 +13377,9 @@ def rbKeyPress(event):
1337713377
G2frame.phaseDisplay.AddPage(G2frame.MCSA,'MC/SA')
1337813378
Pages.append('MC/SA')
1337913379

13380-
if nhist:
13381-
G2frame.FRMC = wx.ScrolledWindow(G2frame.phaseDisplay)
13382-
G2frame.phaseDisplay.AddPage(G2frame.FRMC,'RMC')
13383-
Pages.append('RMC')
13380+
G2frame.FRMC = wx.ScrolledWindow(G2frame.phaseDisplay)
13381+
G2frame.phaseDisplay.AddPage(G2frame.FRMC,'RMC')
13382+
Pages.append('RMC')
1338413383

1338513384
if dataGeneral['Type'] == 'nuclear':
1338613385
G2frame.ISODIST = wx.ScrolledWindow(G2frame.phaseDisplay)

GSASII/GSASIIphsGUI2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#GSASII - phase data display routines
33
'''
4-
5-
Routines for Phase dataframes follow. Only Update routines are here
4+
Routines for Phase dataframes follow. Only a few Update routines are here
65
all others are in GSASIIphsGUI.py
76
'''
87
import os

GSASII/GSASIIplot.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def __init__(self,parent,id=-1,dpi=None,publish=None,**kwargs):
215215
_tabPlotWin.__init__(self,parent,id=id,**kwargs)
216216
mpl.rcParams['legend.fontsize'] = 12
217217
mpl.rcParams['axes.grid'] = False
218+
#TODO: set dpi here via config var: this changes the size of the labeling font 72-100 is normal
218219
self.figure = mplfig.Figure(dpi=dpi,figsize=(5,6))
219220
self.canvas = Canvas(self,-1,self.figure)
220221
self.toolbar = GSASIItoolbar(self.canvas,publish=publish)
@@ -634,6 +635,11 @@ def set_message(self,s):
634635
'''
635636
pass
636637

638+
# TODO: perhaps someday we could pull out the bitmaps and rescale there here
639+
# def AddTool(self,*args,**kwargs):
640+
# print('AddTool',args,kwargs)
641+
# return Toolbar.AddTool(self,*args,**kwargs)
642+
637643
def AddToolBarTool(self,label,title,filename,callback):
638644
bmpFilename = GSASIIpath.getIconFile(filename)
639645
if bmpFilename is None:
@@ -642,10 +648,7 @@ def AddToolBarTool(self,label,title,filename,callback):
642648
else:
643649
bmp = wx.Bitmap(bmpFilename)
644650
# bmp = wx.Bitmap(bmpFilename,type=wx.BITMAP_TYPE_ANY) # probably better
645-
if 'phoenix' in wx.version():
646-
button = self.AddTool(wx.ID_ANY, label, bmp, title)
647-
else:
648-
button = self.AddSimpleTool(wx.ID_ANY, bmp, label, title)
651+
button = self.AddTool(wx.ID_ANY, label, bmp, title)
649652
wx.EVT_TOOL.Bind(self, button.GetId(), button.GetId(), callback)
650653
return button.GetId()
651654

@@ -732,6 +735,20 @@ def OnArrow(self,event):
732735
def OnHelp(self,event):
733736
'Respond to press of help button on plot toolbar'
734737
bookmark = self.Parent.helpKey # get help category used to create plot
738+
G2frame = wx.GetApp().GetMainTopWindow()
739+
if bookmark != G2frame.dataWindow.helpKey:
740+
# plot window and data window are different
741+
try:
742+
selText = '/'.join(G2frame.PickIdText)
743+
except:
744+
selText = G2frame.GPXtree.GetItemText(G2frame.GPXtree.GetSelection())
745+
G2G.G2MessageBox(G2frame,
746+
'Displaying help on plot window, but you have moved to a '
747+
f'different data tree item ({selText}) where plot menu items '
748+
'and key commands are not available. '
749+
'Return to the appropriate data tree '
750+
'item for full plot functionality',
751+
'Wrong data tree selection')
735752
#if GSASIIpath.GetConfigValue('debug'): print 'plot help: key=',bookmark
736753
G2G.ShowHelp(bookmark,self.TopLevelParent)
737754

@@ -3275,24 +3292,26 @@ def OnKeyPress(event):
32753292
sGp = []
32763293
Wp = []
32773294
Qp = []
3295+
sQp = []
32783296
for ip,peak in enumerate(peaks):
32793297
Qp.append(2.*np.pi*difC/peak[0])
3298+
sQp.append(2.*np.pi*difC*peakEsds.get('pos%d'%ip,0.0)/peak[0]**2)
32803299
Ap.append(peak[4])
32813300
sAp.append(peakEsds.get('alp%d'%ip,0.0))
32823301
Bp.append(peak[6])
32833302
sBp.append(peakEsds.get('bet%d'%ip,0.0))
3284-
sp = 1.17741*np.sqrt(peak[8])/peak[0]
3303+
sp = 0.5*sq8ln2*np.sqrt(peak[8])/peak[0]
32853304
Sp.append(sp) #sqrt(8ln2)/2
3286-
sSp.append(0.5*sp*peakEsds.get('sig%d'%ip,0.0)/peak[8])
3305+
sSp.append(0.25*sq8ln2*peakEsds.get('sig%d'%ip,0.0)/(np.sqrt(peak[8])*peak[0]))
32873306
Gp.append(peak[10]/peak[0])
32883307
sGp.append(peakEsds.get('gam%d'%ip,0.0)/peak[0])
32893308

32903309
if Qp:
32913310
if G2frame.ErrorBars:
3292-
Plot.errorbar(Qp,Ap,yerr=sAp,fmt='r+',capsize=2,label='A peak')
3293-
Plot.errorbar(Qp,Bp,yerr=sBp,fmt='+',color='orange',capsize=2,label='B peak')
3294-
Plot.errorbar(Qp,Sp,yerr=sSp,fmt='b+',capsize=2,label='G peak')
3295-
Plot.errorbar(Qp,Gp,yerr=sGp,fmt='m+',capsize=2,label='L peak')
3311+
Plot.errorbar(Qp,Ap,xerr=sQp,yerr=sAp,fmt='r+',capsize=2,label='A peak')
3312+
Plot.errorbar(Qp,Bp,xerr=sQp,yerr=sBp,fmt='+',color='orange',capsize=2,label='B peak')
3313+
Plot.errorbar(Qp,Sp,xerr=sQp,yerr=sSp,fmt='b+',capsize=2,label='G peak')
3314+
Plot.errorbar(Qp,Gp,xerr=sQp,yerr=sGp,fmt='m+',capsize=2,label='L peak')
32963315
else:
32973316
Plot.plot(Qp,Ap,'+',color='r',label='A peak')
32983317
Plot.plot(Qp,Bp,'+',color='orange',label='B peak')
@@ -3394,6 +3413,7 @@ def OnKeyPress(event):
33943413
Plot.plot(Q,Wf,color='b',dashes=(5,5),label='G+L fit')
33953414

33963415
Xp = []
3416+
sXp = []
33973417
Yp = []
33983418
sYp = []
33993419
Zp = []
@@ -3402,6 +3422,7 @@ def OnKeyPress(event):
34023422
for ip,peak in enumerate(peaks):
34033423
tpd = tand(peak[0]/2.)
34043424
Xp.append(4.0*math.pi*sind(peak[0]/2.0)/lam)
3425+
sXp.append(2.0*math.pi*cosd(peak[0]/2.0)*peakEsds.get('pos%d'%ip,0.0)/lam)
34053426
try:
34063427
s = math.sqrt(peak[isig])*math.pi/18000.
34073428
except ValueError:
@@ -3410,14 +3431,14 @@ def OnKeyPress(event):
34103431
G = G2pwd.getgamFW(g,s) #/2.
34113432
yp = sq8ln2*s
34123433
Yp.append(yp/tpd)
3413-
sYp.append((math.pi/36000.)*peakEsds.get('sig%d'%ip,0.0)/yp)
3434+
sYp.append(0.5*sq8ln2*(math.pi/18000.)**2*peakEsds.get('sig%d'%ip,0.0)/(s*tpd))
34143435
Zp.append(g/tpd)
34153436
sZp.append((math.pi/18000.)*peakEsds.get('gam%d'%ip,0.0)/tpd)
34163437
Wp.append(G/tpd)
34173438
if len(peaks):
34183439
if G2frame.ErrorBars:
3419-
Plot.errorbar(Xp,Yp,yerr=sYp,fmt='r+',capsize=2,label='G peak')
3420-
Plot.errorbar(Xp,Zp,yerr=sZp,fmt='g+',capsize=2,label='L peak')
3440+
Plot.errorbar(Xp,Yp,xerr=sXp,yerr=sYp,fmt='r+',capsize=2,label='G peak')
3441+
Plot.errorbar(Xp,Zp,xerr=sXp,yerr=sZp,fmt='g+',capsize=2,label='L peak')
34213442
else:
34223443
Plot.plot(Xp,Yp,'+',color='r',label='G peak')
34233444
Plot.plot(Xp,Zp,'+',color='g',label='L peak')

0 commit comments

Comments
 (0)