- Timestamp:
- Feb 15, 2016 12:58:35 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/GSASII.py ¶
r2148 r2150 943 943 944 944 ''' 945 if os.path.splitext(instfile)[1].lower() != '.instprm': # invalid file946 return None947 if not os.path.exists(instfile): # no such file948 return None949 945 File = open(instfile,'r') 950 946 lines = File.readlines() … … 962 958 when bank = n then use parameters; otherwise skip that set. Ignored if BANK n: 963 959 not present. NB: this kind of instprm file made by a Save all profile command in Instrument Parameters 964 960 :return dict: Inst instrument parameter dict if OK, or 961 str: Error message if failed 965 962 ''' 966 963 if 'GSAS-II' not in instLines[0]: # not a valid file … … 985 982 il += 1 986 983 if il == len(instLines): 987 return 'Bank %d not found in .instprm file'%(bank)984 return 'Bank %d not found in instprm file'%(bank) 988 985 S = instLines[il] 989 986 continue … … 1002 999 newVals.append(val) 1003 1000 il += 1 1004 return G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]),{}1001 return [G2IO.makeInstDict(newItems,newVals,len(newVals)*[False,]),{}] 1005 1002 1006 1003 def ReadPowderIparm(self,instfile,bank,databanks,rd): … … 1008 1005 1009 1006 :param str instfile: name of instrument parameter file 1010 1011 1007 :param int bank: the bank number read in the raw data file 1012 1013 1008 :param int databanks: the number of banks in the raw data file. 1014 1009 If the number of banks in the data and instrument parameter files … … 1016 1011 is used to select the instrument parameter file. If not, the user 1017 1012 is asked to make a selection. 1018 1019 1013 :param obj rd: the raw data (histogram) data object. This 1020 1014 sets rd.instbank. … … 1233 1227 Inst2['Icovar'] = Icovar 1234 1228 return [Inst1,Inst2] 1229 1230 def GetDefaultParms(self,rd): 1231 '''Solicits from user a default set of parameters & returns Inst parm dict 1232 param: self: refers to the GSASII main class 1233 param: rd: importer data structure 1234 returns: dict: Instrument parameter dictionary 1235 ''' 1236 import defaultIparms as dI 1237 while True: # loop until we get a choice 1238 choices = [] 1239 head = 'Select from default instrument parameters for '+rd.idstring 1240 1241 for l in dI.defaultIparm_lbl: 1242 choices.append('Defaults for '+l) 1243 res = rd.BlockSelector( 1244 choices, 1245 ParentFrame=self, 1246 title=head, 1247 header='Select default inst parms', 1248 useCancel=False) 1249 if res is None: continue 1250 rd.instfile = '' 1251 rd.instmsg = 'default: '+dI.defaultIparm_lbl[res] 1252 return self.ReadPowderInstprm(dI.defaultIparms[res],bank) #this is [Inst1,Inst2] a pair of dicts 1235 1253 1236 1254 # stuff we might need from the reader … … 1238 1256 bank = rd.powderentry[2] 1239 1257 numbanks = rd.numbanks 1240 # is there an instrument parameter file defined for the current data set? 1241 # or if this is a read on a set of set of files, use the last one again 1242 #if rd.instparm or (lastdatafile == filename and lastIparmfile): 1243 if rd.instparm or lastIparmfile: 1244 if rd.instparm: 1245 instfile = os.path.join(os.path.split(filename)[0], 1246 rd.instparm) 1247 else: 1248 # for multiple reads of one data file, reuse the inst parm file 1249 instfile = lastIparmfile 1250 if os.path.exists(instfile): 1251 #print 'debug: try read',instfile 1258 #1st priority: is there an instrument parameter file matching the current file 1259 # with extension .instprm, .prm, .inst, or .ins? If so read it 1260 basename = os.path.splitext(filename)[0] 1261 for ext in '.instprm','.prm','.inst','.ins': 1262 instfile = basename + ext 1263 if not os.path.exists(instfile): 1264 continue 1265 if 'instprm' in instfile: 1252 1266 Lines = self.OpenPowderInstprm(instfile) 1253 instParmList = None 1254 if Lines is not None: 1255 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1267 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1256 1268 if 'list' in str(type(instParmList)): 1257 1269 rd.instfile = instfile … … 1259 1271 return instParmList 1260 1272 else: 1261 rd.instmsg = instParmList #an error message 1262 return None 1273 #print 'debug: open/read failed',instfile 1274 pass # fail silently 1275 else: 1263 1276 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1264 1277 if Iparm: … … 1267 1280 rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1268 1281 return SetPowderInstParms(Iparm,rd) 1282 else: 1283 #print 'debug: open/read failed',instfile 1284 pass # fail silently 1285 1286 #2nd priority: is there an instrument parameter file defined for the current data set? 1287 # or if this is a read on a set of set of files, use the last one again 1288 #if rd.instparm or (lastdatafile == filename and lastIparmfile): 1289 if rd.instparm or lastIparmfile: 1290 if rd.instparm: 1291 instfile = os.path.join(os.path.split(filename)[0],rd.instparm) 1292 else: 1293 # for multiple reads of one data file, reuse the inst parm file 1294 instfile = lastIparmfile 1295 if os.path.exists(instfile): 1296 #print 'debug: try read',instfile 1297 if 'instprm' in instfile: #GSAS-II file must have .instprm as extension 1298 Lines = self.OpenPowderInstprm(instfile) 1299 if Lines is not None: 1300 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1301 else: #old GSAS style iparm file - could be named anything! 1302 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1303 if Iparm: 1304 #print 'debug: success' 1305 rd.instfile = instfile 1306 rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1307 instParmList = SetPowderInstParms(Iparm,rd) #this is [Inst1,Inst2] a pair of dicts 1308 if 'list' in str(type(instParmList)): #record stuff & return stuff 1309 rd.instfile = instfile 1310 rd.instmsg = 'GSAS-II file '+instfile 1311 return instParmList 1312 else: #bad iparms - try default 1313 rd.instmsg = instParmList #an error message 1314 return GetDefaultParms(self,rd) 1269 1315 else: 1270 1316 self.ErrorDialog('Open Error','Error opening instrument parameter file ' 1271 1317 +str(instfile)+' requested by file '+ filename) 1272 # is there an instrument parameter file matching the current file1273 # with extension .inst or .prm? If so read it1274 basename = os.path.splitext(filename)[0]1275 for ext in '.instprm','.prm','.inst','.ins':1276 instfile = basename + ext1277 Lines = self.OpenPowderInstprm(instfile)1278 instParmList = None1279 if Lines is not None:1280 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above1281 if instParmList is not None:1282 rd.instfile = instfile1283 rd.instmsg = 'GSAS-II file '+instfile1284 return instParmList1285 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd)1286 if Iparm:1287 #print 'debug: success'1288 rd.instfile = instfile1289 rd.instmsg = instfile + ' bank ' + str(rd.instbank)1290 return SetPowderInstParms(Iparm,rd)1291 else:1292 #print 'debug: open/read failed',instfile1293 pass # fail silently1294 1295 1318 # did we read the data file from a zip? If so, look there for a 1296 1319 # instrument parameter file 1297 1320 if self.zipfile: 1298 1321 for ext in '.instprm','.prm','.inst','.ins': 1299 instfile = G2IO.ExtractFileFromZip( 1300 self.zipfile, 1301 selection=os.path.split(basename + ext)[1], 1302 parent=self) 1322 instfile = G2IO.ExtractFileFromZip(self.zipfile, 1323 selection=os.path.split(basename + ext)[1],parent=self) 1303 1324 if instfile is not None and instfile != self.zipfile: 1304 1325 print 'debug:',instfile,'created from ',self.zipfile … … 1306 1327 instParmList = None 1307 1328 if Lines is not None: 1308 instParmList = self.ReadPowderInstprm(Lines,bank) # know Bank - see above1309 if instParmList is not None:1329 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1330 if 'dict' in str(type(instParmList)): 1310 1331 rd.instfile = instfile 1311 1332 rd.instmsg = 'GSAS-II file '+instfile 1312 1333 return instParmList 1334 else: 1335 rd.instmsg = instParmList #an error message 1336 print 'three',instParmList 1337 return GetDefaultParms(self,rd) 1313 1338 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1314 1339 if Iparm: … … 1336 1361 instfile = dlg.GetPath() 1337 1362 dlg.Destroy() 1338 if not instfile: break 1339 Lines = self.OpenPowderInstprm(instfile) 1340 instParmList = None 1341 if Lines is not None: 1342 instParmList = self.ReadPowderInstprm(Lines,bank) #know Bank - see above 1343 if instParmList is not None: 1344 rd.instfile = instfile 1345 rd.instmsg = 'GSAS-II file '+instfile 1346 return instParmList 1347 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1348 if Iparm: 1349 #print 'debug: success with',instfile 1350 rd.instfile = instfile 1351 rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1352 return SetPowderInstParms(Iparm,rd) 1363 if not instfile: 1364 return GetDefaultParms(self,rd) #on Cancel/break 1365 if 'instprm' in instfile: 1366 Lines = self.OpenPowderInstprm(instfile) 1367 print instfile,bank 1368 if Lines is not None: 1369 instParmList = self.ReadPowderInstprm(Lines,bank) #this is [Inst1,Inst2] a pair of dicts 1370 if 'list' in str(type(instParmList)): 1371 rd.instfile = instfile 1372 rd.instmsg = 'GSAS-II file '+instfile 1373 return instParmList 1374 else: 1375 rd.instmsg = instParmList #an error message 1376 return GetDefaultParms(self,rd) 1353 1377 else: 1354 self.ErrorDialog('Read Error', 1355 'Error opening/reading file '+str(instfile)) 1356 1357 # still no success: offer user choice of defaults 1358 import defaultIparms as dI 1359 while True: # loop until we get a choice 1360 choices = [] 1361 head = 'Select from default instrument parameters for '+rd.idstring 1362 1363 for l in dI.defaultIparm_lbl: 1364 choices.append('Defaults for '+l) 1365 res = rd.BlockSelector( 1366 choices, 1367 ParentFrame=self, 1368 title=head, 1369 header='Select default inst parms', 1370 useCancel=False) 1371 if res is None: continue 1372 rd.instfile = '' 1373 rd.instmsg = 'default: '+dI.defaultIparm_lbl[res] 1374 return self.ReadPowderInstprm(dI.defaultIparms[res],bank) #know Bank - see above 1375 1378 Iparm = self.ReadPowderIparm(instfile,bank,numbanks,rd) 1379 if Iparm: 1380 #print 'debug: success with',instfile 1381 rd.instfile = instfile 1382 rd.instmsg = instfile + ' bank ' + str(rd.instbank) 1383 return SetPowderInstParms(Iparm,rd) 1384 else: 1385 self.ErrorDialog('Read Error', 1386 'Error opening/reading file '+str(instfile)) 1387 1376 1388 def OnImportPowder(self,event): 1377 1389 '''Called in response to an Import/Powder Data/... menu item -
TabularUnified trunk/GSASIIIO.py ¶
r2109 r2150 1407 1407 dlg = wx.MultiChoiceDialog(ParentFrame,title, header,ChoiceList+['Select all'], 1408 1408 wx.CHOICEDLG_STYLE) 1409 dlg.CenterOn Parent()1409 dlg.CenterOnScreen() 1410 1410 if size: dlg.SetSize(size) 1411 1411 if dlg.ShowModal() == wx.ID_OK:
Note: See TracChangeset
for help on using the changeset viewer.