Skip to content

Commit b6175e4

Browse files
committed
fix HDF5 image reread bug in scripting; add reminders to GUI import routines so I am less likely to make that error again.
1 parent 8c0989f commit b6175e4

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

GSASII/GSASIIdataGUI.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,11 @@ def PreviewFile(self,filename):
994994

995995
def OnImportGeneric(self,reader,readerlist,label,multiple=False,
996996
usedRanIdList=[],Preview=True,load2Tree=False,filename=None):
997-
'''Used for all imports, including Phases, datasets, images...
997+
'''Used for all imports from GUI, including Phases, datasets, images...
998+
999+
N.B. The code here is largely duplicated in
1000+
:func:`GSASIIscriptable:import_generic` so any changes made here
1001+
need to be duplicated there, too.
9981002
9991003
Called from :meth:`GSASII.OnImportPhase`, :meth:`GSASII.OnImportImage`,
10001004
:meth:`GSASII.OnImportSfact`, :meth:`GSASII.OnImportPowder`,
@@ -1273,6 +1277,10 @@ def OnImportPhase(self,event):
12731277
reader item associated with the menu item, which will be
12741278
None for the last menu item, which is the "guess" option
12751279
where all appropriate formats will be tried.
1280+
1281+
N.B. The code here is largely duplicated in
1282+
:mod:`GSASIIscriptable` so any changes made here
1283+
need to be duplicated there, too.
12761284
'''
12771285
# look up which format was requested
12781286
reqrdr = self.ImportMenuId.get(event.GetId())
@@ -1513,6 +1521,10 @@ def OnImportImage(self,event):
15131521
where all appropriate formats will be tried.
15141522
15151523
A reader object is filled each time an image is read.
1524+
1525+
N.B. The code here is largely duplicated in
1526+
:mod:`GSASIIscriptable` so any changes made here
1527+
need to be duplicated there, too.
15161528
'''
15171529
self.CheckNotebook()
15181530
# look up which format was requested
@@ -1541,6 +1553,10 @@ def OnImportSfact(self,event):
15411553
reader item associated with the menu item, which will be
15421554
None for the last menu item, which is the "guess" option
15431555
where all appropriate formats will be tried.
1556+
1557+
N.B. The code here is largely duplicated in
1558+
:mod:`GSASIIscriptable` so any changes made here
1559+
need to be duplicated there, too.
15441560
'''
15451561
# get a list of existing histograms
15461562
HKLFlist = []
@@ -1991,6 +2007,10 @@ def OnImportPowder(self,event):
19912007
where all appropriate formats will be tried.
19922008
19932009
Also reads an instrument parameter file for each dataset.
2010+
2011+
N.B. The code here is largely duplicated in
2012+
:mod:`GSASIIscriptable` so any changes made here
2013+
need to be duplicated there, too.
19942014
'''
19952015
FP,tth = 25.0,150.
19962016
# get a list of existing histograms
@@ -2625,6 +2645,8 @@ def OnImportSmallAngle(self,event):
26252645
None for the last menu item, which is the "guess" option
26262646
where all appropriate formats will be tried.
26272647
Small angle data is presumed to be as QIE form for either x-rays or neutrons
2648+
2649+
N.B. This code is not yet duplicated in :mod:`GSASIIscriptable`.
26282650
'''
26292651

26302652
def GetSASDIparm(reader):
@@ -2718,6 +2740,8 @@ def OnImportReflectometry(self,event):
27182740
None for the last menu item, which is the "guess" option
27192741
where all appropriate formats will be tried.
27202742
Reflectometry data is presumed to be in QIE form for x-rays of neutrons
2743+
2744+
N.B. This code is not yet duplicated in :mod:`GSASIIscriptable`.
27212745
'''
27222746

27232747
def GetREFDIparm(reader):
@@ -2817,6 +2841,10 @@ def OnImportPDF(self,event):
28172841
reader item associated with the menu item, which will be
28182842
None for the last menu item, which is the "guess" option
28192843
where all appropriate formats will be tried.
2844+
2845+
N.B. The code here is largely duplicated in
2846+
:mod:`GSASIIscriptable` so any changes made here
2847+
need to be duplicated there, too.
28202848
'''
28212849
# get a list of existing histograms
28222850
PDFlist = []

GSASII/GSASIIscriptable.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ def downloadFile(URL,download_loc=None):
433433
return filename
434434

435435
def import_generic(filename, readerlist, fmthint=None, bank=None,
436-
URL=False, download_loc=None, useNet=True):
436+
URL=False, download_loc=None, useNet=True,
437+
buffer=None):
437438
"""Attempt to import a filename, using a list of reader objects.
438439
439440
Returns the first reader object which worked."""
@@ -496,7 +497,10 @@ def import_generic(filename, readerlist, fmthint=None, bank=None,
496497
# .format(filename,len(rd.selections)))
497498

498499
block = 0
499-
rdbuffer = {}
500+
if buffer is None:
501+
rdbuffer = {}
502+
else:
503+
rdbuffer = buffer
500504
repeat = True
501505
while repeat:
502506
repeat = False
@@ -2694,8 +2698,10 @@ def add_image(self, imagefile, fmthint=None, defaultImage=None,
26942698
"""
26952699
LoadG2fil()
26962700
if not URL: imagefile = os.path.abspath(os.path.expanduser(imagefile))
2701+
rdbuffer = {}
26972702
readers = import_generic(imagefile, Readers['Image'],
2698-
fmthint=fmthint, URL=URL, download_loc=download_loc)
2703+
fmthint=fmthint, URL=URL, download_loc=download_loc,
2704+
buffer=rdbuffer)
26992705
objlist = []
27002706
for i,rd in enumerate(readers):
27012707
if indexList is not None and i not in indexList:
@@ -2706,10 +2712,19 @@ def add_image(self, imagefile, fmthint=None, defaultImage=None,
27062712
#see this: G2IO.EditImageParms(self,rd.Data,rd.Comments,rd.Image,imagefile)
27072713
rd.SciPy = False
27082714
rd.readfilename = imagefile
2715+
TreeLbl = 'IMG '+os.path.basename(imagefile)
27092716
if rd.repeatcount == 1 and not rd.repeat: # skip image number if only one in set
2710-
rd.Data['ImageTag'] = None
2717+
imageInfo = imagefile
2718+
elif 'imagemap' in rdbuffer:
2719+
# if there is an image map, save the entry there rather than
2720+
# a simple number (HDF5 only at present)
2721+
rd.Data['ImageTag'] = rdbuffer['imagemap'][rd.imageEntry]
2722+
TreeLbl += f' #{i:04}'
2723+
imageInfo = (imagefile,rd.Data.get('ImageTag'))
27112724
else:
27122725
rd.Data['ImageTag'] = rd.repeatcount
2726+
imageInfo = (imagefile,rd.Data.get('ImageTag'))
2727+
TreeLbl += f' #{rd.Data.get("ImageTag",-1):04}'
27132728
rd.Data['formatName'] = rd.formatName
27142729
if rd.sumfile:
27152730
rd.readfilename = rd.sumfile
@@ -2718,13 +2733,6 @@ def add_image(self, imagefile, fmthint=None, defaultImage=None,
27182733
# Code from G2IO.LoadImage2Tree(rd.readfilename,self,rd.Comments,rd.Data,rd.Npix,rd.Image)
27192734
Imax = np.amax(rd.Image)
27202735
ImgNames = [i[0] for i in self.names if i[0].startswith('IMG ')]
2721-
TreeLbl = 'IMG '+os.path.basename(imagefile)
2722-
ImageTag = rd.Data.get('ImageTag')
2723-
if ImageTag:
2724-
TreeLbl += ' #'+'%04d'%(ImageTag)
2725-
imageInfo = (imagefile,ImageTag)
2726-
else:
2727-
imageInfo = imagefile
27282736
TreeName = G2obj.MakeUniqueLabel(TreeLbl,ImgNames)
27292737
# MT dict to contain image info
27302738
ImgDict = {}

0 commit comments

Comments
 (0)