From 18ef853c9231cf83f7b61a073533fd0d94974d30 Mon Sep 17 00:00:00 2001 From: Max <17359435+MaxPelly@users.noreply.github.com> Date: Sun, 18 Oct 2026 21:15:26 +0100 Subject: [PATCH 1/7] Read selected databank not just the first Update add_powder_histogram function to read the selected databank if multiple = False. Currently just always reads the first. --- GSASII/GSASIIscriptable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GSASII/GSASIIscriptable.py b/GSASII/GSASIIscriptable.py index b1d5bc52..c15b8a20 100644 --- a/GSASII/GSASIIscriptable.py +++ b/GSASII/GSASIIscriptable.py @@ -1098,7 +1098,7 @@ def add_powder_histogram(self, datafile, iparams=None, phases=[], datafile = os.path.abspath(os.path.expanduser(datafile)) pwdrreaders = import_generic(datafile, Readers['Pwdr'],fmthint=fmthint, bank=databank, URL=URL) - if not multiple: pwdrreaders = pwdrreaders[0:1] + if not multiple: pwdrreaders = [pwdrreaders[databank]] histlist = [] if URL: instprm = downloadFile(iparams) From eb493b18e9985f323b6290b6c6dcaf21fa46e011 Mon Sep 17 00:00:00 2001 From: Max <17359435+MaxPelly@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:30:08 +0100 Subject: [PATCH 2/7] correct for non zero indexed databank paramater --- GSASII/GSASIIscriptable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GSASII/GSASIIscriptable.py b/GSASII/GSASIIscriptable.py index c15b8a20..15246bc2 100644 --- a/GSASII/GSASIIscriptable.py +++ b/GSASII/GSASIIscriptable.py @@ -1098,7 +1098,7 @@ def add_powder_histogram(self, datafile, iparams=None, phases=[], datafile = os.path.abspath(os.path.expanduser(datafile)) pwdrreaders = import_generic(datafile, Readers['Pwdr'],fmthint=fmthint, bank=databank, URL=URL) - if not multiple: pwdrreaders = [pwdrreaders[databank]] + if not multiple: pwdrreaders = [pwdrreaders[databank-1]] histlist = [] if URL: instprm = downloadFile(iparams) From 4616b235c90a5ce8e88c577cc8b097da89e993f5 Mon Sep 17 00:00:00 2001 From: Max Pelly Date: Mon, 19 Oct 2026 09:42:24 +0100 Subject: [PATCH 3/7] Real fix, Reinitialise reader before setting selections from bank paramater --- GSASII/GSASIIscriptable.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/GSASII/GSASIIscriptable.py b/GSASII/GSASIIscriptable.py index 15246bc2..4840f781 100644 --- a/GSASII/GSASIIscriptable.py +++ b/GSASII/GSASIIscriptable.py @@ -482,7 +482,9 @@ def import_generic(filename, readerlist, fmthint=None, bank=None, for rd in primaryReaders + secondaryReaders: # Initialize reader - rd.selections = [] + rd.dnames = [] + rd.ReInitialize() + rd.useNet = useNet # matters only for phase importers if bank is None: rd.selections = [] else: @@ -490,18 +492,12 @@ def import_generic(filename, readerlist, fmthint=None, bank=None, rd.selections = [i-1 for i in bank] except TypeError: rd.selections = [bank-1] - rd.dnames = [] - rd.ReInitialize() - rd.useNet = useNet # matters only for phase importers - # Rewind file - rd.errors = "" if not rd.ContentsValidator(filename): # Report error G2fil.G2Print("Warning: File {} has a validation error, continuing".format(filename)) #if len(rd.selections) > 1: # raise G2ImportException("File {} has {} banks. Specify which bank to read with databank param." # .format(filename,len(rd.selections))) - block = 0 if buffer is None: rdbuffer = {} @@ -1098,7 +1094,7 @@ def add_powder_histogram(self, datafile, iparams=None, phases=[], datafile = os.path.abspath(os.path.expanduser(datafile)) pwdrreaders = import_generic(datafile, Readers['Pwdr'],fmthint=fmthint, bank=databank, URL=URL) - if not multiple: pwdrreaders = [pwdrreaders[databank-1]] + if not multiple: pwdrreaders = pwdrreaders[0:1] histlist = [] if URL: instprm = downloadFile(iparams) From cbfc595821711ade4bdaddeda3de3eabf16bf790 Mon Sep 17 00:00:00 2001 From: Max Pelly Date: Mon, 19 Oct 2026 10:32:55 +0000 Subject: [PATCH 4/7] Keep bank selection for all files in GUI multi-file import --- GSASII/GSASIIdataGUI.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GSASII/GSASIIdataGUI.py b/GSASII/GSASIIdataGUI.py index d975517d..92bd7b24 100644 --- a/GSASII/GSASIIdataGUI.py +++ b/GSASII/GSASIIdataGUI.py @@ -1191,6 +1191,8 @@ def OnImportGeneric(self,reader,readerlist,label,multiple=False, rd.selections = [] rd.dnames = [] rd.ReInitialize() # purge anything from a previous read + if not Start: # reuse bank selections from 1st file + rd.selections = list(userSel) rd.errors = "" # clear out any old errors if not rd.ContentsValidator(filename): # rejected on cursory check errorReport += "\n "+rd.formatName + ' validator error' @@ -1202,6 +1204,7 @@ def OnImportGeneric(self,reader,readerlist,label,multiple=False, if dlg.ShowModal() == wx.ID_OK: rd.selections = dlg.GetSelections() Start = False + userSel = list(rd.selections) dlg.Destroy() repeat = True rdbuffer = {} # create temporary storage for file reader From 92d7aadf1d3efcc3b5730d6f3d43e545efa52f64 Mon Sep 17 00:00:00 2001 From: Max Pelly Date: Mon, 19 Oct 2026 15:17:31 +0100 Subject: [PATCH 5/7] In validator return true if nhist and self.selections. Previusly if there were selections code fell through to no powder data error --- GSASII/imports/G2pwd_GPX.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GSASII/imports/G2pwd_GPX.py b/GSASII/imports/G2pwd_GPX.py index bec4017c..65f8848f 100644 --- a/GSASII/imports/G2pwd_GPX.py +++ b/GSASII/imports/G2pwd_GPX.py @@ -46,7 +46,7 @@ def ContentsValidator(self, filename): if not len(self.selections): #no PWDR entries self.selections = range(nhist) fp.close() - return True + return True self.errors = 'No powder entries found' fp.close() return False From 3e40e981ef82c29f5af712918a8ee1f1f34f4e58 Mon Sep 17 00:00:00 2001 From: Max Pelly Date: Mon, 19 Oct 2026 15:41:40 +0100 Subject: [PATCH 6/7] Also close the file even when there are selections. --- GSASII/imports/G2pwd_GPX.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GSASII/imports/G2pwd_GPX.py b/GSASII/imports/G2pwd_GPX.py index 65f8848f..3aff1d0f 100644 --- a/GSASII/imports/G2pwd_GPX.py +++ b/GSASII/imports/G2pwd_GPX.py @@ -45,7 +45,7 @@ def ContentsValidator(self, filename): if nhist: if not len(self.selections): #no PWDR entries self.selections = range(nhist) - fp.close() + fp.close() return True self.errors = 'No powder entries found' fp.close() From a15b8b605fe70abf52b1e94ab1e210a5c8305a0e Mon Sep 17 00:00:00 2001 From: Max Pelly Date: Tue, 20 Oct 2026 10:11:07 +0100 Subject: [PATCH 7/7] Check for negative bank selections due to 1 to 0 indexed conversion --- GSASII/GSASIIscriptable.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GSASII/GSASIIscriptable.py b/GSASII/GSASIIscriptable.py index 4840f781..d88934f5 100644 --- a/GSASII/GSASIIscriptable.py +++ b/GSASII/GSASIIscriptable.py @@ -492,6 +492,8 @@ def import_generic(filename, readerlist, fmthint=None, bank=None, rd.selections = [i-1 for i in bank] except TypeError: rd.selections = [bank-1] + if any(i < 0 for i in rd.selections): + raise G2ImportException(f"Databank numbering starts at 1, got {bank}.") if not rd.ContentsValidator(filename): # Report error G2fil.G2Print("Warning: File {} has a validation error, continuing".format(filename))