Changeset 3809
- Timestamp:
- Feb 3, 2019 10:35:00 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIIO.py
r3806 r3809 604 604 return 605 605 LastSavedUsing = None 606 file = open(G2frame.GSASprojectfile,'rb')606 filep = open(G2frame.GSASprojectfile,'rb') 607 607 if showProvenance: print ('loading from file: '+G2frame.GSASprojectfile) 608 608 wx.BeginBusyCursor() … … 611 611 try: 612 612 if '2' in platform.python_version_tuple()[0]: 613 data = cPickle.load(file )613 data = cPickle.load(filep) 614 614 else: 615 data = cPickle.load(file ,encoding='latin-1')615 data = cPickle.load(filep,encoding='latin-1') 616 616 except EOFError: 617 617 break … … 667 667 if Data['setDefault']: 668 668 G2frame.imageDefault = Data 669 file.close()670 669 if LastSavedUsing: 671 670 print('GPX load successful. Last saved with GSAS-II revision '+LastSavedUsing) … … 683 682 msg.ShowModal() 684 683 finally: 684 filep.close() 685 685 wx.EndBusyCursor() 686 686 G2frame.Status.SetStatusText('Mouse RB drag/drop to reorder',0) -
trunk/GSASIIscriptable.py
r3506 r3809 957 957 pass 958 958 959 def import_generic(filename, readerlist, fmthint=None ):959 def import_generic(filename, readerlist, fmthint=None, bank=None): 960 960 """Attempt to import a filename, using a list of reader objects. 961 961 … … 979 979 # Initialize reader 980 980 rd.selections = [] 981 if bank is None: 982 rd.selections = [] 983 else: 984 rd.selections = [bank-1] 981 985 rd.dnames = [] 982 986 rd.ReInitialize() … … 985 989 if not rd.ContentsValidator(filename): 986 990 # Report error 987 p ass991 print("Warning: File {} has a validation error, continuing".format(filename)) 988 992 if len(rd.selections) > 1: 989 # Select data? 990 # GSASII.py:543 991 raise G2ImportException("Not sure what data to select") 993 raise G2ImportException("File {} has {} banks. Specify which bank to read with databank param." 994 .format(filename,len(rd.selections))) 992 995 993 996 block = 0 … … 1013 1016 print("Read warning by", rd.formatName, "reader:", 1014 1017 rd.warnings, file=sys.stderr) 1018 elif bank is None: 1019 print("{} read by Reader {}" 1020 .format(filename,rd.formatName)) 1015 1021 else: 1016 print("{} read by Reader {}\n".format(filename,rd.formatName)) 1022 print("{} block # {} read by Reader {}" 1023 .format(filename,bank,rd.formatName)) 1017 1024 return rd_list 1018 1025 raise G2ImportException("No reader could read file: " + filename) 1019 1026 1020 1027 1021 def load_iprms(instfile, reader ):1028 def load_iprms(instfile, reader, bank=None): 1022 1029 """Loads instrument parameters from a file, and edits the 1023 1030 given reader. … … 1030 1037 if ext.lower() == '.instprm': 1031 1038 # New GSAS File, load appropriately 1039 # this likely needs some work as there can now be more than one bank 1032 1040 with open(instfile) as f: 1033 1041 lines = f.readlines() 1034 bank = reader.powderentry[2] 1042 bank = reader.powderentry[2] # this may not be the right entry to use 1035 1043 numbanks = reader.numbanks 1036 1044 iparms = G2fil.ReadPowderInstprm(lines, bank, numbanks, reader) … … 1050 1058 Iparm[line[:12]] = line[12:-1] 1051 1059 ibanks = int(Iparm.get('INS BANK ', '1').strip()) 1052 if ibanks == 1: 1060 if bank is not None: 1061 # pull out requested bank # bank from the data, and change the bank to 1 1062 Iparm,IparmC = {},Iparm 1063 for key in IparmC: 1064 if 'INS' not in key[:3]: continue #skip around rubbish lines in some old iparm 1065 if key[4:6] == " ": 1066 Iparm[key] = IparmC[key] 1067 elif int(key[4:6].strip()) == bank: 1068 Iparm[key[:4]+' 1'+key[6:]] = IparmC[key] 1069 reader.instbank = bank 1070 elif ibanks == 1: 1053 1071 reader.instbank = 1 1054 reader.powderentry[2] = 1 1055 reader.instfile = instfile 1056 reader.instmsg = instfile + ' bank ' + str(reader.instbank) 1057 return G2fil.SetPowderInstParms(Iparm, reader) 1058 # TODO handle >1 banks 1059 raise NotImplementedError("Check GSASIIfiles.py: ReadPowderInstprm") 1060 1061 def load_pwd_from_reader(reader, instprm, existingnames=[]): 1072 else: 1073 raise G2ImportException("Instrument parameter file has {} banks, select one with instbank param." 1074 .format(ibanks)) 1075 reader.powderentry[2] = 1 1076 reader.instfile = instfile 1077 reader.instmsg = instfile + ' bank ' + str(reader.instbank) 1078 return G2fil.SetPowderInstParms(Iparm, reader) 1079 1080 def load_pwd_from_reader(reader, instprm, existingnames=[],bank=None): 1062 1081 """Loads powder data from a reader object, and assembles it into a GSASII data tree. 1063 1082 … … 1072 1091 Iparm1, Iparm2 = instprm 1073 1092 except ValueError: 1074 Iparm1, Iparm2 = load_iprms(instprm, reader )1075 1093 Iparm1, Iparm2 = load_iprms(instprm, reader, bank=bank) 1094 print('Instrument parameters read:',reader.instmsg) 1076 1095 Ymin = np.min(reader.powderdata[1]) 1077 1096 Ymax = np.max(reader.powderdata[1]) … … 1300 1319 SaveDictToProjFile(self.data, self.names, self.filename) 1301 1320 1302 def add_powder_histogram(self, datafile, iparams, phases=[], fmthint=None): 1321 def add_powder_histogram(self, datafile, iparams, phases=[], fmthint=None, 1322 databank=None, instbank=None): 1303 1323 """Loads a powder data histogram into the project. 1304 1324 … … 1315 1335 importers consistent with the file extension will be tried 1316 1336 (equivalent to "guess format" in menu). 1337 :param int databank: Specifies a dataset number to read, if file contains 1338 more than set of data. This should be 1 to read the first bank in 1339 the file (etc.) regardless of the number on the Bank line, etc. 1340 Default is None which means there should only be one dataset in the 1341 file. 1342 :param int instbank: Specifies an instrument parameter set to read, if 1343 the instrument parameter file contains more than set of parameters. 1344 This will match the INS # in an GSAS type file so it will typically 1345 be 1 to read the first parameter set in the file (etc.) 1346 Default is None which means there should only be one parameter set 1347 in the file. 1317 1348 1318 1349 :returns: A :class:`G2PwdrData` object representing … … 1322 1353 datafile = os.path.abspath(os.path.expanduser(datafile)) 1323 1354 iparams = os.path.abspath(os.path.expanduser(iparams)) 1324 pwdrreaders = import_generic(datafile, PwdrDataReaders,fmthint=fmthint )1355 pwdrreaders = import_generic(datafile, PwdrDataReaders,fmthint=fmthint,bank=databank) 1325 1356 histname, new_names, pwdrdata = load_pwd_from_reader( 1326 1357 pwdrreaders[0], iparams, 1327 [h.name for h in self.histograms()] )1358 [h.name for h in self.histograms()],bank=instbank) 1328 1359 if histname in self.data: 1329 1360 print("Warning - redefining histogram", histname)
Note: See TracChangeset
for help on using the changeset viewer.