Skip to content

Commit 7ddaa29

Browse files
committed
Merge branch 'main' into kvec_isodistort_zyp
2 parents 9134b59 + 9d7d89d commit 7ddaa29

File tree

10 files changed

+214
-62
lines changed

10 files changed

+214
-62
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,11 @@ def __init__(self, typ, positiveonly=False, xmin=None, xmax=None,exclLim=[False,
756756
if self.typ == int and self.positiveonly:
757757
self.validchars = '0123456789'
758758
elif self.typ == int:
759-
self.validchars = '0123456789+-'
759+
self.validchars = '0123456789+-%'
760760
elif self.typ == float:
761761
# allow for above and sind, cosd, sqrt, tand, pi, and abbreviations
762762
# also addition, subtraction, division, multiplication, exponentiation
763-
self.validchars = '0123456789.-+eE/cosindcqrtap()*,'
763+
self.validchars = '0123456789.-+eE/cosindcqrtap()*,%'
764764
else:
765765
self.validchars = None
766766
return

GSASII/GSASIIdataGUI.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6627,7 +6627,7 @@ def _makemenu(): # routine to create menu when first used
66276627
self.PWDRMenu = _makemenu
66286628

66296629
# HKLF - many wxIDs defined in PWDR & SASD above
6630-
G2G.Define_wxId('wxID_3DALLHKLPLOT','wxID_MERGEHKL')
6630+
G2G.Define_wxId('wxID_3DALLHKLPLOT','wxID_MERGEHKL','wxID_FIXFSQSQDATA')
66316631
def _makemenu(): # routine to create menu when first used
66326632
self.HKLFMenu = wx.MenuBar()
66336633
self.PrefillDataMenu(self.HKLFMenu)
@@ -6638,6 +6638,7 @@ def _makemenu(): # routine to create menu when first used
66386638
self.ErrorAnal.Append(G2G.wxID_1DHKLSTICKPLOT,'Plot 1D HKLs','Plot of HKLs from single crystal data in 1D')
66396639
self.ErrorAnal.Append(G2G.wxID_PWD3DHKLPLOT,'Plot 3D HKLs','Plot HKLs from single crystal data in 3D')
66406640
self.ErrorAnal.Append(G2G.wxID_3DALLHKLPLOT,'Plot all 3D HKLs','Plot HKLs from all single crystal data in 3D')
6641+
self.ErrorAnal.Append(G2G.wxID_FIXFSQSQDATA,'Fix (F^2)^2 data','Fix F^2 data imported as F')
66416642
# self.ErrorAnal.Append(G2G.wxID_PWDCOPY,'Copy params','Copy of HKLF parameters') #unused
66426643
self.PostfillDataMenu()
66436644
SetDataMenuBar(G2frame,self.HKLFMenu)
@@ -8135,6 +8136,47 @@ def OnMergeHKL(event):
81358136
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Instrument Parameters'),Inst)
81368137
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Reflection List'),{}) #dummy entry for GUI use
81378138
G2frame.GPXtree.SetItemPyData(Id,newData)
8139+
8140+
def OnFixFsqFsq(event):
8141+
''' Fix HKLF data that had been misimported as F instead of F^2'''
8142+
Name = G2frame.GPXtree.GetItemText(G2frame.PatternId)
8143+
Inst = G2frame.GPXtree.GetItemPyData(GetGPXtreeItemId(G2frame,
8144+
G2frame.PatternId,'Instrument Parameters'))
8145+
CId = GetGPXtreeItemId(G2frame,G2frame.PatternId,'Comments')
8146+
if CId:
8147+
Comments = G2frame.GPXtree.GetItemPyData(CId)
8148+
else:
8149+
Comments = []
8150+
Super = data[1]['Super']
8151+
refList = np.copy(data[1]['RefList'])
8152+
Comments.append(' Changing %d reflection F^2^2 to F^2 from %s'%(len(refList),Name))
8153+
for ih,hkl in enumerate(refList): #undo F--> F^2
8154+
hkl[5+Super] = np.sqrt(hkl[5+Super])
8155+
hkl[6+Super] = hkl[6+Super]/(2.0*hkl[5+Super])
8156+
hkl[7+Super] = np.sqrt(hkl[7+Super])
8157+
HKLFlist = []
8158+
if G2frame.GPXtree.GetCount():
8159+
item, cookie = G2frame.GPXtree.GetFirstChild(G2frame.root)
8160+
while item:
8161+
name = G2frame.GPXtree.GetItemText(item)
8162+
if name.startswith('HKLF ') and name not in HKLFlist:
8163+
HKLFlist.append(name)
8164+
item, cookie = G2frame.GPXtree.GetNextChild(G2frame.root, cookie)
8165+
newName = G2obj.MakeUniqueLabel(Name,HKLFlist)
8166+
newData = copy.deepcopy(data)
8167+
newData[0]['ranId'] = ran.randint(0,sys.maxsize)
8168+
newData[1]['RefList'] = refList
8169+
newData[0]['Nobs'] = refList.shape[0]
8170+
newData[0]['wR'] = 0.0
8171+
keys = list(newData[0].keys())
8172+
for item in keys:
8173+
if ':' in item:
8174+
del newData[0][item]
8175+
Id = G2frame.GPXtree.AppendItem(parent=G2frame.root,text=newName)
8176+
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Comments'),Comments)
8177+
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Instrument Parameters'),Inst)
8178+
G2frame.GPXtree.SetItemPyData(G2frame.GPXtree.AppendItem(Id,text='Reflection List'),{}) #dummy entry for GUI use
8179+
G2frame.GPXtree.SetItemPyData(Id,newData)
81388180

81398181
def OnErrorAnalysis(event):
81408182
'''Plots an "Abrams" plot - sorted delta/sig across data set.
@@ -8207,6 +8249,7 @@ def OnEditMag(**args):
82078249
G2frame.Bind(wx.EVT_MENU, OnPlot1DHKL, id=G2G.wxID_1DHKLSTICKPLOT)
82088250
G2frame.Bind(wx.EVT_MENU, OnPlot3DHKL, id=G2G.wxID_PWD3DHKLPLOT)
82098251
G2frame.Bind(wx.EVT_MENU, OnPlotAll3DHKL, id=G2G.wxID_3DALLHKLPLOT)
8252+
G2frame.Bind(wx.EVT_MENU, OnFixFsqFsq, id=G2G.wxID_FIXFSQSQDATA)
82108253
if kind == 'PWDR':
82118254
lbl = 'Powder'
82128255
elif kind == 'SASD':

GSASII/GSASIIlattice.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,10 @@ def CrsAng(H,cell,SGData):
26622662
DR = np.inner(H3,np.inner(G,H3))
26632663
DHR = np.inner(H,np.inner(G,H3))
26642664
DHR /= np.sqrt(DR*DH)
2665-
phi = acosd(max(-1,min(DHR,1.)))
2665+
if DHR.shape:
2666+
phi = acosd(DHR)
2667+
else:
2668+
phi = acosd(max(-1,min(DHR,1.)))
26662669
if Laue == '-1':
26672670
BA = H.T[1]*a/(b-H.T[0]*cosd(ga))
26682671
BB = H.T[0]*sind(ga)**2
@@ -2973,8 +2976,8 @@ def SHarmcal(SytSym,SHFln,psi,gam):
29732976
if SytSym in ['m3m','m3','43m','432','23'] or 'c' in trm:
29742977
Ksl = CubicSHarm(l,m,psi,gam)
29752978
else:
2976-
p = SHFln[term][2]
2977-
Ksl = SphHarmAng(l,m,p,psi,gam)
2979+
# p = SHFln[term][2]
2980+
Ksl = SphHarmAng(l,m,1.0,psi,gam)
29782981
SHVal += SHFln[term][0]*Ksl
29792982
return SHVal
29802983

GSASII/GSASIIobj.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ def CompileVarDesc():
669669
'([XYZ])$' : ('Cauchy instrument broadening \\1',1e-5),
670670
'Zero' : 'Debye-Scherrer zero correction',
671671
'Shift' : 'Bragg-Brentano sample displ.',
672-
'SurfRoughA' : 'Bragg-Brenano surface roughness A',
673-
'SurfRoughB' : 'Bragg-Brenano surface roughness B',
672+
'SurfRoughA' : 'Bragg-Brentano surface roughness A',
673+
'SurfRoughB' : 'Bragg-Brentano surface roughness B',
674674
'Transparency' : 'Bragg-Brentano sample tranparency',
675675
'DebyeA' : 'Debye model amplitude',
676676
'DebyeR' : 'Debye model radius',

GSASII/GSASIIpath.py

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,17 @@ def getG2Branch():
301301

302302
def getG2VersionInfo():
303303
'''Get the git version information. This can be a bit slow, so reading
304-
.../GSASII/saved_version.py may be faster (in main but not master branch)
304+
.../GSASII/saved_version.py may be faster
305305
'''
306306
gv = getSavedVersionInfo()
307307
if HowIsG2Installed().startswith('git'):
308308
g2repo = openGitRepo(path2GSAS2)
309309
commit = g2repo.head.commit
310-
ctim = commit.committed_datetime.strftime('%d-%b-%Y %H:%M')
310+
ctim = commit.committed_datetime.strftime('%d-%b-%y %H:%M')
311311
now = dt.datetime.now().replace(
312312
tzinfo=commit.committed_datetime.tzinfo)
313313
delta = now - commit.committed_datetime
314314
age = delta.total_seconds()/(60*60*24.)
315-
gversion = f"Tag: #{GetVersionNumber()}, {GetVersionTag()}"
316315
msg = ''
317316
if g2repo.head.is_detached:
318317
msg = ("\n" +
@@ -326,14 +325,19 @@ def getG2VersionInfo():
326325
if rc is None:
327326
msg += f"\n\tNo history found. On development branch? ({g2repo.active_branch})"
328327
elif str(g2repo.active_branch) != 'main':
329-
msg += f'\n\tUsing development branch "{g2repo.active_branch}"'
328+
msg += f'\n\tUsing development branch: {g2repo.active_branch}'
330329
elif age > 60 and len(rc) > 0:
331-
msg += f"\n\t**** This version is really old. Please update. >= {len(rc)} updates have been posted ****"
332-
elif age > 5 and len(rc) > 0:
333-
msg += f"\n\t**** Please consider updating. >= {len(rc)} updates have been posted"
334-
elif len(rc) > 0:
335-
msg += f"\n\tThis GSAS-II version is ~{len(rc)} updates behind current."
336-
return f" GSAS-II: {commit.hexsha[:8]}, {ctim} ({age:.1f} days old). {gversion}{msg}"
330+
msg += f"\n\t**** This version is really old ({age:.1f} days). Please update.\n\t**** At least {len(rc)} updates have been posted ****"
331+
elif (age > 5 and len(rc) > 0) or len(rc) > 5:
332+
msg += f"\n\t**** Please consider updating. This version is {age:.1f} days old\n\t**** and {len(rc)} or more updates behind."
333+
# elif len(rc) > 0:
334+
# msg += f"\n\tThis GSAS-II version is ~{len(rc)} updates behind current."
335+
# could consider getting version & tag from gv if not None (see below)
336+
gversion = f"{GetVersionNumber()}/{GetVersionTag()}"
337+
if len(rc) > 0:
338+
return f" GSAS-II: {gversion} posted {ctim} (\u2265{len(rc)} new updates) [{commit.hexsha[:8]}]{msg}"
339+
else:
340+
return f" GSAS-II: {gversion} posted {ctim} (no new updates) [{commit.hexsha[:8]}]{msg}"
337341
elif gv is not None:
338342
vt = ''
339343
cvt = ''
@@ -542,8 +546,10 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
542546
provide useful information in the case of a detached Head (see
543547
:func:`countDetachedCommits` for that.)
544548
545-
:param bool fetch: if True (default), updates are copied over from
549+
:param bool fetch: if True (default), updates are downloaded from
546550
the remote repository (git fetch), before checking for changes.
551+
At present, this feature is not used anywhere in GSAS-II (fetch=False
552+
in all calls).
547553
:param str g2repo: git.Rwpo connecton to GSAS-II installation. If
548554
None (default) it will be opened.
549555
:returns: a list containing (remotecommits, localcommits, fetched) where
@@ -567,8 +573,12 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
567573
g2repo = openGitRepo(path2GSAS2)
568574
if g2repo.head.is_detached:
569575
return (None,None,None)
576+
prevremotecommits = None
570577
if fetch:
571578
try:
579+
head = g2repo.head.ref
580+
tracking = head.tracking_branch()
581+
prevremotecommits = [i.hexsha for i in head.commit.iter_items(g2repo, f'{head.path}..{tracking.path}')]
572582
g2repo.remote().fetch()
573583
fetched = True
574584
except git.GitCommandError as msg:
@@ -578,6 +588,11 @@ def gitCheckForUpdates(fetch=True,g2repo=None):
578588
tracking = head.tracking_branch()
579589
localcommits = [i.hexsha for i in head.commit.iter_items(g2repo, f'{tracking.path}..{head.path}')]
580590
remotecommits = [i.hexsha for i in head.commit.iter_items(g2repo, f'{head.path}..{tracking.path}')]
591+
if prevremotecommits is None: prevremotecommits = remotecommits
592+
if fetch and len(prevremotecommits) != len(remotecommits):
593+
print(f"Fetch of new GSAS-II versions uploaded {len(remotecommits)-len(prevremotecommits)} new updates.")
594+
elif fetch and GetConfigValue('debug'):
595+
print('Updates fetched; nothing new')
581596
return remotecommits,localcommits,fetched
582597
except:
583598
return (None,None,None)
@@ -2164,7 +2179,8 @@ def openInNewTerm(project=None,g2script=None,pythonapp=sys.executable):
21642179

21652180
if updateType == 'fetch':
21662181
# download the latest updates from GitHub to the local repository
2167-
# in background while GSAS-II runs no updates are applied
2182+
# in background while GSAS-II runs no updates are applied.
2183+
# invoked by gitGetUpdate(mode='Background')
21682184
logfile = os.path.join(os.path.expanduser('~'),'GSASII_bkgUpdate.log')
21692185
mode = 'a'
21702186
# don't let log file get too large (20K bytes)
@@ -2176,36 +2192,53 @@ def openInNewTerm(project=None,g2script=None,pythonapp=sys.executable):
21762192
except:
21772193
print('background git update was unable to open log file')
21782194
sys.exit()
2179-
fp.write('Starting background git update')
2180-
fp.write(dt.datetime.strftime(dt.datetime.now(),
2181-
" at %Y-%m-%dT%H:%M\n"))
21822195
try:
21832196
import git
21842197
except:
2185-
fp.write('git import failed')
2198+
fp.write('Git background import failed')
2199+
fp.write(dt.datetime.strftime(dt.datetime.now(),
2200+
" at %Y-%m-%dT%H:%M\n"))
21862201
fp.close()
21872202
sys.exit()
21882203
try:
21892204
g2repo = openGitRepo(path2GSAS2)
2205+
prevremotecommits = None
2206+
if not g2repo.head.is_detached:
2207+
head = g2repo.head.ref
2208+
tracking = head.tracking_branch()
2209+
prevremotecommits = [i.hexsha for i in head.commit.iter_items(g2repo, f'{head.path}..{tracking.path}')]
21902210
g2repo.remote().fetch()
2191-
fp.write('Updates fetched\n')
2211+
if not g2repo.head.is_detached:
2212+
head = g2repo.head.ref
2213+
tracking = head.tracking_branch()
2214+
remotecommits = [i.hexsha for i in head.commit.iter_items(g2repo, f'{head.path}..{tracking.path}')]
2215+
new = len(remotecommits)-len(prevremotecommits)
2216+
msg = f'{new} new update(s) found and downloaded, so {len(remotecommits)} total are available to install'
2217+
#fp.write(f'{msg}\n')
2218+
if new > 0: print(msg)
21922219
except Exception as msg:
2220+
fp.write('Background git update message')
2221+
fp.write(dt.datetime.strftime(dt.datetime.now(),
2222+
" at %Y-%m-%dT%H:%M\n"))
21932223
fp.write(f'Update failed with message {msg}\n')
21942224

21952225
if g2repo.head.is_detached:
2226+
fp.write('Background git update message')
2227+
fp.write(dt.datetime.strftime(dt.datetime.now(),
2228+
" at %Y-%m-%dT%H:%M\n"))
21962229
fp.write('Status: reverted to an old install\n')
2197-
else:
2198-
try:
2199-
rc,lc,_ = gitCheckForUpdates(False,g2repo)
2200-
if len(rc) == 0:
2201-
fp.write('Status: no unapplied commits\n')
2202-
else:
2203-
fp.write(f'Status: unapplied commits now {len(rc)}\n')
2204-
except Exception as msg:
2205-
fp.write(f'\ngitCheckForUpdates failed with message {msg}\n')
2206-
fp.write('update done at')
2207-
fp.write(dt.datetime.strftime(dt.datetime.now(),
2208-
" at %Y-%m-%dT%H:%M\n\n"))
2230+
# else:
2231+
# try:
2232+
# rc,lc,_ = gitCheckForUpdates(False,g2repo)
2233+
# if len(rc) == 0:
2234+
# fp.write('Status: no unapplied commits\n')
2235+
# else:
2236+
# fp.write(f'Status: unapplied commits now {len(rc)}\n')
2237+
# except Exception as msg:
2238+
# fp.write(f'\ngitCheckForUpdates failed with message {msg}\n')
2239+
# fp.write('update done at')
2240+
# fp.write(dt.datetime.strftime(dt.datetime.now(),
2241+
# " at %Y-%m-%dT%H:%M\n\n"))
22092242
fp.close()
22102243
sys.exit()
22112244

0 commit comments

Comments
 (0)